revert an earlier buggy simplification

This commit is contained in:
filifa 2025-05-08 23:48:33 -04:00
parent 2013e26fb9
commit 90c5547710
1 changed files with 9 additions and 5 deletions

View File

@ -40,8 +40,7 @@ type WeightedMatrix interface {
func toAdjMatrix(g WeightedGraph, adj WeightedMatrix) *mat.Dense {
copyEdges(g, adj)
matrix := mat.DenseCopyOf(adj.Matrix())
addSelfEdges(g, matrix)
matrix := addSelfEdges(g, adj)
return matrix
}
@ -57,14 +56,19 @@ func copyEdges(g WeightedGraph, adj WeightedMatrix) {
}
}
func addSelfEdges(g WeightedGraph, matrix mat.Mutable) {
nodes := g.Nodes()
func addSelfEdges(g WeightedGraph, adj WeightedMatrix) *mat.Dense {
matrix := mat.DenseCopyOf(adj.Matrix())
nodes := adj.Nodes()
for i := 0; nodes.Next(); i++ {
u := nodes.Node()
id := nodes.Node().ID()
u := g.Node(id)
e := g.WeightedEdge(u.ID(), u.ID())
if e != nil {
matrix.Set(i, i, e.Weight())
}
}
return matrix
}