]> ruin.nu Git - popboot.git/blobdiff - planner.cpp
compiles again
[popboot.git] / planner.cpp
index c5016a18b4e43b8aa65147e204ed58c6f27e6663..3e8d5de60af18b35416301943000b20d1768094c 100644 (file)
@@ -1,6 +1,8 @@
 #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){
 
@@ -13,8 +15,38 @@ 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;
+       }
 }