2024-10-07 迭代加深算法

今天学习了一种新的搜索方法——迭代加深算法(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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容