这是我之前问题的更新版本。我在 Jupyter 笔记本中的两点之间运行 NetworkX 中的两种算法(您可以在任何现在的网络上尝试(。结果表明,即使启发式为 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
阿斯塔尔:
%%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
NetworkX 使用的 Dijkstra 实现在到达目标节点时不会停止。A* 实现确实如此。