如果没有路径,NetworkX return in single_source_dijkstra_path_length 是什么意思

What does NetworkX return in single_source_dijkstra_path_length if there is no path

我有一个有向图,我正在使用 NetworkX 查找从一个节点到所有节点的最短长度。为此,我使用 single_source_dijkstra_path_length。在文档中,他们说当给定节点不在图中时会引发 NodeNotFound 错误。但是,我想知道对于从给定源无法访问(不存在路径)的节点,它会输出什么。

节点根本不包含在返回的字典中:

import networkx as nx

g = nx.Graph()

g.add_nodes_from(range(3))
g.add_edge(1,2, weight=2)
print(nx.single_source_dijkstra_path_length(g, 1))
# {1: 0, 2: 2}

具有sourcetarget的算法将提高NetworkXNoPath (docs) as you can see for example in the implementation of the undirected algorithms, here, or here for directed case. It is also in the documentation of dijkstra_path