Note

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.

rustworkx.negative_edge_cycle#

negative_edge_cycle(graph, edge_cost_fn, /)#

Check if a negative cycle exists on a graph

This function will check for the existence of a negative cycle in a graph using the Bellman-Ford algorithm with the SPFA heuristic.

Parameters:
  • graph (PyDiGraph) – The input graph to use

  • edge_cost_fn – A python callable that will take in 1 parameter, an edge’s data object and will return a float that represents the cost of that edge.

Returns:

True if there is a negative cycle or False otherwise

Return type:

bool