[英]Shortest cycle in a graph with negative weights, repeated edges and vertices allowed
在以下条件下,我可以使用哪种算法在图形上找到最短周期:
c和n是函数的输入。
例:
With the following edge weights:
A -> B = 1
B -> A = -2
For c = -1.5, n = 10, 2 solutions are possible:
A -> B -> A -> B -> A
+1 -2 +1 -2
B -> A -> B -> A -> B
-2 +1 -2 +1
For c = -100, n = 10, no solution is possible
For c = -1.5, n = 3, no solution is possible
Example of a figure 8-like path, assuming all other edge weights are infinite:
c = -150, n = 10
A -> C -> D -> E -> C -> B -> A
-99 -99 +1 +1 +1 +1
我看过FW和BF,但不确定如何适应我的条件。
如果您没有负循环,则FW将起作用。 只需考虑所有节点对就可以查找距离并找到总和最小的节点对。
为了满足路径长度<n,您需要通过路径上的节点数来保持距离。 您可以通过保留每个步骤的距离矩阵来修改FW以实现此目的。
然后要获得解决方案,除了获得所有成对的节点外,还需要迭代一种方法采取的步骤数以及收回的步骤数。 您可以做到的是O(N ^ 3)。 由于FW也为O(N ^ 3),所以这就是您的最终复杂度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.