我正在使用A*算法解决8数码难题。在这个求解器中,我实现了曼哈顿距离和错位启发式函数。在某些情况下,求解器可以正常工作。但有时会花费很长时间才能找到解决方案。我认为我的问题之一在于查找开放列表(等待扩展)中具有最低值的节点的函数。
a part of psedocode(from wiki)
while openset is not empty
x := the node in openset having the lowest f_score[] value
if x = goal
return reconstruct_path(came_from, came_from[goal])
................................
那么找到最低 f_score 值的最好方法是什么?只需找到最小值,还是我们必须在添加状态时修改列表(在添加状态时对列表进行排序),这样最小值将位于第一个位置。