// Weight return the weight of the edge
Weight return the weight of the edge
// Weight return the weight of the edge
func (g *WeightedGraph) Weight(from, to graph.NodeID) (Weight, error) {
	if !g.IsEdgeValid(from, to) {
		return 0, fmt.Errorf("Edge %v-%v is invalid", from, to)
	}
	edge := graph.EdgeID{From: from, To: to}
	fromToWeight, ok := g.weights[edge]
	if ok {
		return fromToWeight, nil
	}
	if g.Directed() {
		return 0, fmt.Errorf("no weight found for edge %v", edge)
	}
	toFromWeight, ok := g.weights[edge.Reverse()]
	if ok {
		return toFromWeight, nil
	}
	return 0, fmt.Errorf("no weight found for edge %v", edge)
}
func ( g * WeightedGraph ) Weight ( from , to graph . NodeID ) ( Weight , error ) { if ! g . IsEdgeValid ( from , to ) { return 0 , fmt . Errorf ( " " , from , to ) } edge := graph . EdgeID { From : from , To : to } fromToWeight , ok := g . weights [ edge ] if ok { return fromToWeight , nil } if g . Directed ( ) { return 0 , fmt . Errorf ( " " , edge ) } toFromWeight , ok := g . weights [ edge . Reverse ( ) ] if ok { return toFromWeight , nil } return 0 , fmt . Errorf ( " " , edge ) }
Weight return the weight of the edge
Weight return the weight of the edge
//for undirected graph, still need to check reverse // for undirected graph, both from-to and to-from weight not found