簡體   English   中英

查找從所有節點到節點的最短路徑的有效算法?

[英]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 在 NetworkX 中,您可以使用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 文檔中的最短路徑參考

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM