X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=planner.h;h=fc49df9d5659e42646fa307e034c4c59b6ec58b4;hb=44054bc3e498f77571a9448d0cea201fcca6bb0f;hp=7932eb9251814908502d07b197c198d5bed9f712;hpb=dc49c0c521090f0eb4b9692b25a129537c07e19e;p=popboot.git diff --git a/planner.h b/planner.h index 7932eb9..fc49df9 100644 --- a/planner.h +++ b/planner.h @@ -3,49 +3,77 @@ #include #include +#include +#include +#include #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 actions, Literals init, Literals goal); + /** + * Deletes all the remaining nodes and actions. + */ + ~Planner(); -namespace __gnu_cxx { + /** + * 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< std::basic_string > { - size_t operator()(const std::basic_string& s) const { - - const std::collate& c = std::use_facet< std::collate >(std::locale()); - - return c.hash(s.c_str(), s.c_str() + s.size()); -} + protected: - }; + /** + * 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); - template< typename CharT, typename Traits, typename Alloc > - struct hash< const std::basic_string > { //yes you need this version aswell! + /** + * Adds this node to the internal map and vector. + */ + void addNode(Node* node); -size_t operator()(const std::basic_string& s) const { - - const std::collate& c = std::use_facet< std::collate >(std::locale()); - - return c.hash(s.c_str(), s.c_str() + s.size()); - } + /** + * This method goes through the executed nodes and then calls + * executeChildren for these nodes. + */ + void executePlan(); + int executeChildren(Node* node); + void replan(); + int cleanupExecution(); - }; -}; + sem_t _nodes; + sem_t _list; + std::queue _executedNodes; -class Planner { - public: - Planner(std::vector actions, literals init, literals goal); - - protected: - - void makePlan(Node* node); - Node* _start; - __gnu_cxx::hash_map _addedNodes; - __gnu_cxx::hash_map _actions; + Node* _finish; + __gnu_cxx::hash_map _addedEffects; + __gnu_cxx::hash_map _actionEffects; + Literals _init; + Literals _goal; + std::vector _addedNodes; + std::vector _actions; }; #endif