rustworkx.graph_dijkstra_shortest_paths#

graph_dijkstra_shortest_paths()#

Find the shortest path from a node

This function will generate the shortest path from a source node using Dijkstra’s algorithm.

Parameters:
  • graph (PyGraph) –

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

  • target (int) – An optional target to find a path 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.

  • as_undirected (bool) – If set to true the graph will be treated as undirected for finding the shortest path.

Returns:

Dictionary of paths. The keys are destination node indices and the dict values are lists of node indices making the path.

Return type:

dict

Raises:

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