Ask Your Question

Revision history [back]

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

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')])

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']]