X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=node.cpp;h=24da8b1dd60c36d9575151630ca3e990905b9ef2;hb=a1941ebc8535c578f0989f847794917096274f8e;hp=fb1c314dcf682a059c3eff9d7235885d214bf2a7;hpb=dc4211bc1dc77ba3f1a71ec5737c61731614004b;p=popboot.git diff --git a/node.cpp b/node.cpp index fb1c314..24da8b1 100644 --- a/node.cpp +++ b/node.cpp @@ -3,9 +3,9 @@ #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(){ @@ -18,7 +18,7 @@ Node::Node(const Node& node){ _executed = node._executed; } -const Action& Node::action() const{ +const Action* Node::action() const{ return _action; } @@ -34,44 +34,51 @@ bool Node::executed() const{ const Literals& Node::effects() const{ return _effects; } -void Node::satisfyCondition(std::string effect){ + +bool Node::satisfyCondition(std::string effect){ _preconditions.erase(_preconditions.find(effect)); + return _preconditions.size() == 0 && !_executed; } -void Node::execute(const Literals& effects){ - cerr << "Executing: " << _action.name() << endl; +bool Node::satisfyConditions(const Literals& effects){ for (Literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){ - cerr << "Satisfied effect: " << *effect << endl; _preconditions.erase(_preconditions.find(*effect)); } - cerr << "Number of preconditions left: " << _preconditions.size() << endl; + return _preconditions.size() == 0 && !_executed; +} + +void Node::execute(){ if(_executed) - cerr << "Already executed" << endl; + cerr << "Already executed " << _action->name() << 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); - } } +const std::vector& Node::children() const{ + return _children; +} StartNode::StartNode(const Literals& init){ EffectsMap initial; initial[0] = init; - _action = Action("start",Preconditions(),"", initial); + _action = new Action("start",Preconditions(),"", initial); + _executed = true; + _effects = init; +} + +const Preconditions& Node::preconditions() const{ + return _preconditions; } EndNode::EndNode(const Literals& goal){ Preconditions goalState; for(Literals::const_iterator g = goal.begin(); g != goal.end(); ++g) - goalState[*g] = true; - _action = Action("finish",goalState,"",EffectsMap()); - _preconditions = _action.preconditions(); + goalState[*g] = false; + _action = new Action("finish",goalState,"",EffectsMap()); + _preconditions = _action->preconditions(); }