]> ruin.nu Git - popboot.git/commitdiff
seems to work
authorMichael Andreen <harv@ruin.nu>
Fri, 6 May 2005 21:06:02 +0000 (21:06 +0000)
committerMichael Andreen <harv@ruin.nu>
Fri, 6 May 2005 21:06:02 +0000 (21:06 +0000)
actions [new file with mode: 0644]
main.cpp
planner.cpp
src.pro

diff --git a/actions b/actions
new file mode 100644 (file)
index 0000000..db94321
--- /dev/null
+++ b/actions
@@ -0,0 +1,30 @@
+1
+A
+
+2
+B
+
+3
+C
+A
+4
+D
+B
+5
+E
+A D
+6
+F
+C B
+7
+G
+D
+8
+H
+G
+9
+I
+D E
+10
+J
+I G
index 15bca93ef2bcfcdf984c006231bef685b267624b..740c8890771f2cf81bf61458b9ee2e970ce60d9d 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,7 +1,46 @@
 #include <iostream>
+#include <sstream>
+#include <fstream>
 using namespace std;
 
+#include "planner.h"
+#include "action.h"
+
+vector<string> stringToVector(string str){
+       vector<string> strings;
+
+       istringstream ist(str);
+       while (ist >> str){
+               strings.push_back(str);
+       }
+
+       return strings;
+}
+
 int main(int argc, char** argv){
+       
+       if (argc != 4){
+               cout << "Syntax: " << argv[0] << " <file> \"init state\" \"goal state\"" << endl;
+               return 1;
+       }
+
+       ifstream file(argv[1]);
+       if (!file){
+               cerr << "Cannot open input file: " << argv[1] << endl;
+               exit(2);
+       }
 
+       vector<Action> actions;
+       while (!file.eof()){
+               string exec;
+               string precond;
+               string effects;
+               getline(file,exec);
+               getline(file,effects);
+               getline(file,precond);
+               cout << exec << ":" << effects << ":" << precond << endl;
+               actions.push_back(Action(exec, stringToVector(precond), stringToVector(effects)));
+       }
+       Planner p(actions, stringToVector(argv[2]), stringToVector(argv[3]));
        return 0;
 }
index 3e8d5de60af18b35416301943000b20d1768094c..5e1719e11b48619a3a805801893e4bb0fa46408f 100644 (file)
@@ -6,12 +6,13 @@ using namespace __gnu_cxx;
 
 Planner::Planner(std::vector<Action> actions, literals init, literals goal){
 
-       _start = new Node(Action("",init, literals()));
-       Node* finish = new Node(Action("",literals(),goal));
+       _start = new Node(Action("",literals(), init));
+       Node* finish = new Node(Action("",goal,literals()));
 
        for(vector<Action>::iterator action = actions.begin(); action != actions.end(); ++action){
-               literals preconds = action->preconditions();
-               for (literals::iterator effect = preconds.begin(); effect != preconds.end(); ++effect){
+               literals effects = action->effects();
+               for (literals::iterator effect = effects.begin(); effect != effects.end(); ++effect){
+                       cerr << "Adding effect: " << *effect << endl;
                        _actions[*effect] = *action;
                }
        }
@@ -23,20 +24,25 @@ void Planner::makePlan(Node* node){
        literals preconds = node->action().preconditions();
 
        if (preconds.size() == 0){
+               cerr << "Found no preconds" << endl;
                _start->addChild(node);
        }else{
                for (literals::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()){
+                               cerr << "Using already added node" << endl;
                                addedNode->second->addChild(node);
                        }else {
                                hash_map<string, Action>::iterator action = _actions.find(*precond);
                                if (action != _actions.end()){
+                                       cerr << "Adding new node" << endl;
                                        Node* newnode = new Node(action->second);
                                        newnode->addChild(node);
+                                       addNode(newnode);
                                        makePlan(newnode);
                                }else{
-                                       cerr << "Action with effect: " << *precond << " not found!";
+                                       cerr << "Action with effect: " << *precond << " not found!" << endl;
                                }
                        }
                }
@@ -47,6 +53,7 @@ void Planner::addNode(Node* node){
        literals effects = node->action().effects();
 
        for (literals::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 7446f02dabfdeec8dd2f008f3d4e17c9f4544441..c5ed1458dc6ba583076693f9eeb64df831f07ab8 100644 (file)
--- a/src.pro
+++ b/src.pro
@@ -3,6 +3,8 @@
 ######################################################################
 
 TEMPLATE = app
+CONFIG -= qt
+CONFIG += debug
 INCLUDEPATH += .
 
 # Input