Bratmobile
planner.h
Go to the documentation of this file.
1 #ifndef PLANNER_H
2 #define PLANNER_H
3 
4 #include "task.h"
5 #include "graphTools.h"
12 //typedef std::pair<vertexDescriptor, std::vector<vertexDescriptor>> Frontier;
13 
14 struct Frontier{
15  vertexDescriptor frontier=TransitionSystem::null_vertex();
16  std::vector<vertexDescriptor> connecting;
17 
18  Frontier()=default;
19 
20  Frontier(vertexDescriptor _f, const std::vector<vertexDescriptor>&_c):frontier(_f), connecting(_c){}
21 };
22 
27 struct ComparePhi{
28 
29  ComparePhi(){}
30 
31  bool operator()(const std::pair<State*, Frontier>& p1, const std::pair<State*, Frontier>& p2) const{
32  return (*p1.first).phi<(*p2.first).phi;
33  }
34 };
35 
36 
42  private:
43  vertexDescriptor m_currentVertex=0, m_goalVertex=TransitionSystem::null_vertex();
44  Task m_currentTask;
45  Task m_overarchingGoal;
46  bool m_been; //has a plan been made to fulfill this overarching goal before?
47  std::vector <vertexDescriptor> m_plan;
48  protected:
49  friend class Configurator;
50 
51  void been(bool b){m_been=b;}
52 
53  void goalVertex(vertexDescriptor gv){m_goalVertex=gv;}
54 
55 
56  public:
57  ExecutionInfo(){}
58 
59  ExecutionInfo( vertexDescriptor _cv, vertexDescriptor _goal, Task & _ct, Task & _gt, bool _been, std::vector<vertexDescriptor> _plan){
60  m_currentVertex=_cv;
61  m_goalVertex=_goal;
62  m_currentTask=_ct;
63  m_overarchingGoal=_gt;
64  m_been=_been;
65  m_plan=_plan;
66  }
67  void overarchingGoal(const Task & og){m_overarchingGoal=og;}
68 
69 
70  vertexDescriptor currentVertex()const{return m_currentVertex;}
71 
72  vertexDescriptor goalVertex()const{return m_goalVertex;}
73 
74  Task& currentTask(){return m_currentTask;}
75 
76  Task& overarchingGoal() {return m_overarchingGoal;}
77 
78  bool been()const{return m_been;}
79 
80  std::vector<vertexDescriptor> plan()const{return m_plan;}
81 
82 };
83 
88 class Planner{
89  protected:
90 
91  public:
92 
93  Planner()=default;
94 
104  virtual std::vector<vertexDescriptor> plan(TransitionSystem& g, vertexDescriptor src, ExecutionInfo & info, bool *finished)=0;
105 
114  static float evaluationFunction(EndedResult er, const vertexDescriptor &v, std::vector<vertexDescriptor>& p);
115 
127  static EndedResult estimateCost(const State &state, b2Transform start, Direction d, Task & _goal); //returns whether the controlGoal has ended and fills node with cost and error
128 
129 
130 };
131 
150  protected:
155  const Direction frontier_direction=DEFAULT;
156 
165  void path2add2(std::vector<std::vector<vertexDescriptor>>::reverse_iterator & path, const std::vector <vertexDescriptor> & add, std::vector<std::vector<vertexDescriptor>> &paths, TransitionSystem &g);
166 
177  std::vector <vertexDescriptor> best_path(const std::vector<std::vector<vertexDescriptor>>& paths, vertexDescriptor goal, vertexDescriptor cv, bool change, const TransitionSystem& g);
178 
179 
189  std::vector <Frontier> frontierVertices(vertexDescriptor v, TransitionSystem& g, ExecutionInfo & info); //returns the closest vertices to the start vertex which are reached by executing a task of the specified direction
190 
191 
200  void addToPriorityQueue(const Frontier &f, std::vector<Frontier>& queue, TransitionSystem &g, vertexDescriptor goal=TransitionSystem::null_vertex());
201 
202 
203 public:
204 
205  std::vector<vertexDescriptor> plan(TransitionSystem& g, vertexDescriptor src, ExecutionInfo & info, bool * finished=NULL)override;
206 
207 };
208 
213 class NoPlanner:public Planner{
214 
215  std::vector<vertexDescriptor> plan(TransitionSystem& g, vertexDescriptor src, ExecutionInfo & info, bool * finished=NULL)override{}
216 
217 
218 };
219 
220 #endif
Definition: configurator.h:17
Information about what the configurator is doing (current Task, current vertex), what it wants to do ...
Definition: planner.h:41
Performs iterative deepening search over one unit of modular expansion (see below),...
Definition: planner.h:149
const Direction frontier_direction
The depth-first search portion of iterative deepening will stop when it reaches a DEFAULT task.
Definition: planner.h:155
std::vector< vertexDescriptor > best_path(const std::vector< std::vector< vertexDescriptor >> &paths, vertexDescriptor goal, vertexDescriptor cv, bool change, const TransitionSystem &g)
Searches all paths for best path according to the lowest final cost phi.
Definition: planner.cpp:62
std::vector< Frontier > frontierVertices(vertexDescriptor v, TransitionSystem &g, ExecutionInfo &info)
Performs iterative deepening search to find the frontier.
Definition: planner.cpp:89
void addToPriorityQueue(const Frontier &f, std::vector< Frontier > &queue, TransitionSystem &g, vertexDescriptor goal=TransitionSystem::null_vertex())
Adds frontier to priority queue.
Definition: planner.cpp:161
void path2add2(std::vector< std::vector< vertexDescriptor >>::reverse_iterator &path, const std::vector< vertexDescriptor > &add, std::vector< std::vector< vertexDescriptor >> &paths, TransitionSystem &g)
Finds the best path to add a frontier to (frontier found separately)
Definition: planner.cpp:22
std::vector< vertexDescriptor > plan(TransitionSystem &g, vertexDescriptor src, ExecutionInfo &info, bool *finished=NULL) override
Implements custom algorithm to search transition system for a plan.
Definition: planner.cpp:171
Does not extract a plan.
Definition: planner.h:213
Searches the transition system and extracts a plan.
Definition: planner.h:88
static EndedResult estimateCost(const State &state, b2Transform start, Direction d, Task &_goal)
Estimates cost (phi) of a state as a measure of: past cost (gamma): the position relative to an obsta...
Definition: planner.cpp:12
static float evaluationFunction(EndedResult er, const vertexDescriptor &v, std::vector< vertexDescriptor > &p)
calculates cumulative cost phi, add discount factor if in plan
Definition: planner.cpp:3
virtual std::vector< vertexDescriptor > plan(TransitionSystem &g, vertexDescriptor src, ExecutionInfo &info, bool *finished)=0
Implements custom algorithm to search transition system for a plan.
Definition: task.h:19
Predicate which compares evaluation functions in State-Frontier pairs.
Definition: planner.h:27
Definition: measurement.h:74
Contains the frontier (first) and the connecting vertices.
Definition: planner.h:14
Hybrid states in the transition system.
Definition: graphTools.h:69