本文整理汇总了C++中AStarNode::getVisitor方法的典型用法代码示例。如果您正苦于以下问题:C++ AStarNode::getVisitor方法的具体用法?C++ AStarNode::getVisitor怎么用?C++ AStarNode::getVisitor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AStarNode
的用法示例。
在下文中一共展示了AStarNode::getVisitor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
std::vector<AStarNode*>* AStarAlgorithm::startAlgorithm2(AStarNode* startNode, AStarNode* endNode, std::vector<AStarNode*> &path)
{
path.clear();
std::vector<AStarNode*> pathList;
pathList.push_back(startNode);
std::vector<AStarNode*> wastedList;
AStarNode* tmp;
bool wasIn = false;
bool shorterPathFound = false;
int distanceTraveled = 0;
bool secondOut = false;
AStarNode* returnNode;
returnNode = startNode;
while (pathList.size() != 0 && pathList.back()->getName() != endNode->getName() && !pathList.empty())
{
tmp = pathList.back();
wastedList.push_back(pathList.back());
pathList.pop_back();
if (secondOut)
{
returnNode = tmp;
secondOut = false;
}
if (tmp->getName() == startNode->getName())
{
secondOut = true;
}
//adding new paths
for (int i = 0; i < tmp->getPaths()->size(); i++)
{
if (tmp->getPaths()->at(i)->getEndNode()->getName() != tmp->getVisitor()->getName() && tmp->getPaths()->at(i)->getEndNode()->getName() != startNode->getName())
{
AStarNode* copyNode = new AStarNode();
for (int j = 0; j < pathList.size(); j++)
{
if (tmp->getPaths()->at(i)->getEndNode()->getName() == pathList.at(j)->getName())
{
wasIn = true;
copyNode->setPathList(*pathList.at(j)->getPaths());
copyNode->setName(pathList.at(j)->getName());
copyNode->setDistanceToGoal(pathList.at(j)->getDistanceToGoal());
//copyNode->setPosition(wastedList.at(j)->getPosition());
break;
}
}
for (int m = 0; m < wastedList.size(); m++)
{
if (tmp->getPaths()->at(i)->getEndNode()->getName() == wastedList.at(m)->getName())
{
wasIn = true;
copyNode->setPathList(*wastedList.at(m)->getPaths());
copyNode->setName(wastedList.at(m)->getName());
copyNode->setDistanceToGoal(wastedList.at(m)->getDistanceToGoal());
copyNode->setPosition(wastedList.at(m)->getPosition());
break;
}
}
if (!wasIn){
tmp->getPaths()->at(i)->getEndNode()->setDistanceTravelled(tmp->getPaths()->at(i)->getTimeToTravel() + tmp->getDistanceTravelled());
tmp->getPaths()->at(i)->getEndNode()->setTemporary(tmp->getPaths()->at(i)->getEndNode()->getDistanceToGoal() + tmp->getPaths()->at(i)->getEndNode()->getDistanceTravelled());
for (int n = 0; n < pathList.size(); n++)
{
if (pathList.at(n)->getName() == tmp->getPaths()->at(i)->getEndNode()->getName() && pathList.at(n)->getDistanceTravelled() < tmp->getPaths()->at(i)->getEndNode()->getDistanceTravelled())
{
shorterPathFound = true;
}
else if (pathList.at(n)->getName() == tmp->getPaths()->at(i)->getEndNode()->getName() && pathList.at(n)->getDistanceTravelled() >= tmp->getPaths()->at(i)->getEndNode()->getDistanceTravelled()){
pathList.erase(pathList.begin() + n);
}
}
if (!shorterPathFound)
{
pathList.push_back(tmp->getPaths()->at(i)->getEndNode());
tmp->getPaths()->at(i)->getEndNode()->setVisitor(tmp);
}
else{
shorterPathFound = false;
}
}
else{
copyNode->setDistanceTravelled(-(copyNode->getDistanceTravelled()));
copyNode->setDistanceTravelled(tmp->getPaths()->at(i)->getTimeToTravel() + tmp->getDistanceTravelled());
copyNode->setTemporary(tmp->getPaths()->at(i)->getEndNode()->getDistanceToGoal() + copyNode->getDistanceTravelled());
for (int n = 0; n < pathList.size(); n++)
{
if (pathList.at(n)->getName() == copyNode->getName() && pathList.at(n)->getDistanceTravelled() < copyNode->getDistanceTravelled())
{
shorterPathFound = true;
}
else if (pathList.at(n)->getName() == tmp->getPaths()->at(i)->getEndNode()->getName() && pathList.at(n)->getDistanceTravelled() >= tmp->getPaths()->at(i)->getEndNode()->getDistanceTravelled()){
pathList.at(n)->setDistanceTravelled(copyNode->getDistanceTravelled());
//.........这里部分代码省略.........
示例2: startAlgorithm
AStarNode* AStarAlgorithm::startAlgorithm(AStarNode* startNode, AStarNode* endNode)
{
std::cout << "A*-ALGORITHM WILL BE STARTED" << std::endl;
std::vector<AStarNode*> pathList;
std::cout << startNode->getName() << " GOES INTO THE PATHLIST" << std::endl;
pathList.push_back(startNode);
std::vector<AStarNode*> wastedList;
AStarNode* tmp;
bool wasIn = false;
bool shorterPathFound = false;
int distanceTraveled = 0;
bool secondOut = false;
AStarNode* returnNode;
returnNode = startNode;
while (pathList.back()->getName() != endNode->getName() && !pathList.empty())
{
std::cout << "FRONT ELEMENT OF THE LIST GOES OUT: " << pathList.back()->getName()<< "(" << pathList.back()->getTemporary() << ")" << std::endl;
tmp = pathList.back();
wastedList.push_back(pathList.back());
pathList.pop_back();
std::cout << "THE OTHER ELEMENTS IN THE LIST ARE: ";
for (int bb = 0; bb < pathList.size(); bb++)
{
std::cout << pathList.at(bb)->getName() << "(" << pathList.at(bb)->getTemporary() << ")";
}
std::cout << std::endl;
if (secondOut)
{
returnNode = tmp;
secondOut = false;
}
if (tmp->getName() == startNode->getName())
{
secondOut = true;
}
for (int i = 0; i < tmp->getPaths()->size(); i++)
{
//Test, if the endnode of the path that we want to add, was visited beforehand. If this was the case, it would be an returnpath which we do not want here.
if (tmp->getPaths()->at(i)->getEndNode()->getName() != tmp->getVisitor()->getName() && tmp->getPaths()->at(i)->getEndNode()->getName() != startNode->getName())
{
/*Now we have to check if there is a node with the same name in our pathlist.
*If there is, we want to copy it, because we want to be able to safe more than one path to a node*/
AStarNode* copyNode = new AStarNode();
for (int j = 0; j < pathList.size(); j++)
{
if (tmp->getPaths()->at(i)->getEndNode()->getName() == pathList.at(j)->getName())
{
wasIn = true;
copyNode->setPathList(*pathList.at(j)->getPaths());
copyNode->setName(pathList.at(j)->getName());
break;
}
}
for (int m = 0; m < wastedList.size(); m++)
{
if (tmp->getPaths()->at(i)->getEndNode()->getName() == wastedList.at(m)->getName())
{
wasIn = true;
copyNode->setPathList(*wastedList.at(m)->getPaths());
copyNode->setName(wastedList.at(m)->getName());
break;
}
}
//If the node was not found in the pathlist, it will added normally
if (!wasIn){
tmp->getPaths()->at(i)->getEndNode()->setDistanceTravelled(tmp->getPaths()->at(i)->getTimeToTravel() + tmp->getDistanceTravelled());
tmp->getPaths()->at(i)->getEndNode()->setTemporary(tmp->getPaths()->at(i)->getEndNode()->getDistanceToGoal() + tmp->getPaths()->at(i)->getEndNode()->getDistanceTravelled());
//We just add the path, if there is no path in the list which is shorter
for (int n = 0; n < pathList.size(); n++)
{
//There is a path with a shorter travelled disitance
if (pathList.at(n)->getName() == tmp->getPaths()->at(i)->getEndNode()->getName() && pathList.at(n)->getDistanceTravelled() < tmp->getPaths()->at(i)->getEndNode()->getDistanceTravelled())
{
//setting the boolean
shorterPathFound = true;
}
//the existing path to the node which has a longer distanceTravelled will be deleted from the list
else if (pathList.at(n)->getName() == tmp->getPaths()->at(i)->getEndNode()->getName() && pathList.at(n)->getDistanceTravelled() >= tmp->getPaths()->at(i)->getEndNode()->getDistanceTravelled()){
pathList.erase(pathList.begin() + n);
}
}
if (!shorterPathFound)
{
pathList.push_back(tmp->getPaths()->at(i)->getEndNode());
tmp->getPaths()->at(i)->getEndNode()->setVisitor(tmp);
}
//.........这里部分代码省略.........