寻找从所有节点到节点的最短路径的有效算法?
Efficent algorithm for finding the shortest paths from ALL nodes to a node?
我对寻找网络中所有点到特定点的最短路径很感兴趣。到目前为止,我一直在通过遍历所有点计算最短路径来估算这一点。
随着网络规模的增加,这种方法的计算成本很高。有有效的替代方案吗?我忽略了 NetworkX 中的任何内容?
# Pseudocode
For a_node in list_of_nodes:
shortest_path_to_poi = nx.shortest_path(G, source=a_node, target=poi, method='dijkstra')
感谢您的时间和考虑。
Dijkstra 算法通常通过查找从源节点到每个其他节点的所有最短路径来实现 - 参见例如 wikipedia. In NetworkX, you can use nx.single_source_dijkstra.
lengths, paths = nx.single_source_dijkstra(G, source=poi)
# paths[v] is the shortest path from poi to the vertex with index v
另请参阅 nx 文档中的 shortest paths reference。
我对寻找网络中所有点到特定点的最短路径很感兴趣。到目前为止,我一直在通过遍历所有点计算最短路径来估算这一点。
随着网络规模的增加,这种方法的计算成本很高。有有效的替代方案吗?我忽略了 NetworkX 中的任何内容?
# Pseudocode
For a_node in list_of_nodes:
shortest_path_to_poi = nx.shortest_path(G, source=a_node, target=poi, method='dijkstra')
感谢您的时间和考虑。
Dijkstra 算法通常通过查找从源节点到每个其他节点的所有最短路径来实现 - 参见例如 wikipedia. In NetworkX, you can use nx.single_source_dijkstra.
lengths, paths = nx.single_source_dijkstra(G, source=poi)
# paths[v] is the shortest path from poi to the vertex with index v
另请参阅 nx 文档中的 shortest paths reference。