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