#include "planner.h"
#include "node.h"
+#include <iostream>
using namespace std;
+using namespace __gnu_cxx;
Planner::Planner(std::vector<Action> 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<string,Node*>::iterator addedNode = _addedNodes.find(*precond);
+ if(addedNode != _addedNodes.end()){
+ addedNode->second->addChild(node);
+ }else {
+ hash_map<string, Action>::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;
+ }
}
protected:
void makePlan(Node* node);
+ void addNode(Node* node);
Node* _start;
__gnu_cxx::hash_map<std::string,Node*> _addedNodes;