]> ruin.nu Git - popboot.git/commitdiff
replanning seems to work
authorMichael Andreen <harv@ruin.nu>
Thu, 19 May 2005 18:37:29 +0000 (18:37 +0000)
committerMichael Andreen <harv@ruin.nu>
Thu, 19 May 2005 18:37:29 +0000 (18:37 +0000)
planner.cpp

index d29691f95c1d4d620318b2a665f5cebea110d952..a4b5e5d5cfe97aab976e0ac9b1b6ffe106639634 100644 (file)
@@ -91,28 +91,54 @@ void Planner::execute(){
        _start->execute(Literals());
        cerr << "Number of nodes: " << _addedNodes.size() << endl;
        back_insert_iterator<Literals> ii(_init);
-       copy(_init.begin(), _init.end(), ostream_iterator<string>(cout, " "));
-       cout << endl;
        _init.clear();
+       int executions = 0;
        for (vector<Node*>::iterator node = _addedNodes.begin(); node != _addedNodes.end(); ++node){
                cerr << "Deleting node " << (*node)->action()->name() << endl;
                if ((*node)->executed()){
+                       executions++;
                        const Literals& effects = (*node)->effects();
                        copy(effects.begin(),effects.end(),ii);
                        cerr << "Finding action" << endl;
                        vector<Action*>::iterator action = find(_actions.begin(), _actions.end(), (*node)->action());
                        if (action != _actions.end()){
                                cerr << "Removing executed action: " << (*action)->name() << endl;
+                               delete *action;
                                _actions.erase(action);
-                               //BUG: Sometimes finds the wrong action.
-                               //delete *action;
                        }
                }
                delete *node;
        }
        _addedNodes.clear();
+       _addedEffects.clear();
        _actionEffects.clear();
-       copy(_init.begin(), _init.end(), ostream_iterator<string>(cout, " "));
-       cerr << "Number of nodes left: " << _addedNodes.size() << endl;
+       copy(_init.begin(), _init.end(), ostream_iterator<string>(cerr, " "));
+       cerr << endl;
+       cerr << "Number of actions left: " << _actions.size() << endl;
        //TODO: Fill _actionEffects with the remaining effects, create start end end nodes and create a new plan.
+       if (executions <= 1){
+               cerr << "Non of the remaining actions could be executed, quiting." << endl;
+               return;
+       }
+       if (_actions.size() == 0){
+               cerr << "No remaining actions, quiting." << endl;
+               return;
+       }
+       for (vector<Action*>::iterator action = _actions.begin(); action != _actions.end(); ++action){
+               const Literals& effects = (*action)->effects(0);
+               for (Literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
+                       cerr << "Adding effect: '" << *effect << "', action: " << (*action)->name() << endl;
+                       _actionEffects[*effect] = *action;
+               }
+       }
+       _start = new StartNode(_init);
+       _finish = new EndNode(_goal);
+       addNode(_start);
+       makePlan(_finish);
+       if (_addedNodes.size() <= 2){
+               cerr << "No actions to execute, quiting." << endl;
+               return;
+       }
+       execute();
+       
 }