]> ruin.nu Git - popboot.git/commitdiff
seems to be working now
authorMichael Andreen <harv@ruin.nu>
Thu, 19 May 2005 10:59:46 +0000 (10:59 +0000)
committerMichael Andreen <harv@ruin.nu>
Thu, 19 May 2005 10:59:46 +0000 (10:59 +0000)
action.cpp
input.txt
node.cpp
parser.y
planner.cpp
planner.h

index 87947ca054bb6684bfe9e23e006a16ff94df7c6c..6e4b60785917cf7627c7ef1969b9621481c40022 100644 (file)
@@ -1,4 +1,5 @@
 #include "action.h"
 #include "action.h"
+#include <cstdlib>
 #include <iostream>
 using namespace std;
 using namespace __gnu_cxx;
 #include <iostream>
 using namespace std;
 using namespace __gnu_cxx;
@@ -16,6 +17,7 @@ Action::Action(const Action& action){
        _name = action._name;
        _preconditions = action._preconditions;
        _effects = action._effects;
        _name = action._name;
        _preconditions = action._preconditions;
        _effects = action._effects;
+       _executable = action._executable;
 }
 
 const Literals& Action::effects(int value) const{
 }
 
 const Literals& Action::effects(int value) const{
@@ -30,8 +32,8 @@ const Preconditions& Action::preconditions() const{
 }
 
 int Action::execute() const{
 }
 
 int Action::execute() const{
-       cout << "Executing: " << _executable << endl;
-       return 0;
+       cout << "Executing: " << _name << endl;
+       return system(_executable.c_str());
 }
 
 const string& Action::name() const{
 }
 
 const string& Action::name() const{
index 9b54b4c27d8deb34bb33ba0cf1986db018255aee..fb943a87619deedc736165eb19e82eaf7e1f54b7 100644 (file)
--- a/input.txt
+++ b/input.txt
@@ -18,7 +18,7 @@ httpd.sh
 #dasdssad
 eth0
  # no preconditions 
 #dasdssad
 eth0
  # no preconditions 
-"ifconfig up eth0"
+true #"ifconfig up eth0"
 0: NET # kommentar
 
 
 0: NET # kommentar
 
 
index 1efdf6a03199e01f882e27e4d4d7de499f01a27b..899f38bf325592f2a9fa200f48edfb0acf5cb66c 100644 (file)
--- a/node.cpp
+++ b/node.cpp
@@ -1,5 +1,6 @@
 #include "node.h"
 #include <algorithm>
 #include "node.h"
 #include <algorithm>
+#include <iostream>
 using namespace std;
 
 Node::Node(const Action& action){
 using namespace std;
 
 Node::Node(const Action& action){
@@ -35,25 +36,25 @@ const Literals& Node::effects() const{
 }
 
 void Node::execute(const Literals& effects){
 }
 
 void Node::execute(const Literals& effects){
+       cerr << "Executing: " << _action.name() << endl;
        for (Literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
        for (Literals::const_iterator effect = effects.begin(); effect != effects.end(); ++effect){
+               cerr << "Satisfied effect: " << *effect << endl;
                _preconditions.erase(_preconditions.find(*effect));
        }
                _preconditions.erase(_preconditions.find(*effect));
        }
+       cerr << "Number of preconditions left: " << _preconditions.size() << endl;
+       if(_executed)
+               cerr << "Already executed" << endl;
        if ((_preconditions.size() != 0) || _executed)
                return;
 
        if ((_preconditions.size() != 0) || _executed)
                return;
 
-       if (_preconditions.size() != 0){
-               for (Preconditions::iterator precond = _preconditions.begin(); precond != _preconditions.end(); ++precond){
-                       if (precond->second)
-                               return;
-               }
-       }
-
        _executed = true;
        int value = _action.execute();
        _effects = _action.effects(value);
 
        _executed = true;
        int value = _action.execute();
        _effects = _action.effects(value);
 
+       cerr << "Got returnvalue: " << value << ", number of effects: " << _effects.size() << endl;
+
        for(vector<Node*>::iterator child = _children.begin(); child != _children.end(); ++child){
        for(vector<Node*>::iterator child = _children.begin(); child != _children.end(); ++child){
-               (*child)->execute(effects);
+               (*child)->execute(_effects);
        }
 }
 
        }
 }
 
index c3192e33861130542aa2b74065d1e9c0f9506fcf..1fec19db31f6f6704f3f1564e185c34ae6679542 100644 (file)
--- a/parser.y
+++ b/parser.y
@@ -64,23 +64,23 @@ action      : id preconds '\n' exec effects '\n' {
 
                                //---------------------------------------------
                                // Debug test print :   
 
                                //---------------------------------------------
                                // Debug test print :   
-                               cout << "id:  " << *$1 << endl;
+                               cerr << "id:  " << *$1 << endl;
 
                                // Precondition flags:
 
                                // Precondition flags:
-                               cout << "a: " << (*$2)["a"] << endl;
-                               cout << "b: " << (*$2)["b"] << endl;
-                               cout << "c: " << (*$2)["c"] << endl;
-                               cout << "d: " << (*$2)["d"] << endl;
-                               cout << "e: " << (*$2)["e"] << endl;
+                               cerr << "a: " << (*$2)["a"] << endl;
+                               cerr << "b: " << (*$2)["b"] << endl;
+                               cerr << "c: " << (*$2)["c"] << endl;
+                               cerr << "d: " << (*$2)["d"] << endl;
+                               cerr << "e: " << (*$2)["e"] << endl;
 
 
-                               cout << "exe: " << *$4 << endl;
+                               cerr << "exe: " << *$4 << endl;
 
                                // Print number of effects
 
                                // Print number of effects
-                               cout << "1: " << (*$5)[1].size() << endl;
-                               cout << "99: " << (*$5)[99].size() << endl;
-                               cout << "88: " << (*$5)[88].size() << endl;
+                               cerr << "0: " << (*$5)[0].size() << endl;
+                               cerr << "99: " << (*$5)[99].size() << endl;
+                               cerr << "88: " << (*$5)[88].size() << endl;
 
 
-                               cout << endl;
+                               cerr << endl;
                                //----------------------------------------------
                                            }
        ;
                                //----------------------------------------------
                                            }
        ;
@@ -226,13 +226,14 @@ int
 main (int argc, char** argv)
 {
 
 main (int argc, char** argv)
 {
 
-    if (argc!=4)
+    if (argc < 3)
     {
     {
-       cout << "Syntax: " << argv[0] << 
+       cerr << "Syntax: " << argv[0] << 
                " <file> <runlevel> \"init state\"" << endl;
        return 1;
     }
 
                " <file> <runlevel> \"init state\"" << endl;
        return 1;
     }
 
+       Literals init = argc >= 4 ? stringToVector(argv[3]) : Literals();
     ifstream file(argv[1]);
     if (!file)
     {
     ifstream file(argv[1]);
     if (!file)
     {
@@ -247,11 +248,11 @@ main (int argc, char** argv)
 
     yyparse();
 
 
     yyparse();
 
-    cout << (*runlevels)[2].size() << endl;
-    cout << (*runlevels)[3].size() << endl;
-    cout << (*runlevels)[4].size() << endl;
-    cout << (*runlevels)[5].size() << endl;
+    cerr << (*runlevels)[2].size() << endl;
+    cerr << (*runlevels)[3].size() << endl;
+    cerr << (*runlevels)[4].size() << endl;
+    cerr << (*runlevels)[5].size() << endl;
 
 
-    Planner p(*actions, stringToVector(argv[3]), (*runlevels)[atoi(argv[2])]);
+    Planner p(*actions, init, (*runlevels)[atoi(argv[2])]);
     p.execute();
 }
     p.execute();
 }
index d49fb911beb267aa1b7005a8bdd9a729b84f2e22..10f5e57f2970f1cd7a111d497de7d75c81dc848b 100644 (file)
@@ -19,14 +19,14 @@ Planner::Planner(std::vector<Action> actions, Literals init, Literals goal){
                        _actions[*effect] = *action;
                }
        }
                        _actions[*effect] = *action;
                }
        }
-       cout << "Number of actions: " << _actions.size() << endl;
+       cerr << "Number of actions: " << _actions.size() << endl;
        makePlan(_finish);
 }
 
 Planner::~Planner(){
        makePlan(_finish);
 }
 
 Planner::~Planner(){
-       for (hash_map<string,Node*>::iterator node = _addedNodes.begin(); node != _addedNodes.end(); ++node){
-               cerr << "Deleting node " << node->second->action().name() << endl;
-               delete node->second;
+       for (vector<Node*>::iterator node = _addedNodes.begin(); node != _addedNodes.end(); ++node){
+               cerr << "Deleting node " << (*node)->action().name() << endl;
+               delete *node;
        }
 }
 
        }
 }
 
