+
+ cout << "Unsatisfied preconditions so far: " << _goal.size() << ": ";
+ copy(_goal.begin(), _goal.end(), ostream_iterator<string>(cout, " "));
+ cout << endl;
+
+ //iterator for inserting effects at the end of _init
+ back_insert_iterator<Literals> ii(_init);
+
+ //Iterate throu the nodes, to see what's been done
+ for (vector<Node*>::iterator node = _addedNodes.begin(); node != _addedNodes.end(); ++node){
+ if ((*node)->executed()){
+ //Node was executed, adding the effects to _init.
+ executions++;
+ const Literals& effects = (*node)->effects();
+ copy(effects.begin(),effects.end(),ii);
+
+ vector<Action*>::iterator action = find(_actions.begin(), _actions.end(), (*node)->action());
+ if (action != _actions.end()){
+ //The action can be deleted, since it's already been executed.
+ delete *action;
+ _actions.erase(action);
+ }
+ }
+ //The node is not needed anymore
+ delete *node;
+ }
+ //Clearing the vectors and maps, since they are obsolete now.
+ _addedNodes.clear();
+ _addedEffects.clear();
+ _actionEffects.clear();
+
+ cout << "Effects achieved so far: " << _init.size() << ": ";
+ copy(_init.begin(), _init.end(), ostream_iterator<string>(cout, " "));
+ cout << endl;
+
+ if (executions <= 1){
+ cerr << "Non of the remaining actions could be executed, quiting." << endl;
+ return;
+ }
+ if (_actions.size() == 0){
+ //Nothing left to do, quitting.
+ return;
+ }
+ //REPLANNING
+ cout << "Replanning..." << endl;
+
+ //Adding the effecs for the remaining actions.
+ 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){
+ _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();
+
+}
+void* executeNode(void* arg){
+ ExecutionStuff* es = (ExecutionStuff*)arg;
+
+ es->node->execute();
+
+ sem_wait(es->list);
+ //Add this node to the queue with executed nodes
+ es->execQueue->push(es->node);
+ sem_post(es->list);
+
+ //Signal that the node is available.
+ sem_post(es->nodes);
+
+ pthread_exit((void*)0);