Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

networkx.algorithms.shortest_paths.dense.reconstruct_path

reconstruct_path(source, target, predecessors)[source]

Reconstruct a path from source to target using the predecessors dict as returned by floyd_warshall_predecessor_and_distance

Parameters:
  • source (node) – Starting node for path
  • target (node) – Ending node for path
  • predecessors (dictionary) – Dictionary, keyed by source and target, of predecessors in the shortest path, as returned by floyd_warshall_predecessor_and_distance
Returns:

path – A list of nodes containing the shortest path from source to target

If source and target are the same, an empty list is returned

Return type:

list

Notes

This function is meant to give more applicability to the floyd_warshall_predecessor_and_distance function