本文整理汇总了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;
//.........这里部分代码省略.........