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 {
 | 
			
		||||
	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
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue