NetworkX

Previous topic

networkx.algorithms.shortest_paths.weighted.bellman_ford

Next topic

networkx.algorithms.shortest_paths.dense.floyd_warshall_predecessor_and_distance

networkx.algorithms.shortest_paths.dense.floyd_warshall

networkx.algorithms.shortest_paths.dense.floyd_warshall(G)

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

Parameters :

G : NetworkX graph

Returns :

distance : dict

A dictionary, keyed by source and target, of shortest paths distances between nodes.

See also

floyd_warshall_predecessor_and_distance, floyd_warshall_numpy, all_pairs_shortest_path, all_pairs_shortest_path_length

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).