标准方法如下:AI:一种现代方法
function UNIFORM-COST-SEARCH
node <- INITIAL-STATE
frontier <- priority queue ordered by PATH-COST, with node as the only element
explored <- an empty set
loop 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-Modified
node <- INITIAL-STATE
frontier <- priority queue ordered by PATH-COST, with node as the only element
explored <- an empty set
loop 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)
所以我不在乎边界是否包含重复的状态。我只扩展了边界中重复状态中的第一个。由于路径成本是consistent
,并且边界是使用 实现的priority queue
,因此忽略其他成本较高的重复状态是无害的。
合理吗?
更新
对不起,我忘了提到我对一致的启发式案例特别感兴趣。