single_source_shortest_path_length#
- single_source_shortest_path_length(G, source, cutoff=None)[源代码]#
计算从源到所有可到达节点的最短路径长度。
- 参数
- G网络X图表
- source结点
路径的起始节点
- cutoff整数,可选
深度以停止搜索。仅返回长度<=截止的路径。
- 返回
- lengthsDICT
以节点为关键字的到源的最短路径长度的字典。
参见
shortest_path_length
实例
>>> G = nx.path_graph(5) >>> length = nx.single_source_shortest_path_length(G, 0) >>> length[4] 4 >>> for node in length: ... print(f"{node}: {length[node]}") 0: 0 1: 1 2: 2 3: 3 4: 4