今天学习了一种新的搜索方法——迭代加深算法(IDDFS)。它是一种综合了DFS和BFS的算法,核心思想在于利用DFS去做有最大深度限制的搜索,在没有找到解时逐步增加最大深度,从而得到最优解,适用于搜索空间太大时BFS不适用的情况。
伪代码如下:
function IDDFS(node, goal):
for depth_limit in range(0, ∞): // 逐步增加深度限制
result = DLS(node, goal, depth_limit)
if result is not cutoff: // 如果找到了解决方案或者确定无解
return result
// 和DFS几乎相同,只是在此基础上添加了depth_limit
function DLS(node, goal, depth_limit):
if node is goal:
return solution
elif depth_limit == 0:
return cutoff
else:
for child in expand(node):
result = DLS(child, goal, depth_limit - 1)
if result is not cutoff:
return result
return cutoff