python - 为什么 A star 比 Dijkstra 更快,即使启发式在网络中设置为 Nonex

标签 python time networkx dijkstra a-star

这是我之前问题的更新版本。我在 Jupyter notebook 的两点之间运行 NetworkX 中的两种算法(你可以在你现在的任何网络上尝试)。结果显示 astar 更快,即使启发式为 None。我想“无”意味着它是 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)

迪杰斯特拉:

%%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

最佳答案

Dijkstra implementation NetworkX 正在使用,到达目标节点时不会停止。 A* 实现。

关于python - 为什么 A star 比 Dijkstra 更快,即使启发式在网络中设置为 Nonex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45684425/

相关文章:

php - 通过从 curl_getinfo() 获取详细信息来获取 cURL 请求的时间

python - NetworkX 图形对象不可订阅

python - 在 networkx 中从节点名称映射到它的索引,反之亦然

python - 使用 BeautifulSoup 将 <a> 定位到特定属性

php - 给定一个时间,如何找到一个月前的时间

c - C中两毫秒之间的差异

python - Self Join Pandas 后如何获得两列之间的唯一关系?

python - 连接字符串的大多数 Pythonic 方式

python - 将字符串添加到 Python 列表

python - Spark : pyspark crash for some datasets - ubuntu