@@ -45,8 +45,8 @@ void Planner::makePlan(Node* node){
        }else{
                for (Preconditions::const_iterator precond = preconds.begin(); precond != preconds.end(); ++precond){
                        cerr << "Looking for: '" << precond->first << "'" <<  endl;
        }else{
                for (Preconditions::const_iterator precond = preconds.begin(); precond != preconds.end(); ++precond){
                        cerr << "Looking for: '" << precond->first << "'" <<  endl;
-                       hash_map<string,Node*>::iterator addedNode = _addedNodes.find(precond->first);
-                       if(addedNode != _addedNodes.end()){
+                       hash_map<string,Node*>::iterator addedNode = _addedEffects.find(precond->first);
+                       if(addedNode != _addedEffects.end()){
                                cerr << "Using already added node" << endl;
                                addedNode->second->addChild(node);
                        }else {
                                cerr << "Using already added node" << endl;
                                addedNode->second->addChild(node);
                        }else {
@@ -73,10 +73,11 @@ void Planner::addNode(Node* node){
        cerr << "Adding node for action: " << node->action().name() << endl;
        const Literals& effects = node->action().effects(0);
        cerr << "Number of effects: " << effects.size() << endl;
        cerr << "Adding node for action: " << node->action().name() << endl;
        const Literals& effects = node->action().effects(0);
        cerr << "Number of effects: " << effects.size() << endl;
+       _addedNodes.push_back(node);
 
        for (Literals::const_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;
+               cerr << "Adding node for effect: " << *effect << endl;
+               _addedEffects[*effect] = node;
        }
 }
 
        }
 }
 
index 3faa6fb6918559f0182e45b51fc167c340920db1..79db5420a06cd52e751947013f8eb594af8d7791 100644 (file)
--- a/planner.h
+++ b/planner.h
@@ -21,9 +21,10 @@ class Planner {
                
                Node* _start;
                Node* _finish;
                
                Node* _start;
                Node* _finish;
-               __gnu_cxx::hash_map<std::string,Node*> _addedNodes;
+               __gnu_cxx::hash_map<std::string,Node*> _addedEffects;
                __gnu_cxx::hash_map<std::string,Action> _actions;
                Literals _init;
                Literals _goal;
                __gnu_cxx::hash_map<std::string,Action> _actions;
                Literals _init;
                Literals _goal;
+               std::vector<Node*> _addedNodes;
 };
 #endif
 };
 #endif