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:
sourcenode

Starting node for path

targetnode

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:
pathlist

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

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

Notes

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