6 Node::Node(const Action& action){
8 _preconditions = _action.preconditions();
15 Node::Node(const Node& node){
16 _action = node._action;
17 _preconditions = node._preconditions;
18 _executed = node._executed;
21 const Action& Node::action() const{
26 void Node::addChild(Node* node){
27 _children.push_back(node);
30 bool Node::executed() const{
34 const Literals& Node::effects() const{
38 void Node::execute(const Literals& effects){
39 cerr << "Executing: " << _action.name() << endl;
40 for (Literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
41 cerr << "Satisfied effect: " << *effect << endl;
42 _preconditions.erase(_preconditions.find(*effect));
44 cerr << "Number of preconditions left: " << _preconditions.size() << endl;
46 cerr << "Already executed" << endl;
47 if ((_preconditions.size() != 0) || _executed)
51 int value = _action.execute();
52 _effects = _action.effects(value);
54 cerr << "Got returnvalue: " << value << ", number of effects: " << _effects.size() << endl;
56 for(vector<Node*>::iterator child = _children.begin(); child != _children.end(); ++child){
57 (*child)->execute(_effects);
61 StartNode::StartNode(const Literals& init){
64 _action = Action("start",Preconditions(),"", initial);
67 EndNode::EndNode(const Literals& goal){
68 Preconditions goalState;
69 for(Literals::const_iterator g = goal.begin(); g != goal.end(); ++g)
71 _action = Action("finish",goalState,"",EffectsMap());
72 _preconditions = _action.preconditions();