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{
37 void Node::satisfyCondition(std::string effect){
38 _preconditions.erase(_preconditions.find(effect));
41 void Node::execute(const Literals& effects){
42 cerr << "Executing: " << _action.name() << endl;
43 for (Literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
44 cerr << "Satisfied effect: " << *effect << endl;
45 _preconditions.erase(_preconditions.find(*effect));
47 cerr << "Number of preconditions left: " << _preconditions.size() << endl;
49 cerr << "Already executed" << endl;
50 if ((_preconditions.size() != 0) || _executed)
54 int value = _action.execute();
55 _effects = _action.effects(value);
57 cerr << "Got returnvalue: " << value << ", number of effects: " << _effects.size() << endl;
59 for(vector<Node*>::iterator child = _children.begin(); child != _children.end(); ++child){
60 (*child)->execute(_effects);
64 StartNode::StartNode(const Literals& init){
67 _action = Action("start",Preconditions(),"", initial);
70 EndNode::EndNode(const Literals& goal){
71 Preconditions goalState;
72 for(Literals::const_iterator g = goal.begin(); g != goal.end(); ++g)
74 _action = Action("finish",goalState,"",EffectsMap());
75 _preconditions = _action.preconditions();