X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=node.cpp;h=83b3334a7dab9b6095e1d1907a35ac808d9d6bc9;hb=921850c029bdaad568b0e40969b0805df785b72a;hp=acc5bd7090144cf31ffd4b536e2a5a68f1a72f18;hpb=3dadaa088d9fff7ca05cbb297f3d7e88179faccb;p=popboot.git diff --git a/node.cpp b/node.cpp index acc5bd7..83b3334 100644 --- a/node.cpp +++ b/node.cpp @@ -1,10 +1,11 @@ #include "node.h" #include +#include using namespace std; -Node::Node(const Action& action){ +Node::Node(const Action* action){ _action = action; - _preconditions = _action.preconditions(); + _preconditions = _action->preconditions(); _executed = false; } Node::Node(){ @@ -17,7 +18,7 @@ Node::Node(const Node& node){ _executed = node._executed; } -const Action& Node::action() const{ +const Action* Node::action() const{ return _action; } @@ -30,38 +31,47 @@ bool Node::executed() const{ return _executed; } -const literals& Node::effects() const{ +const Literals& Node::effects() const{ return _effects; } +void Node::satisfyCondition(std::string effect){ + _preconditions.erase(_preconditions.find(effect)); +} -void Node::execute(const literals& effects){ - for (literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){ - _preconditions.erase(find(_preconditions.begin(),_preconditions.end(), *effect)); +void Node::execute(const Literals& effects){ + cerr << "Executing: " << _action->name() << endl; + for (Literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){ + cerr << "Satisfied effect: " << *effect << endl; + _preconditions.erase(_preconditions.find(*effect)); } - if (_preconditions.size() != 0 || _executed) + cerr << "Number of preconditions left: " << _preconditions.size() << endl; + if(_executed) + cerr << "Already executed" << endl; + if ((_preconditions.size() != 0) || _executed) return; _executed = true; - int value = _action.execute(); - _effects = _action.effects(value); + int value = _action->execute(); + _effects = _action->effects(value); + + cerr << "Got returnvalue: " << value << ", number of effects: " << _effects.size() << endl; for(vector::iterator child = _children.begin(); child != _children.end(); ++child){ - (*child)->execute(effects); + (*child)->execute(_effects); } } -StartNode::StartNode(const literals& init){ - effectsMap initial; +StartNode::StartNode(const Literals& init){ + EffectsMap initial; initial[0] = init; - Node(Action("start",preconditionsVector(), initial)); + _action = new Action("start",Preconditions(),"", initial); } -EndNode::EndNode(const literals& goal){ - preconditionsVector goalState; - pair goalPair; - goalPair.first = ""; - goalPair.second = goal; - goalState.push_back(goalPair); - Node(Action("finish",goalState,effectsMap())); +EndNode::EndNode(const Literals& goal){ + Preconditions goalState; + for(Literals::const_iterator g = goal.begin(); g != goal.end(); ++g) + goalState[*g] = false; + _action = new Action("finish",goalState,"",EffectsMap()); + _preconditions = _action->preconditions(); }