Using the networkx library, I define a MultDiGraph. I then calculate the shortest path between two given nodes. As my graph holds parallel edges, I would like to know the keys of the edges that make up the shortest path. Here's an example:
import networkx as nx
G = nx.MultiDiGraph()
G.add_edge('a', 'b', key=0, weight=1)
G.add_edge('a', 'b', key=1, weight=2)
G.add_edge('b', 'c', key=0, weight=1)
shortest_path = nx.shortest_path(G, source='a', target='c')
shortest_path_length = nx.shortest_path_length(G, source='a', target='c')
print(shortest_path)
print(shortest_path_length)
The result looks like this:
['a', 'b', 'c']
2
This is only correct if the shortest path between nodes 'a' and 'b' is via the key=0 (weight=1). I couldn't find anything in the docs that would allow me to retrieve the keys of the actual edges involved in the shortest path. How could I get to this information?