all_pairs_shortest_path#

all_pairs_shortest_path(G, cutoff=None)[源代码]#

计算所有节点之间的最短路径。

参数
G网络X图表
cutoff整数,可选

停止搜索的深度。仅限最多长度的路径 cutoff 都被退回了。

返回
lengths词典

以源和目标为关键字的最短路径词典。

参见

floyd_warshall

实例

>>> G = nx.path_graph(5)
>>> path = dict(nx.all_pairs_shortest_path(G))
>>> print(path[0][4])
[0, 1, 2, 3, 4]