all_pairs_dijkstra_path#

all_pairs_dijkstra_path(G, cutoff=None, weight='weight')[source]#

计算加权图中所有节点之间的最短路径。

Parameters:
GNetworkX 图
cutoff整数或浮点数, 可选

搜索停止的长度(边权重的总和)。 如果提供了 cutoff,则仅返回总权重 <= cutoff 的路径。

weight字符串或函数

如果这是一个字符串,则将通过具有此键的边属性访问边权重(即,连接 uv 的边的权重将是 G.edges[u, v][weight] )。如果没有这样的边属性存在,则假设边的权重为 1。

如果这是一个函数,则边的权重是该函数返回的值。该函数必须接受三个位置参数:一条边的两个端点和该边的边属性字典。该函数必须返回一个数字或 None 以表示隐藏的边。

Returns:
paths迭代器

(源节点, 字典) 迭代器,字典以目标节点为键,最短路径为键值。

See also

floyd_warshall, all_pairs_bellman_ford_path

Notes

边权重属性必须是数值。 距离计算为遍历的加权边的总和。

Examples

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

Additional backends implement this function

parallelParallel backend for NetworkX algorithms

The parallel implementation first divides the nodes into chunks and then creates a generator to lazily compute shortest paths for each node_chunk, and then employs joblib’s Parallel function to execute these computations in parallel across all available CPU cores.

Additional parameters:
get_chunksstr, function (default = “chunks”)

A function that takes in an iterable of all the nodes as input and returns an iterable node_chunks. The default chunking is done by slicing the G.nodes into n chunks, where n is the number of CPU cores.

[Source]