bidirectional_shortest_path#
- bidirectional_shortest_path(G, source, target)[源代码]#
返回源节点与目标节点之间的最短路径中的节点列表。
- 参数:
- GNetworkX 图
- source节点标签
路径的起始节点
- target节点标签
路径的结束节点
- 返回:
- path: list
从源节点到目标节点的路径中的节点列表。
- 引发:
- NetworkXNoPath
如果在源节点和目标节点之间不存在路径。
另请参阅
shortest_path
说明
shortest_path(G, source, target) 使用此算法。
示例
>>> 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] ----
其他后端实现了此函数
cugraph : GPU 加速后端。