本文整理汇总了C++中AbstractNode::setPredecessor方法的典型用法代码示例。如果您正苦于以下问题:C++ AbstractNode::setPredecessor方法的具体用法?C++ AbstractNode::setPredecessor怎么用?C++ AbstractNode::setPredecessor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AbstractNode
的用法示例。
在下文中一共展示了AbstractNode::setPredecessor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addNearestNeighbor
/**
* \brief Determines the neighbor that is closest to the random node, sets its predecessor
* to the current node, and adds it to the list of explored nodes.
* \param[in] currentNode The current node.
* \param[in] neighbors The list of neighbors of the current node.
* \param[in] randomNode The randomly drawn node.
* \param[in,out] list The list of already expanded nodes.
*/
void RRT::addNearestNeighbor(GridNode* const currentNode, const std::vector<AbstractNode*>& neighbors,
GridNode* const randomNode, std::vector<AbstractNode*>& list) const {
/* TODO: Determine the neighbor that is closest to the random node, set its predecessor
* to the current node, and add it to the list of explored nodes.
*/
/* Available methods and fields:
* - node->setPredecessor(AbstractNode* node): store the predecessor node for a node (required
* later for extracting the path)
* - getClosestNodeInList(node, list): Defined above
*/
int min_cost = INT_MAX;
AbstractNode* minNode = NULL;
std::vector<AbstractNode *>::const_iterator it;
it = neighbors.begin();
for (;it != neighbors.end(); it++ )
{
double cost = distance(*it,randomNode);
if (cost < min_cost)
{
minNode = *it;
min_cost = cost;
}
}
minNode->setPredecessor(currentNode) ;
list.push_back(minNode);
// int min_cost = INT_MAX;
// AbstractNode* minNode = NULL;
// std::vector<AbstractNode*>::iterator it;
// for(it=neighbors.begin() ; it < neighbors.end(); it++)
// {
// double cost = distance(*it,randomNode);
// if (cost < min_cost)
// {
// minNode = *it;
// min_cost = cost;
// }
// }
// minNode->predecessor = currentNode;
// list.push_back(minNode);
}