寻找独特的循环闭合曲线图曲线图、独特

2023-09-11 23:23:25 作者:親吻ωǒ資夲

我终于写了一个code找出所有的循环可能与当前的配置。例如,对于下面的图像,下面是输入到我的程序

I finally managed to write a code to identify all the loops possible with the current configuration. For example, for the image below, the following is the input to my program.

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()

现在,我已经从我的输出过滤数据,以找到独特的循环硬的时间。

Now, I have hard-time in filtering the data from my output to find the unique 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]
--------------------------------------------------------

我用递归(还有什么可能是更好的选择?)来解决这个问题。现在,当我得到的结果,我发现很难筛选这些结果,并找到独特的循环。我的图论的认识是有限的(我刚开始读它)。什么可能是发现这个标识环的唯一循环的有效途径?

I used the recursion( what else might be the better choice?) to solve the problem. Now after I obtain the result, I am finding it difficult to filter those results and to find the unique loops. My understanding of graph theory is limited( I just started reading about it). What might be the effective way of finding the unique loop from this identified loops?

感谢您一个答案这表明,重复循环有逆转时保持相同的性能。对于例如:

Thanks for one answer which suggested that duplicate loop has the property of staying the same when reversed. For eg:

[1,2,3,1]
[1,3,2,1]
[2,3,1,2]

IFF它开始从相同的顶点作为第一和第二个在上述情况下,扭转将表明,这些都是相同的循环,但在第三种情况下,虽然是相同的循环作为第2,情况有点麻烦。现在反向应通过在该循环中的第三顶点进行。当顶点的数目形成循环增加这种并发症将增加。这样,有效地简化了此问题的任何算法?我在这里看到一些递归模式,但仍是有点复杂,就趴知道,如果有人能提出简单的解决方案。

Iff it starts from the same vertex as first and second one in above case, reversing will indicate that those are same loops but in the third case, although it is the same loop as the first two, the situation is little tricky. Now the reverse should be done through the third vertex in that loop. This complication will increase when the number of vertex forming the loop increases. As such, any algorithms that effectively simplifies this problem? I see some recursive pattern here but still it is little complicated and would lie to know if somebody can suggest simple solutions.

推荐答案

请注意,一个循环重复具有这样的性质,如果你扭转它的顺序,你会得到原始循环。

Note that a loop duplicate has the property that if you reverse the order of it you'll get the original loop.

为了让您的生活更轻松,你可以决定你将采取具有较小的字典索引您的解决方案的循环。这意味着,如果你发现了环 1→3→2→1 1→2→3 - →1 (这是由你的定义相同),你会采取 1→2→3→1 到该溶液中。

To make your life easy, you can decide that you'll take the loop that has the lesser lexicographic index to your solution. Which means, if you found the loops 1->3->2->1 and 1->2->3->1 (which are equal by your definition), you'll take 1->2->3->1 to the solution.

从这一点出发是将扭转你发现的每个循环中,如果反向模式具有比原始低级词典索引,忽略环路的最佳方式。否则将其添加到该溶液中。

Best way to proceed from this point would be to reverse each loop you found, if the reverse mode has a lower lexicographic index than the original, ignore the loop. otherwise add it to the solution.

您可以通过非常简单的方法,检查词典的索引,只是创建了一批出顶点的顺序。

You can check the lexicographic index by a very simple method, just create a number out of the order of vertices.

例如:翻译 1→2→3→1 1231 1→3→2→1 1321 1231 小于 1321 ,从而 1→2→3→ 1 将采取的解决方案和 1→3→2→1 将被忽略

For example: translate 1->2->3->1 to 1231 and 1->3->2->1 to 1321. 1231 is less than 1321, thus 1->2->3->1 will be taken to the solution and 1->3->2->1 will be ignored.

编辑:

为了消除重复的循环,不共享同一起跑线(如在你的榜样, 1→3→2→1 2→1→3→2 ,你可以忽略它的第一个顶点索引不是最小的指数环中的任何环这里 2→1→3→2 可以忽略不计的指数 2 是不是最小的循环。

In order to eliminate duplicated loops that don't share the same starting (like in your example, 1->3->2->1 and 2->1->3->2, you can ignore any loop for which the first vertex index is not the smallest index in the loop. here 2->1->3->2 can be ignored as the index 2 is not the smallest in the loop.