这是我之前提问的更新版本。我在NetworkX中运行两个算法,在Jupyter笔记本中两点之间(你可以在任何现在的网络上试试)。结果表明,即使启发式算法为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