This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.


graph_all_pairs_bellman_ford_shortest_paths(graph, edge_cost_fn, /)#

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

This function will generate the shortest path from a source node using the Bellman-Ford algorithm.

  • graph – The input PyGraph 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


A read-only dictionary of paths. The keys are destination 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:



NegativeCycle: when there is a negative cycle and the shortest path is not defined.