本文整理汇总了C++中Motion::setParent方法的典型用法代码示例。如果您正苦于以下问题:C++ Motion::setParent方法的具体用法?C++ Motion::setParent怎么用?C++ Motion::setParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Motion
的用法示例。
在下文中一共展示了Motion::setParent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cMin
bool ompl::geometric::FMT::expandTreeFromNode(Motion **z)
{
// Find all nodes that are near z, and also in set Unvisited
std::vector<Motion*> xNear;
const std::vector<Motion*> &zNeighborhood = neighborhoods_[*z];
const unsigned int zNeighborhoodSize = zNeighborhood.size();
xNear.reserve(zNeighborhoodSize);
for (unsigned int i = 0; i < zNeighborhoodSize; ++i)
{
Motion *x = zNeighborhood[i];
if (x->getSetType() == Motion::SET_UNVISITED)
{
saveNeighborhood(x);
if (nearestK_)
{
// Only include neighbors that are mutually k-nearest
// Relies on NN datastructure returning k-nearest in sorted order
const base::Cost connCost = opt_->motionCost((*z)->getState(), x->getState());
const base::Cost worstCost = opt_->motionCost(neighborhoods_[x].back()->getState(), x->getState());
if (opt_->isCostBetterThan(worstCost, connCost))
continue;
else
xNear.push_back(x);
}
else
xNear.push_back(x);
}
}
// For each node near z and in set Unvisited, attempt to connect it to set Open
std::vector<Motion*> yNear;
std::vector<Motion*> Open_new;
const unsigned int xNearSize = xNear.size();
for (unsigned int i = 0 ; i < xNearSize; ++i)
{
Motion *x = xNear[i];
// Find all nodes that are near x and in set Open
const std::vector<Motion*> &xNeighborhood = neighborhoods_[x];
const unsigned int xNeighborhoodSize = xNeighborhood.size();
yNear.reserve(xNeighborhoodSize);
for (unsigned int j = 0; j < xNeighborhoodSize; ++j)
{
if (xNeighborhood[j]->getSetType() == Motion::SET_OPEN)
yNear.push_back(xNeighborhood[j]);
}
// Find the lowest cost-to-come connection from Open to x
base::Cost cMin(std::numeric_limits<double>::infinity());
Motion *yMin = getBestParent(x, yNear, cMin);
yNear.clear();
// If an optimal connection from Open to x was found
if (yMin != nullptr)
{
bool collision_free = false;
if (cacheCC_)
{
if (!yMin->alreadyCC(x))
{
collision_free = si_->checkMotion(yMin->getState(), x->getState());
++collisionChecks_;
// Due to FMT* design, it is only necessary to save unsuccesful
// connection attemps because of collision
if (!collision_free)
yMin->addCC(x);
}
}
else
{
++collisionChecks_;
collision_free = si_->checkMotion(yMin->getState(), x->getState());
}
if (collision_free)
{
// Add edge from yMin to x
x->setParent(yMin);
x->setCost(cMin);
x->setHeuristicCost(opt_->motionCostHeuristic(x->getState(), goalState_));
yMin->getChildren().push_back(x);
// Add x to Open
Open_new.push_back(x);
// Remove x from Unvisited
x->setSetType(Motion::SET_CLOSED);
}
} // An optimal connection from Open to x was found
} // For each node near z and in set Unvisited, try to connect it to set Open
// Update Open
Open_.pop();
(*z)->setSetType(Motion::SET_CLOSED);
// Add the nodes in Open_new to Open
unsigned int openNewSize = Open_new.size();
//.........这里部分代码省略.........
示例2: PlannerStatus
//.........这里部分代码省略.........
yNear.reserve(nbh.size());
for (std::size_t j = 0; j < nbh.size(); ++j)
{
if (nbh[j]->getSetType() == Motion::SET_CLOSED)
{
if (nearestK_)
{
// Only include neighbors that are mutually k-nearest
// Relies on NN datastructure returning k-nearest in sorted order
const base::Cost connCost = opt_->motionCost(nbh[j]->getState(), m->getState());
const base::Cost worstCost = opt_->motionCost(neighborhoods_[nbh[j]].back()->getState(), nbh[j]->getState());
if (opt_->isCostBetterThan(worstCost, connCost))
continue;
else
yNear.push_back(nbh[j]);
}
else
yNear.push_back(nbh[j]);
}
}
// Sample again if the new sample does not connect to the tree.
if (yNear.empty())
continue;
// cache for distance computations
//
// Our cost caches only increase in size, so they're only
// resized if they can't fit the current neighborhood
if (costs.size() < yNear.size())
{
costs.resize(yNear.size());
incCosts.resize(yNear.size());
sortedCostIndices.resize(yNear.size());
}
// Finding the nearest neighbor to connect to
// By default, neighborhood states are sorted by cost, and collision checking
// is performed in increasing order of cost
//
// calculate all costs and distances
for (std::size_t i = 0 ; i < yNear.size(); ++i)
{
incCosts[i] = opt_->motionCost(yNear[i]->getState(), m->getState());
costs[i] = opt_->combineCosts(yNear[i]->getCost(), incCosts[i]);
}
// sort the nodes
//
// we're using index-value pairs so that we can get at
// original, unsorted indices
for (std::size_t i = 0; i < yNear.size(); ++i)
sortedCostIndices[i] = i;
std::sort(sortedCostIndices.begin(), sortedCostIndices.begin() + yNear.size(),
compareFn);
// collision check until a valid motion is found
for (std::vector<std::size_t>::const_iterator i = sortedCostIndices.begin();
i != sortedCostIndices.begin() + yNear.size();
++i)
{
if (si_->checkMotion(yNear[*i]->getState(), m->getState()))
{
m->setParent(yNear[*i]);
yNear[*i]->getChildren().push_back(m);
const base::Cost incCost = opt_->motionCost(yNear[*i]->getState(), m->getState());
m->setCost(opt_->combineCosts(yNear[*i]->getCost(), incCost));
m->setHeuristicCost(opt_->motionCostHeuristic(m->getState(), goalState_));
m->setSetType(Motion::SET_OPEN);
nn_->add(m);
saveNeighborhood(m);
updateNeighborhood(m,nbh);
Open_.insert(m);
z = m;
break;
}
}
} // while (!ptc && Open_.empty())
} // else if (extendedFMT_ && !successfulExpansion)
} // While not at goal
if (plannerSuccess)
{
// Return the path to z, since by definition of planner success, z is in the goal region
lastGoalMotion_ = z;
traceSolutionPathThroughTree(lastGoalMotion_);
OMPL_DEBUG("Final path cost: %f", lastGoalMotion_->getCost().value());
return base::PlannerStatus(true, false);
} // if plannerSuccess
else
{
// Planner terminated without accomplishing goal
return base::PlannerStatus(false, false);
}
}