NetworkX

Previous topic

networkx.algorithms.shortest_paths.dense.floyd_warshall_predecessor_and_distance

Next topic

networkx.algorithms.shortest_paths.astar.astar_path

networkx.algorithms.shortest_paths.dense.floyd_warshall_numpy

networkx.algorithms.shortest_paths.dense.floyd_warshall_numpy(G, nodelist=None)

Find all-pairs shortest path lengths using Floyd’s algorithm.

Parameters :

G : NetworkX graph

nodelist : list, optional

The rows and columns are ordered by the nodes in nodelist. If`nodelist is None then the ordering is produced by G.nodes().

Returns :

distance : NumPy matrix

A matrix of shortest path distances between nodes. If there is no path between to nodes the corresponding matrix entry will be Inf.

Notes

Floyd’s algorithm is appropriate for finding shortest paths in dense graphs or graphs with negative weights when Dijkstra’s algorithm fails. This algorithm can still fail if there are negative cycles. It has running time O(n^3) with running space is O(n^2).