迭代深化搜索:是否递归?

问题描述 投票:1回答:2

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

谢谢!您将成为救生员!

search iterative-deepening
2个回答
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; }

但是存在一种自动过程,可以将任何递归程序转换为非递归程序。

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

对于国际象棋程序,这确实有一些好处。即使在以后包含先前由alpha-beta修剪的分支的情况下,它也可以改善移动顺序。通过使用换位表,可以使额外搜索的成本保持较低。

https://www.chessprogramming.org/Internal_Iterative_Deepening

© www.soinside.com 2019 - 2024. All rights reserved.