]> ruin.nu Git - popboot.git/commitdiff
it compiles
authorMichael Andreen <harv@ruin.nu>
Fri, 6 May 2005 18:56:52 +0000 (18:56 +0000)
committerMichael Andreen <harv@ruin.nu>
Fri, 6 May 2005 18:56:52 +0000 (18:56 +0000)
action.cpp
action.h
node.cpp
node.h
planner.cpp
planner.h
src.pro [new file with mode: 0644]

index 695c74fb71d4b7b6d8e764e186a730ad4354317f..3e9cddf692163b41a515655c33e37ef29bffd270 100644 (file)
@@ -1,21 +1,26 @@
 #include "action.h"
 
 Action::Action(std::string executable, literals preconditions, literals effects){
 #include "action.h"
 
 Action::Action(std::string executable, literals preconditions, literals effects){
-       _execututable = executable;
+       _executable = executable;
        _preconditions = preconditions;
        _effects = effects;
 }
 
        _preconditions = preconditions;
        _effects = effects;
 }
 
+Action::Action(const Action& action){
+       _executable = action._executable;
+       _preconditions = action._preconditions;
+       _effects = action._effects;
+}
 
 
-const literals Action::effects(){
+literals Action::effects() const{
        return _effects;
 }
 
        return _effects;
 }
 
-const literals Action::preconditions(){
+literals Action::preconditions() const{
        return _preconditions;
 }
 
        return _preconditions;
 }
 
-int Action::execute(){
+int Action::execute() const{
 
        return 0;
 }
 
        return 0;
 }
index 60206a391c76119853c3beaf9fbde219f2f284c8..35119c35c7d245615e10ab6c857d0e02702d089e 100644 (file)
--- a/action.h
+++ b/action.h
@@ -1,13 +1,18 @@
 #ifndef __ACTION_H__
 #define __ACTION_H__
 
 #ifndef __ACTION_H__
 #define __ACTION_H__
 
-typedef literals std::vector<string>;
+#include <vector>
+#include <string>
+
+typedef std::vector<std::string> literals;
 
 class Action {
        public:
                Action(std::string executable, literals preconditions, literals effects);
 
 class Action {
        public:
                Action(std::string executable, literals preconditions, literals effects);
-               const literals effects() const;
-               const literals preconditions() const;
+               Action(const Action& action);
+               Action(){};
+               literals effects() const;
+               literals preconditions() const;
                int execute() const;
 
        protected:
                int execute() const;
 
        protected:
index a9cb4539431d6d1f959339f9e042d867ba68fb74..11fed08507b52bfe5953a1558aed3c3e2be6818a 100644 (file)
--- a/node.cpp
+++ b/node.cpp
@@ -1,6 +1,5 @@
 #include "node.h"
 
 #include "node.h"
 
-Node::Node(Action action, std::vector<Node&> children){
+Node::Node(Action action){
        _action = action;
        _action = action;
-       _children = children;
 }
 }
diff --git a/node.h b/node.h
index db9fb09663fbcff9fa99d797269a84ff1286e630..55e34e6d4675fc644e7a8070abfe929efc0a0844 100644 (file)
--- a/node.h
+++ b/node.h
@@ -6,13 +6,13 @@
 
 class Node {
 
 
 class Node {
 
-       Node(Action action, std::vector<Node&> children);
-
-       addChild(Node& node);
+       public:
+               Node(Action action);
+               void addChild(Node* node);
 
        protected:
                Action _action;
 
        protected:
                Action _action;
-               std::vector<Node&> _children;
+               std::vector<Node*> _children;
 };
 
 #endif
 };
 
 #endif
index 159cb528d68f15e5e0d5667facef30455042867d..c5016a18b4e43b8aa65147e204ed58c6f27e6663 100644 (file)
@@ -1,3 +1,20 @@
 #include "planner.h"
 #include "planner.h"
+#include "node.h"
+using namespace std;
 
 
+Planner::Planner(std::vector<Action> actions, literals init, literals goal){
 
 
+       _start = new Node(Action("",init, literals()));
+       Node* finish = new Node(Action("",literals(),goal));
+
+       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){
+                       _actions[*effect] = *action;
+               }
+       }
+}
+
+
+void Planner::makePlan(Node* node){
+}
index 1b4938b36e7eb04560342e9403baeec3499d896f..7932eb9251814908502d07b197c198d5bed9f712 100644 (file)
--- a/planner.h
+++ b/planner.h
@@ -1,14 +1,51 @@
 #ifndef __PLANNER_H__
 #define __PLANNER_H__
 
 #ifndef __PLANNER_H__
 #define __PLANNER_H__
 
-#include <hash_map>
-#include "node.h"
+#include <ext/hash_map>
+#include <vector>
+#include "action.h"
+
+class Node;
+
+
+
+namespace __gnu_cxx {
+
+    template< typename CharT, typename Traits, typename Alloc >
+    struct hash< std::basic_string<CharT, Traits, Alloc> > {
+        size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
+            
+           const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(std::locale());
+           
+           return c.hash(s.c_str(), s.c_str() + s.size());
+
+}
+
+    };
+
+    template< typename CharT, typename Traits, typename Alloc >
+    struct hash< const std::basic_string<CharT, Traits, Alloc> > { //yes you need this version aswell!
+
+size_t operator()(const std::basic_string<CharT, Traits, Alloc>& s) const {
+       
+          const std::collate<CharT>& c = std::use_facet< std::collate<CharT> >(std::locale());
+      
+          return c.hash(s.c_str(), s.c_str() + s.size());
+        }
+
+    };
+};
 
 class Planner {
        public:
 
 class Planner {
        public:
+               Planner(std::vector<Action> actions, literals init, literals goal);
 
        protected:
 
        protected:
-               Node start;
-               std::hash_map<string,Node*> addedNodes;
+
+               void makePlan(Node* node);
+               
+               Node* _start;
+               __gnu_cxx::hash_map<std::string,Node*> _addedNodes;
+               __gnu_cxx::hash_map<std::string,Action> _actions;
 };
 #endif
 };
 #endif
diff --git a/src.pro b/src.pro
new file mode 100644 (file)
index 0000000..7446f02
--- /dev/null
+++ b/src.pro
@@ -0,0 +1,10 @@
+######################################################################
+# Automatically generated by qmake (1.07a) Fri May 6 20:04:49 2005
+######################################################################
+
+TEMPLATE = app
+INCLUDEPATH += .
+
+# Input
+HEADERS += action.h node.h planner.h
+SOURCES += action.cpp main.cpp node.cpp planner.cpp