// Validate check whether a valid weighted graph
// i.e. all edges have a weight
Validate check whether a valid weighted graph
i.e. all edges have a weight
// Validate check whether a valid weighted graph // i . e . all edges have a weight
func (g *WeightedGraph) Validate() bool {
	if g.EdgeCount() != len(g.weights) {
		return false
	}
	directedGraph := g.Directed()
	valid := true
	g.ControllableIterateAllNodes(func(u graph.NodeID) graph.IterateControl {
		g.ControllableIterateAdjacencyNodes(u, func(v graph.NodeID) graph.IterateControl {
			edge := graph.EdgeID{From: u, To: v}
			_, ok := g.weights[edge]
			if ok {
				return graph.ContinueIterate
			}
			if !directedGraph { 
				_, reverseOk := g.weights[edge.Reverse()]
				if reverseOk {
					return graph.ContinueIterate
				}
			}
			valid = false
			return graph.BreakIterate
		})
		if !valid {
			return graph.BreakIterate
		}
		return graph.ContinueIterate
	})
	return valid
}
func ( g * WeightedGraph ) Validate ( ) bool { if g . EdgeCount ( ) != len ( g . weights ) { return false } directedGraph := g . Directed ( ) valid := true g . ControllableIterateAllNodes ( func ( u graph . NodeID ) graph . IterateControl { g . ControllableIterateAdjacencyNodes ( u , func ( v graph . NodeID ) graph . IterateControl { edge := graph . EdgeID { From : u , To : v } _ , ok := g . weights [ edge ] if ok { return graph . ContinueIterate } if ! directedGraph { _ , reverseOk := g . weights [ edge . Reverse ( ) ] if reverseOk { return graph . ContinueIterate } } valid = false return graph . BreakIterate } ) if ! valid { return graph . BreakIterate } return graph . ContinueIterate } ) return valid }
Validate check whether a valid weighted graph
i.e.
Validate check whether a valid weighted graph i . e .
//undirected graph, also check reverse