【问题标题】:Underlying algorithm used by OSMNx package to find shortest route?OSMNx 包用于查找最短路线的底层算法?
【发布时间】:2023-01-26 18:41:07
【问题描述】:

NetworkX 库中的 shortest_path 函数默认使用 Dijkstra 算法来获得最小化总长度的最佳路径。

route = nx.shortest_path(G, origin_node, destination_node, weight = 'length')

OSMNx 函数用于查找最短路径的算法是什么?

route = ox.shortest_path(G, orig, dest, weight="length")

该函数是否也使用 Dijkstra 算法?

【问题讨论】:

    标签: python shortest-path osmnx


    【解决方案1】:

    它依赖于 NetworkX shortest_path 函数,如您在 osmnx 源代码中所见:

    https://github.com/gboeing/osmnx/blob/66775dbb723ab8c605ff8a8eb061647147c25381/osmnx/_api.py#L9

    -> https://github.com/gboeing/osmnx/blob/c034e2bf670bd8e9e46c5605bc989a7d916d58f3/osmnx/distance.py#L377-L442

    --> https://github.com/gboeing/osmnx/blob/c034e2bf670bd8e9e46c5605bc989a7d916d58f3/osmnx/distance.py#L370-L374

    def _single_shortest_path(G, orig, dest, weight):
        (...)
        return nx.shortest_path(G, orig, dest, weight=weight)
    
    def shortest_path(G, orig, dest, weight="length", cpus=1):
        (....)
        paths = [_single_shortest_path(G, o, d, weight) for o, d in zip(orig, dest)]
    
    

    此代码摘要中函数之间的链接:

    所以是的,是Dijkstra

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-30
      • 1970-01-01
      • 2015-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多