我的数据结构:
class Cell
{
public:
struct CellLink
{
Cell *cell;
int weight;
};
public:
int row;
int column;
vector<CellLink> neighbors;
State state;
int totalCost = 0;
};
主要职能:
void AI::IterativeDeepeningSearch(Cell* cell)
{
Cell* temp;
int bound = 0;
while (true)
{
naturalFailure = false;
temp = IDShelper(cell, bound);
if (IsExit(temp))
{
break;
}
bound++;
}
}
助理员:
Cell* AI::IDShelper(Cell* cell, int bound)
{
Cell* temp = cell;
SetEnvironment(cell, State::visited);
PrintEnvironment();
if (bound > 0)
{
for (int i = 0; i < cell->neighbors.size(); i++)
{
temp = IDShelper(cell->neighbors[i].cell, bound - 1);
if (IsExit(temp))
{
naturalFailure = true;
return temp;
}
}
}
else if (IsExit(cell))
{
return cell;
}
return temp;
}
我对迷宫进行了反复而深入的探索。问题是,在21x21迷宫上完成搜索几乎需要几个小时,而其他算法则需要几秒钟。
我知道IDS应该是慢的,但它应该是那么慢吗?
发布于 2013-11-17 17:49:58
我想我明白为什么这么慢了。
在你的帮手里,你是这样拜访邻居的:
if (bound > 0)
{
for (int i = 0; i < cell->neighbors.size(); i++)
{
temp = IDShelper(cell->neighbors[i].cell, bound - 1);
if (IsExit(temp))
{
naturalFailure = true;
return temp;
}
}
}
但你绝不会用过去的结果。您将某事物标记为已访问,但不要检查它是否已被访问。
https://stackoverflow.com/questions/20033969
复制相似问题