首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >迭代深化搜索应该有那么慢吗?

迭代深化搜索应该有那么慢吗?
EN

Stack Overflow用户
提问于 2013-11-17 17:41:22
回答 1查看 931关注 0票数 1

我的数据结构:

代码语言:javascript
运行
复制
class Cell
{
public:
    struct CellLink 
    {
        Cell *cell;
        int weight;
    };
public:
    int row;
    int column;
    vector<CellLink> neighbors;
    State state;
    int totalCost = 0;
};

主要职能:

代码语言:javascript
运行
复制
    void AI::IterativeDeepeningSearch(Cell* cell)
        {
            Cell* temp;
            int bound = 0;


        while (true)
        {
            naturalFailure = false;
            temp = IDShelper(cell, bound);

            if (IsExit(temp))
            {
                break;
            }
            bound++;
        }   
    }

助理员:

代码语言:javascript
运行
复制
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应该是慢的,但它应该是那么慢吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-17 17:49:58

我想我明白为什么这么慢了。

在你的帮手里,你是这样拜访邻居的:

代码语言:javascript
运行
复制
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;
        }
    }
}

但你绝不会用过去的结果。您将某事物标记为已访问,但不要检查它是否已被访问。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20033969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档