我已经在互联网上搜索了有关IDS算法的信息,我一直在寻找一些示例,但是它们都是递归的,而且据我所知,迭代不是递归的。所以,您能给我一些IDS算法的例子吗?(实现会很好,而且不会递归)
谢谢!您将成为救生员!
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; }
但是存在一种自动过程,可以将任何递归程序转换为非递归程序。
对于国际象棋程序,这确实有一些好处。即使在以后包含先前由alpha-beta修剪的分支的情况下,它也可以改善移动顺序。通过使用换位表,可以使额外搜索的成本保持较低。
https://www.chessprogramming.org/Internal_Iterative_Deepening