]> ruin.nu Git - popboot.git/commitdiff
references instead of copies
authorMichael Andreen <harv@ruin.nu>
Sun, 8 May 2005 10:20:37 +0000 (10:20 +0000)
committerMichael Andreen <harv@ruin.nu>
Sun, 8 May 2005 10:20:37 +0000 (10:20 +0000)
action.cpp
action.h
main.cpp
node.cpp
node.h
planner.cpp
src.pro

index 427440b268c182270bd358d248870de02c78a8be..626eb37475bb5487756381dafcd823fd2188380f 100644 (file)
@@ -14,11 +14,11 @@ Action::Action(const Action& action){
        _effects = action._effects;
 }
 
-literals Action::effects() const{
+const literals& Action::effects() const{
        return _effects;
 }
 
-literals Action::preconditions() const{
+const literals& Action::preconditions() const{
        return _preconditions;
 }
 
@@ -26,3 +26,7 @@ int Action::execute() const{
        cout << "Executing: " << _executable << endl;
        return 0;
 }
+
+const string& Action::executable() const{
+       return _executable;
+}
index 35119c35c7d245615e10ab6c857d0e02702d089e..9b3c9276a105ab8366324c63839ffde92d34d70f 100644 (file)
--- a/action.h
+++ b/action.h
@@ -11,8 +11,9 @@ class Action {
                Action(std::string executable, literals preconditions, literals effects);
                Action(const Action& action);
                Action(){};
-               literals effects() const;
-               literals preconditions() const;
+               const literals& effects() const;
+               const literals& preconditions() const;
+               const std::string& executable() const;
                int execute() const;
 
        protected:
index 2affab554e32372a66adb1f312adaddd78ed99c6..4463ff26d4d0e49f2c249c17594ca7340a53337f 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -39,6 +39,7 @@ int main(int argc, char** argv){
                getline(file,effects);
                getline(file,precond);
                cout << exec << ":" << effects << ":" << precond << endl;
+               if (effects == "") continue;
                actions.push_back(Action(exec, stringToVector(precond), stringToVector(effects)));
        }
        Planner p(actions, stringToVector(argv[2]), stringToVector(argv[3]));
index dbb099cf47bc5c30fe14b03fe83aad6cd5d53ca9..1fb2b2e3ee9448eeb50a7f0657e23f1082f72895 100644 (file)
--- a/node.cpp
+++ b/node.cpp
@@ -7,7 +7,7 @@ Node::Node(Action action){
        _preconditions = _action.preconditions();
 }
 
-Action Node::action(){
+const Action& Node::action() const{
        return _action;
 }
 
@@ -17,8 +17,8 @@ void Node::addChild(Node* node){
 }
 
 
-void Node::execute(literals effects){
-       for (literals::iterator effect = effects.begin(); effect != effects.end(); ++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));
        }
        if (_preconditions.size() != 0)
diff --git a/node.h b/node.h
index 0d9cae6fa0229ce432dfb21497452adfa2075e16..7bcf3a8c371338375df7d42604ce5d0ddf98ce74 100644 (file)
--- a/node.h
+++ b/node.h
@@ -9,8 +9,8 @@ class Node {
        public:
                Node(Action action);
                void addChild(Node* node);
-               Action action();
-               void execute(literals effects);
+               const Action& action() const;
+               void execute(const literals& effects);
 
        protected:
                Action _action;
index a15028e29a3175e8fa316e2e6e6a37e2dc41194f..cf7801520883ac9e94cf62b958884fc8d95f369b 100644 (file)
@@ -11,8 +11,8 @@ Planner::Planner(std::vector<Action> actions, literals init, literals goal){
        Node* finish = new Node(Action("finish",goal,literals()));
 
        for(vector<Action>::iterator action = actions.begin(); action != actions.end(); ++action){
-               literals effects = action->effects();
-               for (literals::iterator effect = effects.begin(); effect != effects.end(); ++effect){
+               const literals& effects = action->effects();
+               for (literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
                        cerr << "Adding effect: " << *effect << endl;
                        _actions[*effect] = *action;
                }
@@ -22,13 +22,15 @@ Planner::Planner(std::vector<Action> actions, literals init, literals goal){
 
 
 void Planner::makePlan(Node* node){
-       literals preconds = node->action().preconditions();
+       cerr << "Fetching preconditions for action: " << node->action().executable() << ".. ";
+       const literals& preconds = node->action().preconditions();
+       cerr << "done" << endl;
 
        if (preconds.size() == 0){
                cerr << "Found no preconds" << endl;
                _start->addChild(node);
        }else{
-               for (literals::iterator precond = preconds.begin(); precond != preconds.end(); ++precond){
+               for (literals::const_iterator precond = preconds.begin(); precond != preconds.end(); ++precond){
                        cerr << "Looking for: " << *precond << endl;
                        hash_map<string,Node*>::iterator addedNode = _addedNodes.find(*precond);
                        if(addedNode != _addedNodes.end()){
@@ -51,9 +53,9 @@ void Planner::makePlan(Node* node){
 }
 
 void Planner::addNode(Node* node){
-       literals effects = node->action().effects();
+       const literals& effects = node->action().effects();
 
-       for (literals::iterator effect = effects.begin(); effect != effects.end(); ++effect){
+       for (literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
                cout << "Adding node for effect: " << *effect << endl;
                _addedNodes[*effect] = node;
        }
diff --git a/src.pro b/src.pro
index d0c6da8bae4d3c5bc04aaad1fad972f5a310c541..e8c02b915af74467803c2477db48e1b055509fa0 100644 (file)
--- a/src.pro
+++ b/src.pro
@@ -7,6 +7,7 @@ CONFIG -= qt
 CONFIG += debug
 INCLUDEPATH += .
 TARGET = planner
+#LIBS += -lpthread
 
 # Input
 HEADERS += action.h node.h planner.h