我使用networkx创造一个无向图。我想找到的所有特定的节点可能圆形路径?有没有什么办法让那些因为我无法找到一个方法?
尝试:
import pandas as pd
import networkx as nx
df = pd.DataFrame({'Source':[0,1,2,0,16,17,18,0,16,19,1,2],'Target':[1,2,3,3,17,18,19,16,19,3,17,18]})
G = nx.from_pandas_edgelist(df, 'Source', 'Target')
nx.cycles.find_cycle(G)
输出:
[(0, 1), (1, 2), (2, 3), (3, 0)]