本文整理汇总了C++中Problem::getActions方法的典型用法代码示例。如果您正苦于以下问题:C++ Problem::getActions方法的具体用法?C++ Problem::getActions怎么用?C++ Problem::getActions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Problem
的用法示例。
在下文中一共展示了Problem::getActions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doSearch
/*
* initialize the priority queue with the initial state
* explored <-- empty
* loop do
* if empty(queue) return failure
* node <-- queue.pop()
* if node is goal, then return solution(node)
* add node to explored
* for each action in Action(problem, node) do
* child node <-- childnode(problem, node, action)
* if child is not in queue or expolored, add node to queue
* otherwise, if the child.state is in queue and with a higher pathcost,
* then replace that node with the child
*
*/
bool UCSearch::doSearch(Problem &problem, std::vector<MapNode *> &path)
{
MapNode *init = problem.getInitState();
insertQueue(init);
while(!_queue->isEmpty())
{
MapNode *node = _queue->pop();
if(problem.isGoal(node))
{
node->getPathFromRoot(path);
return true;
}
insertExplored(node);
std::vector<MovAction_t> & action = problem.getActions();
std::vector<MovAction_t>::iterator it;
for(it=action.begin(); it<action.end(); it++)
{
if(*it == MOV_ACT_NOOP) {
continue;
}
MapNode *child = NULL;
int res = 0;
res = problem.movAction(node, *it, &child);
if(res == OP_OK)
{
if(!isInQueue(child) && !isInExplored(child))
{
insertQueue(child);
}
else
{
if(isInQueue(child))
{
//get old one
MapNode *old = findQueueByKey(child->getKey());
if(child->getPathCost() < old->getPathCost())
{
//update;
#ifdef HW1_DEBUG
std::cout <<"before update, child cost: " << child->getPathCost();
std::cout <<", old cost: " << old->getPathCost();
#endif
updateQueue(old, child);
#ifdef HW1_DEBUG
std::cout <<"after, old cost: " << old->getPathCost();
#endif
}
}
}
}
}
}
return false;
}