C++ 在IDA*算法中查找下一个阈值时遇到问题

C++ 在IDA*算法中查找下一个阈值时遇到问题,c++,algorithm,search,C++,Algorithm,Search,我正在做3x3和4x4的滑动拼图,我做了我的A*算法,工作如预期。但现在我必须为IDA编码,因为4x4是一件大事。在递归的每次迭代中,我都很难找到下一个阈值 摘自Korf的: “在每次迭代中 用于下一次迭代的阈值是所使用的所有值的最小成本 已超过当前阈值。“ 这是我不能编码的部分,我理解它,但就是不能 这是我的cpp文件: #include <iostream> #include "IDAstar.h" using namespace std; void IDAstar::DFS(

我正在做3x3和4x4的滑动拼图,我做了我的A*算法,工作如预期。但现在我必须为IDA编码,因为4x4是一件大事。在递归的每次迭代中,我都很难找到下一个阈值

摘自Korf的: “在每次迭代中 用于下一次迭代的阈值是所使用的所有值的最小成本 已超过当前阈值。“

这是我不能编码的部分,我理解它,但就是不能

这是我的cpp文件:

#include <iostream>
#include "IDAstar.h"
using namespace std;

void IDAstar::DFS(state &start, state &goal, int d, int &f, bool &foundGoal, int Puzzle){
    if(start == goal){
        cout << "Cost: " << start.cost << endl;
        foundGoal = true;
        return;
    }
    vector<Action> PossibleActions;
    environment.GetActions(start, PossibleActions, Puzzle);
    for(int i=0;i<PossibleActions.size();i++){
            /*The missing code should
                go around here?*/
        state simulator;                               
        simulator = start;
        environment.ApplyAction(simulator, PossibleActions[i], Puzzle);
        simulator.cost = simulator.cost + 1;
        simulador.heuristic = environment.HCost(simulator, Puzzle);
        if(simulator.cost+simulator.heuristic <= d)
                    /* or inside this if? */
            DFS(start, environment.goal, d, f, foundGoal, Puzzle);
    }
}

void IDAstar::GetPath(state &start, int Puzzle){
    int d = environment.HCost(start, Puzzle);     
    int f = d; 
    environment.SetGoal(Puzzle);
    bool foundGoal = false;    
    while(true){    
        DFS(start, environment.goal, d, f, foundGoal, Puzzle);
        d = f;
        if(foundGoal)
            return;
    }
}
#包括
#包括“IDAstar.h”
使用名称空间std;
无效IDAstar::DFS(状态和开始、状态和目标、整数d、整数f、布尔和foundGoal、整数拼图){
如果(开始=目标){

看一下上面的解释,似乎
d
是当前搜索递归的截止点,一旦递归完成,如果没有找到解决方案,我们将截止点提高到上次
DFS
期间计算的最小成本,然后再次搜索。这基本上就是您在
GetPath
中所做的>。在
DFS
中,如果当前调用的成本已经高于
d
,则停止该调用并返回该值。否则,将迭代递归并保留最小返回值。