From 498b277372ebab0008b97399d387285b36d88826 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Fri, 6 May 2005 22:29:25 +0000 Subject: [PATCH] initial execution of the plan --- action.cpp | 4 +++- main.cpp | 2 ++ node.cpp | 9 +++++++++ node.h | 1 + planner.cpp | 9 +++++++-- planner.h | 2 ++ 6 files changed, 24 insertions(+), 3 deletions(-) diff --git a/action.cpp b/action.cpp index 3e9cddf..427440b 100644 --- a/action.cpp +++ b/action.cpp @@ -1,4 +1,6 @@ #include "action.h" +#include +using namespace std; Action::Action(std::string executable, literals preconditions, literals effects){ _executable = executable; @@ -21,6 +23,6 @@ literals Action::preconditions() const{ } int Action::execute() const{ - + cout << "Executing: " << _executable << endl; return 0; } diff --git a/main.cpp b/main.cpp index 740c889..2affab5 100644 --- a/main.cpp +++ b/main.cpp @@ -42,5 +42,7 @@ int main(int argc, char** argv){ actions.push_back(Action(exec, stringToVector(precond), stringToVector(effects))); } Planner p(actions, stringToVector(argv[2]), stringToVector(argv[3])); + + p.execute(); return 0; } diff --git a/node.cpp b/node.cpp index 4f81069..ed72a7f 100644 --- a/node.cpp +++ b/node.cpp @@ -1,4 +1,5 @@ #include "node.h" +using namespace std; Node::Node(Action action){ _action = action; @@ -13,3 +14,11 @@ void Node::addChild(Node* node){ _children.push_back(node); } + +void Node::execute(){ + _action.execute(); + + for(vector::iterator child = _children.begin(); child != _children.end(); ++child){ + (*child)->execute(); + } +} diff --git a/node.h b/node.h index 31568fc..3cd3a9e 100644 --- a/node.h +++ b/node.h @@ -10,6 +10,7 @@ class Node { Node(Action action); void addChild(Node* node); Action action(); + void execute(); protected: Action _action; diff --git a/planner.cpp b/planner.cpp index b675ce0..4630494 100644 --- a/planner.cpp +++ b/planner.cpp @@ -6,9 +6,9 @@ using namespace __gnu_cxx; Planner::Planner(std::vector actions, literals init, literals goal){ - _start = new Node(Action("",literals(), init)); + _start = new Node(Action("start",literals(), init)); addNode(_start); - Node* finish = new Node(Action("",goal,literals())); + Node* finish = new Node(Action("finish",goal,literals())); for(vector::iterator action = actions.begin(); action != actions.end(); ++action){ literals effects = action->effects(); @@ -58,3 +58,8 @@ void Planner::addNode(Node* node){ _addedNodes[*effect] = node; } } + + +void Planner::execute(){ + _start->execute(); +} diff --git a/planner.h b/planner.h index c74d536..ce7aef0 100644 --- a/planner.h +++ b/planner.h @@ -40,6 +40,8 @@ class Planner { public: Planner(std::vector actions, literals init, literals goal); + void execute(); + protected: void makePlan(Node* node); -- 2.39.2