X-Git-Url: https://ruin.nu/git/?p=popboot.git;a=blobdiff_plain;f=planner.cpp;h=3e8d5de60af18b35416301943000b20d1768094c;hp=c5016a18b4e43b8aa65147e204ed58c6f27e6663;hb=b177aeec472c3941b39b874a83883ff87a41919c;hpb=dc49c0c521090f0eb4b9692b25a129537c07e19e diff --git a/planner.cpp b/planner.cpp index c5016a1..3e8d5de 100644 --- a/planner.cpp +++ b/planner.cpp @@ -1,6 +1,8 @@ #include "planner.h" #include "node.h" +#include using namespace std; +using namespace __gnu_cxx; Planner::Planner(std::vector actions, literals init, literals goal){ @@ -13,8 +15,38 @@ Planner::Planner(std::vector actions, literals init, literals goal){ _actions[*effect] = *action; } } + makePlan(finish); } void Planner::makePlan(Node* node){ + literals preconds = node->action().preconditions(); + + if (preconds.size() == 0){ + _start->addChild(node); + }else{ + for (literals::iterator precond = preconds.begin(); precond != preconds.end(); ++precond){ + hash_map::iterator addedNode = _addedNodes.find(*precond); + if(addedNode != _addedNodes.end()){ + addedNode->second->addChild(node); + }else { + hash_map::iterator action = _actions.find(*precond); + if (action != _actions.end()){ + Node* newnode = new Node(action->second); + newnode->addChild(node); + makePlan(newnode); + }else{ + cerr << "Action with effect: " << *precond << " not found!"; + } + } + } + } +} + +void Planner::addNode(Node* node){ + literals effects = node->action().effects(); + + for (literals::iterator effect = effects.begin(); effect != effects.end(); ++effect){ + _addedNodes[*effect] = node; + } }