| 1 | initial version |
Try this:
G = nx.Graph()
e = [('1', '2', 6), ('1', '3', 2), ('1', '4', 2), ('2', '3', 1),('2','4',5),('3','4',3)]
G.add_weighted_edges_from(e)
print([p for p in nx.all_shortest_paths(G, source='1', target='2', weight='weight')])
| 2 | No.2 Revision |
Try this:
import networkx as nx
G = nx.Graph()
e = [('1', '2', 6), ('1', '3', 2), ('1', '4', 2), ('2', '3', 1),('2','4',5),('3','4',3)]
G.add_weighted_edges_from(e)
print([p for p in nx.all_shortest_paths(G, source='1', target='2', weight='weight')])
| 3 | No.3 Revision |
Try this:
import networkx as nx
G = nx.Graph()
e = [('1', '2', 6), ('1', '3', 2), ('1', '4', 2), ('2', '3', 1),('2','4',5),('3','4',3)]
G.add_weighted_edges_from(e)
print([p for p in nx.all_shortest_paths(G, source='1', target='2', weight='weight')])
# output: [['1', '3', '2']]
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.