revert an earlier buggy simplification
This commit is contained in:
parent
2013e26fb9
commit
90c5547710
|
@ -40,8 +40,7 @@ type WeightedMatrix interface {
|
||||||
|
|
||||||
func toAdjMatrix(g WeightedGraph, adj WeightedMatrix) *mat.Dense {
|
func toAdjMatrix(g WeightedGraph, adj WeightedMatrix) *mat.Dense {
|
||||||
copyEdges(g, adj)
|
copyEdges(g, adj)
|
||||||
matrix := mat.DenseCopyOf(adj.Matrix())
|
matrix := addSelfEdges(g, adj)
|
||||||
addSelfEdges(g, matrix)
|
|
||||||
|
|
||||||
return matrix
|
return matrix
|
||||||
}
|
}
|
||||||
|
@ -57,14 +56,19 @@ func copyEdges(g WeightedGraph, adj WeightedMatrix) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addSelfEdges(g WeightedGraph, matrix mat.Mutable) {
|
func addSelfEdges(g WeightedGraph, adj WeightedMatrix) *mat.Dense {
|
||||||
nodes := g.Nodes()
|
matrix := mat.DenseCopyOf(adj.Matrix())
|
||||||
|
|
||||||
|
nodes := adj.Nodes()
|
||||||
for i := 0; nodes.Next(); i++ {
|
for i := 0; nodes.Next(); i++ {
|
||||||
u := nodes.Node()
|
id := nodes.Node().ID()
|
||||||
|
u := g.Node(id)
|
||||||
|
|
||||||
e := g.WeightedEdge(u.ID(), u.ID())
|
e := g.WeightedEdge(u.ID(), u.ID())
|
||||||
if e != nil {
|
if e != nil {
|
||||||
matrix.Set(i, i, e.Weight())
|
matrix.Set(i, i, e.Weight())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return matrix
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue