为什么 NetworkX find_cycle 函数不产生涉及指定源顶点的输出?

问题描述

在 NetworkX 中采用以下无向图对象。

G_3 = nx.Graph()
G_3.add_nodes_from([1,2,3,4,5])
G_3.add_weighted_edges_from([(1,1),(2,1,(4,(3,(1,(5,1)])

图形看起来像这样。有三个基本循环,我想使用函数 nx.cycle_basisnx.find_cycle获取构成每个循环的节点和边的列表。

enter image description here

当我使用 nx.cycle_basis 时,我得到以下结果:

cycles_3 = [c for c in nx.cycle_basis(G_3)]
print(cycles_3)
>>> [[2,5,1],[2,4]] 

这是正确的输出。但是,当我使用 nx.find_cycle 函数时,我最终得到以下输出

num_nodes = len(G_3.nodes())
edges_in_cycle = {}

for i in range(1,num_nodes+1):
  edges_in_cycle[i] = nx.find_cycle(G_3,i)`

edges_in_cycle
>>>
{1: [(2,4),3),2)],2: [(2,3: [(2,4: [(4,2),4)],5: [(2,2)]}

nx.find_cycle(G_3,source=5) 如何产生不涉及顶点 5 的输出?请告诉我如何使用此函数提取特定循环的边缘信息。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)