2016-07-26 1 views
0

원본에서 대상까지 여러 경로가있는 경우 NetworkX를 사용하여 이러한 경로를 모두 얻으려면 어떻게해야합니까? 이 예제는 단순화 된 예제이며 실제로 nx.all_pairs_shortest_path() 함수를 사용하여 두 노드 사이의 모든 최단 경로를 가져 오려고합니다.NetworkX에 동일한 길이의 여러 경로 표시

코드 :

import networkx as nx 
G = nx.Graph([(0, 1), (0, 2), (1, 3), (2, 3)]) 
nx.draw(G) 
print(nx.shortest_path(G,0,3)) 

출력 내가 얻을 :

[[0, 1, 3], [0, 2, 3]] 

답변

0

all_shortest_paths 당신이 계신 않지만, 발전기입니다 :

[0, 1, 3] 

출력 내가 원하는. 목록을 원할 경우 list 주위에 넣으십시오.

shortest_path_generator = nx.all_shortest_paths(G,0,3) 
list(shortest_path_generator)