NetworkX

Previous topic

networkx.all_pairs_shortest_path_length

Next topic

networkx.dijkstra_path_length

networkx.dijkstra_path

dijkstra_path(G, source, target)

Returns the shortest path from source to target in a weighted graph G.

Uses a bidirectional version of Dijkstra’s algorithm.

Parameters:

G : NetworkX graph

source : node label

starting node for path

target : node label

ending node for path

Notes

Edge data must be numerical values for Graph and DiGraphs.

Examples

>>> G=nx.path_graph(5)
>>> print nx.dijkstra_path(G,0,4)
[0, 1, 2, 3, 4]