Python 为什么星星比迪克斯特拉快';s即使在networkx中启发式设置为“无”

Python 为什么星星比迪克斯特拉快';s即使在networkx中启发式设置为“无”,python,time,networkx,dijkstra,a-star,Python,Time,Networkx,Dijkstra,A Star,这是我上一个问题的更新版本。我在Jupyter笔记本的两点之间运行NetworkX中的两个算法(您可以在现在的任何网络上尝试)。结果表明,即使在启发式为“无”的情况下,astar也要快得多。我想“无”意味着这是一个迪克斯特拉。我错了吗 import osmnx as ox import networkx as nx G = ox.graph_from_place('Manhattan, New York, USA', network_type='drive') #change to a simp

这是我上一个问题的更新版本。我在Jupyter笔记本的两点之间运行NetworkX中的两个算法(您可以在现在的任何网络上尝试)。结果表明,即使在启发式为“无”的情况下,astar也要快得多。我想“无”意味着这是一个迪克斯特拉。我错了吗

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)
迪克斯特拉:

%%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正在使用的不会在到达目标节点时停止。A*实现确实如此。

其他人注意:
heuristic=None
意味着源代码中的
heuristic=lambda:0
。所以这并不像我第一次猜测的那样聪明。