问题描述
我正在使用igraph
生成顶点对之间的最短路径距离矩阵,但是我不知道如何返回顶点.到目前为止,我有:
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:
path_length_matrix = ig_graph.shortest_paths_dijkstra(None,None,"distance", "ALL")
我正在寻找一个返回路径矩阵(如距离矩阵)的函数,但在 igraph文档,其中显示了如何获取路径.
I'm looking for a function which returns a matrix of paths like the matrix of distances but I can't see anything in the igraph documentation which shows how to get the paths.
推荐答案
我相信您需要的功能是get_shortest_paths
.请参见 http://packages.python.org/python-igraph/igraph.GraphBase-class.html#get_shortest_paths
The function you need is get_shortest_paths
I believe. See http://packages.python.org/python-igraph/igraph.GraphBase-class.html#get_shortest_paths
您需要为每个源顶点分别调用它,并且它将为每对节点仅提供一条(任意)最短路径.如果您需要所有最短路径,请参见get_all_shortest_paths
: http: //packages.python.org/python-igraph/igraph.GraphBase-class.html#get_all_shortest_paths
You need to call it individually for each source vertex, and it will give you only a single (arbitrary) shortest path for each pair of nodes. If you need all shortest paths, then see get_all_shortest_paths
: http://packages.python.org/python-igraph/igraph.GraphBase-class.html#get_all_shortest_paths
这篇关于如何使用igraph获取最短路径上的顶点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!