迭代深化搜索应该那么慢吗?
Is Iterative Deepening Search supposed to be that slow?
我的数据结构:
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应该很慢,但它应该那么慢吗?
我想我明白为什么这很慢。
在你的助手中,你像这样拜访邻居:
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;
}
}
}
但你永远不会使用过去的结果。您将某些内容标记为已访问,但从不检查它是否已被访问过。
相关文章:
- 高级选择排序 - 在一次迭代中搜索两个元素
- 我可以在没有堆栈的情况下在二叉搜索树中实现迭代器吗?
- C++以迭代方式搜索混合类型地图
- 基于函数而不是集合的二分搜索或迭代器?
- 迭代向量以获得搜索功能
- 使用迭代深度优先搜索算法的未加权图的最短路径
- 无法打印完整的二叉搜索树,因为我从最低节点向后迭代的逻辑有缺陷
- 编译时二叉搜索树错误的反向迭代器表示"no matching function call for operator=()"
- 使用二进制搜索树中的迭代器对象访问左侧节点
- 使用迭代器的二叉搜索
- 使用迭代器搜索映射中的值
- 按属性搜索对象的向量并返回迭代器
- 矢量迭代器在尝试对图形进行深度优先搜索时导致分割错误 11
- 从预序遍历迭代(不是递归)构造二叉搜索树
- 二进制搜索树中按顺序遍历的复杂性(使用迭代器)
- 迭代深化搜索应该那么慢吗?
- 广度优先搜索中的 C++ 迭代器和指针用法
- 使用迭代器位置的线性和二叉搜索
- C++:二叉搜索树 end() 迭代器
- c++初级二进制搜索迭代器