由网友(心与口不同)分享简介:考虑我的下图:A -> BB -> CC -> DC -> A什么是要找到一个最简单的方法 - 乙 - ç - > A是圆形的关系?有没有已经建成NetworkX这样的功能或其他容易使用Python库?What is the easiest way to find that A -> B -> C -> A...
考虑我的下图:
A -> B
B -> C
C -> D
C -> A
什么是要找到一个最简单的方法 - 乙 - ç - > A是圆形的关系?有没有已经建成NetworkX这样的功能或其他容易使用Python库?
What is the easiest way to find that A -> B -> C -> A is a circular relation? Is there such a function already built into NetworkX or another easy to use Python library?
推荐答案
networkx.simple_cycles这是否给你。
networkx.simple_cycles
does this for you.
>>> import networkx as nx
>>> G = nx.DiGraph()
>>> G.add_edge('A', 'B')
>>> G.add_edge('B', 'C')
>>> G.add_edge('C', 'D')
>>> G.add_edge('C', 'A')
>>> nx.simple_cycles(G)
[['A', 'B', 'C', 'A']]
相关推荐
最新文章