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


C++ AbstractNode::setPredecessor方法代码示例

本文整理汇总了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);

}
开发者ID:CheHaoKang,项目名称:HumanoidRobotics,代码行数:55,代码来源:RRT.cpp


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