标准方法如下: AI: 现代方法
function UNIFORM-COST-SEARCHnode <- INITIAL-STATEfrontier <- priority queue ordered by PATH-COST, with node as the only elementexplored <- an empty setloop do if frontier is empty then return failure node <- POP frontier /* chooses the lowest-cost node in frontier */ if GOAL-TEST(node) then return SOLUTION(node) add node to explored for each action in ACTIONS(node) do child <- CHILD-NODE(problem, node, action) if child is not in explored or frontier then frontier.INSERT(child) else if child is in frontier with higher PATH-COST then replace that frontier node with child
这里这一步实现起来很复杂,普通的优先级队列无法高效地更新某个元素的优先级。
else if child is in frontier with higher PATH-COST then replace that frontier node with child
我在考虑以下方式修改算法:
function UNIFORM-COST-SEARCH-Modifiednode <- INITIAL-STATEfrontier <- priority queue ordered by PATH-COST, with node as the only elementexplored <- an empty setloop do if frontier is empty then return failure node <- POP frontier /* chooses the lowest-cost node in frontier */ > if node is in explored then continue if GOAL-TEST(node) then return SOLUTION(node) add node to explored for each action in ACTIONS(node) do child <- CHILD-NODE(problem, node, action) > if child is not in explored then frontier.INSERT(child)
所以我不在乎前沿是否包含重复状态。我只扩展前沿中第一个重复状态。由于路径成本是一致
的,并且前沿使用优先级队列
实现,忽略其他成本更高的重复状态是无害的。
这是合理的吗?
更新
抱歉,我忘了提到我特别关注一致性启发式的情况。
回答:
这个想法原则上是正确的,但有一个错误:
> if node is in explored then continue
如果启发函数不是单调的(不违反可接受性),这一行可能会导致失败。
A*允许重新探索节点,如果新成本比之前找到的更好。这些情况发生在非单调启发函数中。
你应该仅在新成本“更大”于explored
中节点附带的成本时才continue
,而不是仅当它存在于其中时。
编辑:(基于评论和问题编辑)
对于h=0
,A*实际上退化为迪杰斯特拉算法,并且由于迪杰斯特拉算法永远不需要修改已经“探索”的节点(当然假设权重为正)——该算法在这些情况下是正确的。
一般来说,在单调启发函数中不会重新访问已经访问过的节点,所以这不是问题,这种方法在这些情况下是正确的——但要注意不要将其应用于非单调启发函数中。