rustworkx.digraph_all_pairs_dijkstra_shortest_paths#

digraph_all_pairs_dijkstra_shortest_paths(graph, edge_cost_fn, /)#

For each node in the graph, finds the shortest paths to all others in a PyDiGraph object

This function will generate the shortest paths from all nodes in the graph Dijkstra’s algorithm. This function is multithreaded and will run launch a thread pool with threads equal to the number of CPUs by default. You can tune the number of threads with the RAYON_NUM_THREADS environment variable. For example, setting RAYON_NUM_THREADS=4 would limit the thread pool to 4 threads.

Parameters:
  • graph – The input PyDiGraph object to use

  • edge_cost_fn – A callable object that acts as a weight function for an edge. It will accept a single positional argument, the edge’s weight object and will return a float which will be used to represent the weight/cost of the edge

Returns:

A read-only dictionary of paths. The keys are source node indices and the values are dicts of the target node and the list of the node indices making up the shortest path to that node. For example:

{
    0: {1: [0, 1],  2: [0, 1, 2]},
    1: {2: [1, 2]},
    2: {0: [2, 0]},
}

Return type:

AllPairsPathMapping

Raises:

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