我终于成功地编写代码,以确定所有的循环可能与当前的配置。 例如,对于下面的图像,下面是输入到我的程序。
network2=Pipes.NetworkManager(vertices=[1,2,3,4],
nodes=[(1,2),(1,3),(1,4),(2,1),(2,3),
(2,4),(3,1),(3,2),(3,4),(4,1),(4,2),(4,3)])
network2.search_loop()
现在,我在从我的输出滤波的数据,以找到独特的循环硬的时间。
这是结果:
starting search from 1
--------------------------------------------------------
the loop is complete [1, 2, 3, 1]
the loop is complete [1, 2, 3, 4, 1]
the loop is complete [1, 2, 4, 1]
the loop is complete [1, 2, 4, 3, 1]
the loop is complete [1, 3, 2, 1]
the loop is complete [1, 3, 2, 4, 1]
the loop is complete [1, 3, 4, 1]
the loop is complete [1, 3, 4, 2, 1]
the loop is complete [1, 4, 2, 1]
the loop is complete [1, 4, 2, 3, 1]
the loop is complete [1, 4, 3, 1]
the loop is complete [1, 4, 3, 2, 1]
--------------------------------------------------------
starting search from 2
--------------------------------------------------------
the loop is complete [2, 1, 3, 2]
the loop is complete [2, 1, 3, 4, 2]
the loop is complete [2, 1, 4, 2]
the loop is complete [2, 1, 4, 3, 2]
the loop is complete [2, 3, 1, 2]
the loop is complete [2, 3, 1, 4, 2]
the loop is complete [2, 3, 4, 1, 2]
the loop is complete [2, 3, 4, 2]
the loop is complete [2, 4, 1, 2]
the loop is complete [2, 4, 1, 3, 2]
the loop is complete [2, 4, 3, 1, 2]
the loop is complete [2, 4, 3, 2]
--------------------------------------------------------
starting search from 3
--------------------------------------------------------
the loop is complete [3, 1, 2, 3]
the loop is complete [3, 1, 2, 4, 3]
the loop is complete [3, 1, 4, 2, 3]
the loop is complete [3, 1, 4, 3]
the loop is complete [3, 2, 1, 3]
the loop is complete [3, 2, 1, 4, 3]
the loop is complete [3, 2, 4, 1, 3]
the loop is complete [3, 2, 4, 3]
the loop is complete [3, 4, 1, 2, 3]
the loop is complete [3, 4, 1, 3]
the loop is complete [3, 4, 2, 1, 3]
the loop is complete [3, 4, 2, 3]
--------------------------------------------------------
starting search from 4
--------------------------------------------------------
the loop is complete [4, 1, 2, 3, 4]
the loop is complete [4, 1, 2, 4]
the loop is complete [4, 1, 3, 2, 4]
the loop is complete [4, 1, 3, 4]
the loop is complete [4, 2, 1, 3, 4]
the loop is complete [4, 2, 1, 4]
the loop is complete [4, 2, 3, 1, 4]
the loop is complete [4, 2, 3, 4]
the loop is complete [4, 3, 1, 2, 4]
the loop is complete [4, 3, 1, 4]
the loop is complete [4, 3, 2, 1, 4]
the loop is complete [4, 3, 2, 4]
--------------------------------------------------------
我用递归(还有什么可能是更好的选择吗?)来解决这个问题。 现在,在我获得的结果,我发现很难筛选这些结果,并找到独特的循环。 我的图论的理解是有限的(我刚开始读它)。 什么可能是发现从这个识别圈独特的循环的有效途径?
感谢这表明,重复循环有逆转时保持相同的属性的一个答案。 对于例如:
[1,2,3,1]
[1,3,2,1]
[2,3,1,2]
当且仅当它从同一个顶点在上述情况下,第一和第二个启动,倒车将表明,那些都是相同的循环,但在第三种情况下,虽然是同一个环路前两个,情况有点棘手。 现在相反,应通过在循环中的第三个顶点来完成。 当形成顶点的数量增加循环这种并发症会增加。 因此,能够有效地简化了这个问题的任何算法? 我在这里看到一些递归模式,但仍是有点复杂,并会骗知道如果有人能提出简单的解决方案。