]> ruin.nu Git - popboot.git/blobdiff - planner.h
documentation
[popboot.git] / planner.h
index c74d536b5e5d03ac7f439921bd06a6793c2b715b..fc49df9d5659e42646fa307e034c4c59b6ec58b4 100644 (file)
--- a/planner.h
+++ b/planner.h
@@ -3,50 +3,77 @@
 
 #include <ext/hash_map>
 #include <vector>
+#include <queue>
+#include <pthread.h>
+#include <semaphore.h>
 #include "action.h"
 
 class Node;
 
+class Planner {
+       public:
+               /**
+                * Creates a plan given the input actions, initial state and goal.
+                *
+                * @param actions A list of actions which will be used to reach the goal.
+                * @param init The initial state which the plan will start from.
+                * @param goal The goal state which the plan will try to reach.
+                */
+               Planner(std::vector<Action> actions, Literals init, Literals goal);
 
+               /**
+                * Deletes all the remaining nodes and actions.
+                */
+               ~Planner();
 
-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());
-
-}
+               /**
+                * Executes the plan.
+                * Creates new threads for execution of each action.
+                *
+                * If any action fail in some way, this method will try to replan and
+                * recursively call itself.
+                */
+               void execute();
 
-    };
 
-    template< typename CharT, typename Traits, typename Alloc >
-    struct hash< const std::basic_string<CharT, Traits, Alloc> > { //yes you need this version aswell!
+       protected:
 
-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());
-        }
+               /**
+                * This method does the actual planning. Given the input node it will
+                * try to find all preconditions and create links from parent nodes
+                * to this node and, if the precondition did not have a node associated
+                * with it, create a new and recursively call this method for the newly
+                * created node.
+                *
+                * @param node The node which this method will find parent nodes for.
+                */
+               void makePlan(Node* node);
 
-    };
-};
+               /**
+                * Adds this node to the internal map and vector.
+                */
+               void addNode(Node* node);
 
-class Planner {
-       public:
-               Planner(std::vector<Action> actions, literals init, literals goal);
+               /**
+                * This method goes through the executed nodes and then calls 
+                * executeChildren for these nodes.
+                */
+               void executePlan();
+               int executeChildren(Node* node);
+               void replan();
+               int cleanupExecution();
 
-       protected:
+               sem_t _nodes;
+               sem_t _list;
+               std::queue<Node*> _executedNodes;
 
-               void makePlan(Node* node);
-               void addNode(Node* node);
-               
                Node* _start;
-               __gnu_cxx::hash_map<std::string,Node*> _addedNodes;
-               __gnu_cxx::hash_map<std::string,Action> _actions;
+               Node* _finish;
+               __gnu_cxx::hash_map<std::string,Node*> _addedEffects;
+               __gnu_cxx::hash_map<std::string,Action*> _actionEffects;
+               Literals _init;
+               Literals _goal;
+               std::vector<Node*> _addedNodes;
+               std::vector<Action*> _actions;
 };
 #endif