I'm using networkx to calculate the shortest distance(in terms of weight) between two vertexes in a directed, weighted graph. I think that the dijkstra_path_length algorithm is the right one to use here, but I don't understand what I have to put as a default parameter for the weight in order to get the results I want.
import networkx as nx
G = nx.MultiDiGraph()
G.add_nodes_from(['A', 'B', 'C', 'D', 'E'])
G.add_edge('A', 'B', 5)
G.add_edge('B', 'C', 4)
G.add_edge('C', 'D', 8)
G.add_edge('D', 'C', 8)
G.add_edge('D', 'E', 6)
G.add_edge('A', 'D', 5)
G.add_edge('C', 'E', 2)
G.add_edge('E', 'B', 3)
G.add_edge('A', 'E', 7)
Here is the graph I input. I have to calculate the shortest path (in terms of weight) from A to C (its A-B-C with weight=9) but whatever I do the only answer I get is 2 (the number of edges, as if the graph has no weight). The correct answer should be 9.