每对边缘的简单路径的独特组合

问题描述

我有一个大型网络,在那里我可以计算“所有简单路径”,但是很耗时。而且,我需要每对边缘都具有所有简单路径。这是一个由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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...