【问题标题】:Iterative deepening search : Is it recursive?迭代深化搜索:它是递归的吗?
【发布时间】:2013-11-07 07:34:11
【问题描述】:

我在互联网上搜索了有关 IDS 算法的信息,并且一直在寻找一些示例,但它们都是递归的,据我所知,迭代不是递归的。 那你能给我一些IDS算法的例子吗?(实现会很好,没有递归)

提前致谢!您将成为救生员!

【问题讨论】:

  • 递归是什么意思。您可以在程序化算法中自动转换任何递归算法。

标签: search iterative-deepening


【解决方案1】:

迭代部分不是递归的:在顶部它或多或少:

int limit = 0;
Solution sol;
do {
    limit++;
    sol = search(problem,limit);
} while(sol == null);
//do something with the solution.

这就是说,在大多数情况下,寻找解决方案确实是递归实现的:

Solution search(Problem problem, int limit) {
    return search(problem,0,limit);
}
Solution search (Problem problem, int price, int limit) {
    if(problem.solved) {
        return problem.getSolution();
    }
    for(int value = 0; value < valuerange; value++) {
        problem.assignVariable(value);
        int newprice = price + problem.price();
        if(price < limit) {
            Solution solution = search(problem,newprice,limit);
            if(s != null) {
                return solution;
            }
        }
        problem.backtrackVariable();
    }
    return null;
}

但是有一个自动过程可以将任何递归程序变成非递归程序。

【讨论】:

    【解决方案2】:

    如果您从算法方面考虑(不仅仅是实现),这意味着在搜索树的所有节点上应用迭代,而不是仅仅在根节点上。

    对于国际象棋程序,这确实有一些好处。它改进了移动顺序,即使在后来包含先前被 alpha-beta 修剪的分支的情况下也是如此。通过使用转置表,额外搜索的成本保持在较低水平。

    https://www.chessprogramming.org/Internal_Iterative_Deepening

    【讨论】:

      猜你喜欢
      • 2013-11-30
      • 2017-10-17
      • 1970-01-01
      • 1970-01-01
      • 2011-11-15
      • 1970-01-01
      • 1970-01-01
      • 2018-09-20
      • 1970-01-01
      相关资源
      最近更新 更多