【发布时间】:2018-11-06 12:58:53
【问题描述】:
Graph-tool 提供了许多用于评估图表的工具:https://graph-tool.skewed.de/static/doc/topology.html。但是,我找不到任何计算周长的方法,即图中的最短周期。
您知道是否存在适当的方法,或者我是否可以使用现有的方法来进行有效的计算?
【问题讨论】:
标签: python graph-theory graph-tool
Graph-tool 提供了许多用于评估图表的工具:https://graph-tool.skewed.de/static/doc/topology.html。但是,我找不到任何计算周长的方法,即图中的最短周期。
您知道是否存在适当的方法,或者我是否可以使用现有的方法来进行有效的计算?
【问题讨论】:
标签: python graph-theory graph-tool
我认为这可以使用all_paths 函数轻松计算。
g = gt.collection.data["karate"]
min_cycle_lengths = []
for v in g.vertices():
cycles_v = list(gt.all_paths(g, source = v, target = v))
min_cycle_lengths.append(min([len(x)-1 for x in cycles_v if len(x) > 3]))
girth = min(min_cycle_lengths)
【讨论】: