当前位置: 首页>>代码示例>>C++>>正文


C++ AStar::shortestPath方法代码示例

本文整理汇总了C++中AStar::shortestPath方法的典型用法代码示例。如果您正苦于以下问题:C++ AStar::shortestPath方法的具体用法?C++ AStar::shortestPath怎么用?C++ AStar::shortestPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AStar的用法示例。


在下文中一共展示了AStar::shortestPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: gettimeofday

vector<Edge*> PRM::query(int numberClosestNeighbors)
{
    path.erase(path.begin(),path.end());
    struct timeval begin,end;
    gettimeofday(&begin,NULL);
    qDebug() << "Query começando";
    mGraph->V.push_back(mGoalNode);
    mGraph->V.push_back(mInitNode);


    vector<Node*> Nq = mInitNode->sortedClosest(mGraph,numberClosestNeighbors);
    Edge *edge = NULL;
    do
    {
        if(delta(mInitNode,Nq.at(0)) != NULL)
        {
            edge = new Edge(mInitNode,Nq.at(0));
            mInitNode->neighbors.push_back(edge);
            mGraph->E.push_back(edge);
        }
        else
        {
            Nq.erase(Nq.begin());
        }
    }while(Nq.size() && (edge == NULL));


    edge = NULL;
    Nq = mGoalNode->sortedClosest(mGraph,numberClosestNeighbors);
    do
    {
        if(delta(mGoalNode,Nq.at(0)) != NULL)
        {
            edge = new Edge(Nq.at(0),mGoalNode);
            Nq.at(0)->neighbors.push_back(edge);
            mGraph->E.push_back(edge);
        }
        else
        {
            Nq.erase(Nq.begin());
        }
    }while(Nq.size() && (edge == NULL));

    AStar search;
    bool again = false;
    do
    {
        again = false;
        path = search.shortestPath(mInitNode,mGoalNode); //Run shortest path
        for(int i=0;i<path.size();i++)
        {
            Edge *edge = path.at(i);
            if(!checkNodeAreaIsEmpty(edge->mNodeR))
            {
                qDebug() << "Removendo nodo ";
                Node *deletar = edge->mNodeR;
                for(int j=0;j<deletar->neighbors.size();j++)
                {
                    Edge *e = deletar->neighbors.at(j);
                    for(int x=0;x<e->mNodeR->neighbors.size();x++)
                    {
                        Edge *e2 = e->mNodeR->neighbors.at(x);
                        if(e2->mNodeR == deletar)
                        {
                            e->mNodeR->neighbors.erase(remove(e->mNodeR->neighbors.begin(),e->mNodeR->neighbors.end(),e2),e->mNodeR->neighbors.end());
                            mGraph->E.erase(std::remove(mGraph->E.begin(),mGraph->E.end(),e2),mGraph->E.end());
                            delete e2;
                        }
                    }
                    mGraph->E.erase(std::remove(mGraph->E.begin(),mGraph->E.end(),e),mGraph->E.end());
                    delete e;
                }
                mGraph->V.erase(std::remove(mGraph->V.begin(),mGraph->V.end(),deletar),mGraph->V.end());
                delete deletar;
                again = true;
                break;
            }
            if(delta(edge->mNodeL,edge->mNodeR) == NULL)
            {
                qDebug() << "Removendo arco ";
                Edge *deletar = edge;

                for(int j=0;j<deletar->mNodeR->neighbors.size();j++)
                {
                    Edge *e = deletar->mNodeR->neighbors.at(j);
                    if(e->mNodeR == deletar->mNodeL)
                    {
                        deletar->mNodeR->neighbors.erase(remove(deletar->mNodeR->neighbors.begin(),deletar->mNodeR->neighbors.end(),e),deletar->mNodeR->neighbors.end());
                        mGraph->E.erase(remove(mGraph->E.begin(),mGraph->E.end(),e),mGraph->E.end());
                        delete e;
                    }
                }
                for(int j=0;j<deletar->mNodeL->neighbors.size();j++)
                {
                    Edge *e = deletar->mNodeL->neighbors.at(j);
                    if(e->mNodeR == deletar->mNodeR)
                    {
                        deletar->mNodeL->neighbors.erase(remove(deletar->mNodeL->neighbors.begin(),deletar->mNodeL->neighbors.end(),e),deletar->mNodeL->neighbors.end());
                        mGraph->E.erase(remove(mGraph->E.begin(),mGraph->E.end(),e),mGraph->E.end());
                        delete e;
//.........这里部分代码省略.........
开发者ID:schvarcz,项目名称:PRM,代码行数:101,代码来源:prm.cpp


注:本文中的AStar::shortestPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。