]> ruin.nu Git - popboot.git/blobdiff - planner.cpp
not working
[popboot.git] / planner.cpp
index 1210d0479309df2ed3af1a2fe0b8f783fa5d1a33..324c2dd73a3c0754d3a4899edbbf739473465d80 100644 (file)
@@ -1,19 +1,22 @@
 #include "planner.h"
 #include "node.h"
 #include <iostream>
+#include <vector>
 using namespace std;
 using namespace __gnu_cxx;
 
 Planner::Planner(std::vector<Action> actions, literals init, literals goal){
-
-       _start = new Node(Action("start",literals(), init));
-       Node* finish = new Node(Action("finish",goal,literals()));
+       _init = init;
+       _goal = goal;
+       _start = new StartNode(_init);
+       Node* finish = new EndNode(_goal);
 
        for(vector<Action>::iterator action = actions.begin(); action != actions.end(); ++action){
-               const literals& effects = action->effects();
+               Action* act = new Action(*action);
+               const literals& effects = act->effects(0);
                for (literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
                        cerr << "Adding effect: " << *effect << endl;
-                       _actions[*effect] = *action;
+                       _actions[*effect] = act;
                }
        }
        makePlan(finish);
@@ -21,18 +24,19 @@ Planner::Planner(std::vector<Action> actions, literals init, literals goal){
 
 Planner::~Planner(){
        for (hash_map<string,Node*>::iterator node = _addedNodes.begin(); node != _addedNodes.end(); ++node){
-               cerr << "Deleting node " << node->second->action().executable() << endl;
+               cerr << "Deleting node " << node->second->action().name() << endl;
                delete node->second;
        }
 }
 
 
 void Planner::makePlan(Node* node){
-       cerr << "Fetching preconditions for action: " << node->action().executable() << ".. ";
+       addNode(node);
+
+       cerr << "Fetching preconditions for action: " << node->action().name() << ".. ";
        const literals& preconds = node->action().preconditions();
        cerr << "done" << endl;
 
-       addNode(node);
 
        if (preconds.size() == 0){
                cerr << "Found no preconds" << endl;
@@ -45,10 +49,10 @@ void Planner::makePlan(Node* node){
                                cerr << "Using already added node" << endl;
                                addedNode->second->addChild(node);
                        }else {
-                               hash_map<string, Action>::iterator action = _actions.find(*precond);
+                               hash_map<string, Action*>::iterator action = _actions.find(*precond);
                                if (action != _actions.end()){
                                        cerr << "Adding new node" << endl;
-                                       Node* newnode = new Node(action->second);
+                                       Node* newnode = new Node(*action->second);
                                        newnode->addChild(node);
                                        makePlan(newnode);
                                }else{
@@ -60,7 +64,7 @@ void Planner::makePlan(Node* node){
 }
 
 void Planner::addNode(Node* node){
-       const literals& effects = node->action().effects();
+       const literals& effects = node->action().effects(0);
 
        for (literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
                cout << "Adding node for effect: " << *effect << endl;
@@ -71,4 +75,5 @@ void Planner::addNode(Node* node){
 
 void Planner::execute(){
        _start->execute(literals());
+       for (hash_map<string,Node*>::iterator node = _addedNodes.begin(); node != _addedNodes.end(); ++node){
 }