NetworkX

Previous topic

networkx.floyd_warshall

Next topic

networkx.dijkstra_path_length

networkx.dijkstra_path

dijkstra_path(G, source, target, weight='weight')

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

Parameters:

G : NetworkX graph

source : node

Starting node

target : node

Ending node

weight: string, optional :

Edge data key corresponding to the edge weight

Returns:

path : list

List of nodes in a shortest path.

Notes

Uses a bidirectional version of Dijkstra’s algorithm. Edge weight attributes must be numerical.

Examples

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