Skip to content

Instantly share code, notes, and snippets.

@MrYawe
Last active September 21, 2016 12:39
Show Gist options
  • Save MrYawe/cc8a420d426ac0d79454c67f09327b21 to your computer and use it in GitHub Desktop.
Save MrYawe/cc8a420d426ac0d79454c67f09327b21 to your computer and use it in GitHub Desktop.
from igraph import *
g = Graph(11)
g.vs["name"]=["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K"]
g.add_edges([
("A","B"),("A","C"),("A","D"),
("B","E"),("B","G"),
("C","E"),("C","F"),("E","G"),("E","H"),
("D","E"),("D","G"),("D","H"),
("E","I"),("E","J"),
("F","I"),("F","J"),
("G","I"),("G","J"),
("H","J"),
("I","K"),
("J","K")
])
ww=[
8, 5, 7,
3, 4,
5, 4, 6, 4,
3, 2, 3,
4, 5,
4, 4,
3, 2,
4,
5, 7
]
print g
g.vs["label"]=g.vs["name"]
layout = g.layout_kamada_kawai()
layout._coords = [
[0, 0],
[1, -1], [1, 0], [1, 1],
[2, -2], [2, -1], [2, 0], [2, 1],
[3, 1], [3 ,0],
[4, 0]
]
print layout
# Shortest path
print g.shortest_paths_dijkstra(source="A", target="K", weights=ww, mode=OUT)
print g.get_shortest_paths("A", to="K", weights=ww)
# Show graph
plot(g, layout = layout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment