rustworkx.all_shortest_paths#

all_shortest_paths(graph, source, target, weight_fn=None, default_weight=1.0, as_undirected=False)[source]#

Find all shortest paths between two nodes

This function will generate all possible shortest paths from a source node to a target using Dijkstra’s algorithm.

Parameters:
  • graph – The input graph to find the shortest paths for

  • source (int) – The node index to find paths from

  • target (int) – A target to find paths to

  • weight_fn – An optional weight function for an edge. It will accept a single argument, the edge’s weight object and will return a float which will be used to represent the weight/cost of the edge

  • default_weight (float) – If weight_fn isn’t specified this optional float value will be used for the weight/cost of each edge.

Returns:

List of paths. Each paths are lists of node indices, starting at source and ending at target.

Return type:

list

Raises:

ValueError – when an edge weight with NaN or negative value is provided.