【发布时间】:2011-11-23 09:48:15
【问题描述】:
我正在根据本教程实现 A* 算法:
create the open list of nodes, initially containing only our starting node
create the closed list of nodes, initially empty
while (we have not reached our goal) {
consider the best node in the open list (the node with the lowest f value)
if (this node is the goal) {
then we're done
}
else {
move the current node to the closed list and consider all of its neighbors
for (each neighbor) {
if (this neighbor is in the closed list and our current g value is lower) {
update the neighbor with the new, lower, g value
change the neighbor's parent to our current node
}
else if (this neighbor is in the open list and our current g value is lower) {
update the neighbor with the new, lower, g value
change the neighbor's parent to our current node
}
else this neighbor is not in either the open or closed list {
add the neighbor to the open list and set its g value
}
}
}
}
现在我有两个优先队列用于打开列表和关闭列表。
将一个节点从打开列表移动到关闭列表后,我必须生成它的邻居,如果它们也在关闭列表中,则必须一一检查并执行上述操作。问题是我只能 peek() 仅队列的头部并与生成的邻居进行比较。我也无法访问队列中的其余节点以进行比较。
我的问题是:
如何将邻居与封闭列表中的节点进行比较。或者我应该为封闭列表使用不同的数据结构?
谢谢
【问题讨论】:
标签: java algorithm path-finding