How do I get the vertices on the shortest path using igraph?

后端 未结 3 746
北恋
北恋 2021-01-12 03:20

I\'m using igraph to generate a matrix of shortest path distances between pairs of vertices but I can\'t figure out how to return the vertices. So far I have:

3条回答
  •  执念已碎
    2021-01-12 04:18

    I do this

    from igraph import *
    g = Graph([(0,1), (0,2), (2,3), (3,4), (4,2), (2,5), (5,0), (6,3), (5,6)])
    g.vs["name"] = ["Alice", "Bob", "Claire", "Dennis", "Esther", "Frank", "George"]
    #You could create Vertexes like g.add_vertex(name="Bill") 
    path=g.get_shortest_paths("Alice",to="Frank",mode=OUT,output='vpath')
    for n in path[0]:
        print("{}".format(g.vs[n]['name']))
    

    Hope this helps

提交回复
热议问题