]> ruin.nu Git - popboot.git/blob - planner.h
documentation
[popboot.git] / planner.h
1 #ifndef __PLANNER_H__
2 #define __PLANNER_H__
3
4 #include <ext/hash_map>
5 #include <vector>
6 #include <queue>
7 #include <pthread.h>
8 #include <semaphore.h>
9 #include "action.h"
10
11 class Node;
12
13 class Planner {
14         public:
15                 /**
16                  * Creates a plan given the input actions, initial state and goal.
17                  *
18                  * @param actions A list of actions which will be used to reach the goal.
19                  * @param init The initial state which the plan will start from.
20                  * @param goal The goal state which the plan will try to reach.
21                  */
22                 Planner(std::vector<Action> actions, Literals init, Literals goal);
23
24                 /**
25                  * Deletes all the remaining nodes and actions.
26                  */
27                 ~Planner();
28
29                 /**
30                  * Executes the plan.
31                  * Creates new threads for execution of each action.
32                  *
33                  * If any action fail in some way, this method will try to replan and
34                  * recursively call itself.
35                  */
36                 void execute();
37
38
39         protected:
40
41                 /**
42                  * This method does the actual planning. Given the input node it will
43                  * try to find all preconditions and create links from parent nodes
44                  * to this node and, if the precondition did not have a node associated
45                  * with it, create a new and recursively call this method for the newly
46                  * created node.
47                  *
48                  * @param node The node which this method will find parent nodes for.
49                  */
50                 void makePlan(Node* node);
51
52                 /**
53                  * Adds this node to the internal map and vector.
54                  */
55                 void addNode(Node* node);
56
57                 /**
58                  * This method goes through the executed nodes and then calls 
59                  * executeChildren for these nodes.
60                  */
61                 void executePlan();
62                 int executeChildren(Node* node);
63                 void replan();
64                 int cleanupExecution();
65
66                 sem_t _nodes;
67                 sem_t _list;
68                 std::queue<Node*> _executedNodes;
69
70                 Node* _start;
71                 Node* _finish;
72                 __gnu_cxx::hash_map<std::string,Node*> _addedEffects;
73                 __gnu_cxx::hash_map<std::string,Action*> _actionEffects;
74                 Literals _init;
75                 Literals _goal;
76                 std::vector<Node*> _addedNodes;
77                 std::vector<Action*> _actions;
78 };
79 #endif