Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 2 years ago

licheng gravatar image

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')])
click to hide/show revision 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')])
click to hide/show revision 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']]