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.find_negative_cycle#

find_negative_cycle(graph, edge_cost_fn, /)#

Find a negative cycle of a graph

This function will find an arbitrary 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:

A list of the nodes in an arbitrary negative cycle, if it exists

Return type:

NodeIndices

Raises:

ValueError: when there is no cycle in the graph provided