bidirectional_shortest_path#
- bidirectional_shortest_path(G, source, target)[source]#
返回从源到目标的最短路径上的节点列表。
- Parameters:
- GNetworkX 图
- source节点标签
路径的起始节点
- target节点标签
路径的结束节点
- Returns:
- path: 列表
从源到目标的路径上的节点列表。
- Raises:
- NetworkXNoPath
如果源和目标之间不存在路径。
See also
shortest_path
Notes
此算法被 shortest_path(G, source, target) 使用。
Examples
>>> G = nx.Graph() >>> nx.add_path(G, [0, 1, 2, 3, 0, 4, 5, 6, 7, 4]) >>> nx.bidirectional_shortest_path(G, 2, 6) [2, 1, 0, 4, 5, 6]