]> ruin.nu Git - popboot.git/blobdiff - planner.cpp
moved addNode
[popboot.git] / planner.cpp
index cf7801520883ac9e94cf62b958884fc8d95f369b..1210d0479309df2ed3af1a2fe0b8f783fa5d1a33 100644 (file)
@@ -7,7 +7,6 @@ using namespace __gnu_cxx;
 Planner::Planner(std::vector<Action> actions, literals init, literals goal){
 
        _start = new Node(Action("start",literals(), init));
-       addNode(_start);
        Node* finish = new Node(Action("finish",goal,literals()));
 
        for(vector<Action>::iterator action = actions.begin(); action != actions.end(); ++action){
@@ -20,12 +19,21 @@ Planner::Planner(std::vector<Action> actions, literals init, literals goal){
        makePlan(finish);
 }
 
+Planner::~Planner(){
+       for (hash_map<string,Node*>::iterator node = _addedNodes.begin(); node != _addedNodes.end(); ++node){
+               cerr << "Deleting node " << node->second->action().executable() << endl;
+               delete node->second;
+       }
+}
+
 
 void Planner::makePlan(Node* node){
        cerr << "Fetching preconditions for action: " << node->action().executable() << ".. ";
        const literals& preconds = node->action().preconditions();
        cerr << "done" << endl;
 
+       addNode(node);
+
        if (preconds.size() == 0){
                cerr << "Found no preconds" << endl;
                _start->addChild(node);
@@ -42,7 +50,6 @@ void Planner::makePlan(Node* node){
                                        cerr << "Adding new node" << endl;
                                        Node* newnode = new Node(action->second);
                                        newnode->addChild(node);
-                                       addNode(newnode);
                                        makePlan(newnode);
                                }else{
                                        cerr << "Action with effect: " << *precond << " not found!" << endl;