2

我有一个有向循环图,其中包含多个循环,我需要一种方法来检测(并列出)有向图中存在的每个循环。

该图可以在这里看到:http: //img412.imageshack.us/img412/3327/schematic.gif

这是为了调试我的 python 脚本而放在一起的虚拟图。它包含循环:

[n13, n14], [n6, n8, n15, n16, n7], [n6, n8, n9, n7]

该算法必须检测有向图中的每个循环,而不仅仅是最小的也不是它遇到的第一个。

4

3 回答 3

2

您并没有真正指定如何表示有向图,但您可以查看Neopythonic:Detecting Cycles indirected graph

于 2010-07-28T10:34:45.893 回答
1

AFAIK,python-graph 只找到一个循环,而不是所有可能的循环。看:

http://groups.google.com/group/python-graph/browse_thread/thread/9170926f1bdd097b

This other article似乎解决了这个问题中提出的问题:

http://www.bitformation.com/art/python_toposort.html

它使用的是 RE Tarjan 在 1972 年设计的算法

于 2011-07-22T16:31:01.723 回答
0

您可能想尝试使用这个。它有一个循环检测算法。

于 2011-06-19T08:38:52.933 回答