如何解决每对边缘的简单路径的独特组合
我有一个大型网络,在那里我可以计算“所有简单路径”,但是很耗时。而且,我需要每对边缘都具有所有简单路径。这是一个由5个节点组成的小型网络的示例。
gg = nx.complete_graph(6) # Create nework
nx.draw(gg,with_labels = True) # Plot it
edgelist = nx.to_edgelist(gg) # Extract edges
sources = [s for s,t,d in edgelist]
targets = [t for s,d in edgelist]
# Calculate all paths per each pair of edges
for source in sources:
for target in targets:
paths = nx.all_simple_paths(gg,source,target,cutoff=None) # Calculate all paths
s = set(map(frozenset,paths)) # Avoid repetion such as [4,1,3,5],[4,5]
non_redundant_paths = [[source,*[*p-{source,target}],target] for p in s]
nx.set_edge_attributes(gg,'unique_paths',non_redundant_paths)
这里的问题是每对都给我相同的所有路径。 我想要每个特定节点对的所有路径。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。