这是我上一个问题的更新版本。我在Jupyter notebook的两个点之间用NetworkX运行了两个算法(你可以在你的任何now网络上尝试它)。结果表明,即使在启发式为None的情况下,astar也要快得多。我认为‘无’意味着它是Dijkstra。我说错了吗?
import osmnx as ox
import networkx as nx
G = ox.graph_from_place('Manhattan, New York, USA', network_type='drive')
#change to a simple network in order to run Astar
G_simple=nx.Graph(G)
Dijkstra:
%%time
nx.dijkstra_path(G_simple, 42434910, 595314027, weight='length') #the node is random selected from nodes in the graph
计算时间为:
CPU times: user 15.4 ms, sys: 1.86 ms, total: 17.2 ms
Wall time: 17.1 ms
Astar:
%%time
nx.astar_path(G_simple, 42434910, 595314027, heuristic=None, weight='length')
计算时间为:
CPU times: user 8.8 ms, sys: 313 µs, total: 9.12 ms
Wall time: 9.18 ms
发布于 2017-08-14 23:35:46
正在使用的Dijkstra implementation NetworkX在到达目标节点时不会停止。A*实现做到了。
https://stackoverflow.com/questions/45684425
复制