Skip to content

Instantly share code, notes, and snippets.

@MrYawe
Created September 28, 2016 13:00
Show Gist options
  • Save MrYawe/88ca5a4ea3fea3c21f52c6069316100c to your computer and use it in GitHub Desktop.
Save MrYawe/88ca5a4ea3fea3c21f52c6069316100c to your computer and use it in GitHub Desktop.
from igraph import *
g = Graph(16, directed=True)
g.add_edges([
(0,1), (0,2), (0,3),
(1,4),
(2, 4), (2,5),
(3,5), (3,6),
(4,7), (4,8),
(5,8), (5,9), (5,10),
(6,10),
(7,11),
(8,11), (8,12), (8,13),
(9,13),
(10,13), (10,14),
(11,15),
(12,15),
(13,15),
(14,15)
])
ww=[
10, 12, 15,
5,
5, 15,
15, 10,
3, 10,
10, 5, 20,
20,
4,
4, 5, 20,
20,
20, 7,
-550,
-580,
-590,
-600
]
# print g.shortest_paths_dijkstra(source=0, target=15, weights=ww, mode=OUT)
# print g.shortest_paths_bellman_ford(source=0, target=15, weights=ww, mode=OUT)
print g.shortest_paths(source=0, target=11, weights=ww)
print g.shortest_paths(source=0, target=12, weights=ww)
print g.shortest_paths(source=0, target=13, weights=ww)
print g.shortest_paths(source=0, target=14, weights=ww)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment