rustworkx.find_negative_cycle#

find_negative_cycle(graph, edge_cost_fn, /)#

寻找图的负环

本函数将使用带SPFA启发式的Bellman-Ford算法,在图中寻找任意负循环。

Parameters:
  • graph (PyDiGraph) – 要使用的输入图

  • edge_cost_fn – 一个Python可调用对象,它将接收1个参数,即边的数据对象,并返回一个表示该边成本的浮点数。

Returns:

一个任意的负循环中包含的节点列表(如果存在)

Return type:

NodeIndices

Raises:

ValueError: when there is no cycle in the graph provided