X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=planner.cpp;h=1210d0479309df2ed3af1a2fe0b8f783fa5d1a33;hb=895d43297511597e9d8734c0fd5ba534f551de5f;hp=cf7801520883ac9e94cf62b958884fc8d95f369b;hpb=e26fd7b3195576b25ffe51253a391b53f412a650;p=popboot.git diff --git a/planner.cpp b/planner.cpp index cf78015..1210d04 100644 --- a/planner.cpp +++ b/planner.cpp @@ -7,7 +7,6 @@ using namespace __gnu_cxx; Planner::Planner(std::vector actions, literals init, literals goal){ _start = new Node(Action("start",literals(), init)); - addNode(_start); Node* finish = new Node(Action("finish",goal,literals())); for(vector::iterator action = actions.begin(); action != actions.end(); ++action){ @@ -20,12 +19,21 @@ Planner::Planner(std::vector actions, literals init, literals goal){ makePlan(finish); } +Planner::~Planner(){ + for (hash_map::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;