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"
6 #include <algorithm>
13 //typedef std::pair<vertexDescriptor, std::vector<vertexDescriptor>> Frontier;
14 
15 
16 struct Frontier{
17  vertexDescriptor frontier=TransitionSystem::null_vertex();
18  std::vector<vertexDescriptor> connecting;
19 
20  Frontier()=default;
21 
22  Frontier(vertexDescriptor _f, const std::vector<vertexDescriptor>&_c):frontier(_f), connecting(_c){}
23 
24  bool operator==(const Frontier &f)const{
25  return frontier==f.frontier && connecting==f.connecting;
26  }
27 };
28 
29 
34 struct ComparePhi{
35 
36  ComparePhi(){}
37 
38  bool operator()(const std::pair<State*, Frontier>& p1, const std::pair<State*, Frontier>& p2) const{
39  return (*p1.first).phi<(*p2.first).phi;
40  }
41 };
42 
43 
49  private:
50  vertexDescriptor m_currentVertex=0, m_goalVertex=TransitionSystem::null_vertex();
51  Task m_currentTask;
52  Task m_overarchingGoal;
53  bool m_been; //has a plan been made to fulfill this overarching goal before?
54  std::vector <vertexDescriptor> m_plan;
55  protected:
56  friend class Configurator;
57 
58  void been(bool b){m_been=b;}
59 
60  void goalVertex(vertexDescriptor gv){m_goalVertex=gv;}
61 
62 
63  public:
64  ExecutionInfo(){}
65 
66  ExecutionInfo( vertexDescriptor _cv, vertexDescriptor _goal, Task & _ct, Task & _gt, bool _been, std::vector<vertexDescriptor> _plan){
67  m_currentVertex=_cv;
68  m_goalVertex=_goal;
69  m_currentTask=_ct;
70  m_overarchingGoal=_gt;
71  m_been=_been;
72  m_plan=_plan;
73  }
74  void overarchingGoal(const Task & og){m_overarchingGoal=og;}
75 
76 
77  vertexDescriptor currentVertex()const{return m_currentVertex;}
78 
79  vertexDescriptor goalVertex()const{return m_goalVertex;}
80 
81  Task& currentTask(){return m_currentTask;}
82 
83  Task& overarchingGoal() {return m_overarchingGoal;}
84 
85  bool been()const{return m_been;}
86 
87  std::vector<vertexDescriptor> plan()const{return m_plan;}
88 
89 };
90 
91 
101 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
102 
111 float evaluationFunction(EndedResult er, const vertexDescriptor &v, std::vector<vertexDescriptor>& p);
112 
123 EndedResult estimateCost(const State &state, b2Transform start, Direction d, Task & _goal); //returns whether the controlGoal has ended and fills node with cost and error
124 
125 
130 class Planner{
131  protected:
132 
133  public:
134 
135  Planner()=default;
136 
146  virtual std::vector<vertexDescriptor> plan(TransitionSystem& g, vertexDescriptor src, ExecutionInfo & info, bool *finished)=0;
147 
148 
149 };
150 
169  protected:
170 
179  void path2add2(std::vector<std::vector<vertexDescriptor>>::reverse_iterator & path, const std::vector <vertexDescriptor> & add, std::vector<std::vector<vertexDescriptor>> &paths, TransitionSystem &g);
180 
191  std::vector <vertexDescriptor> best_path(const std::vector<std::vector<vertexDescriptor>>& paths, vertexDescriptor goal, vertexDescriptor cv, bool change, const TransitionSystem& g);
192 
193 
194 
203  void addToPriorityQueue(const Frontier &f, std::vector<Frontier>& queue, TransitionSystem &g,const std::set<vertexDescriptor>&closed, vertexDescriptor goal=TransitionSystem::null_vertex());
204 
205 
206 public:
207 
208  std::vector<vertexDescriptor> plan(TransitionSystem& g, vertexDescriptor src, ExecutionInfo & info, bool * finished=NULL)override;
209 
210 };
211 
216 class NoPlanner:public Planner{
217 
218  std::vector<vertexDescriptor> plan(TransitionSystem& g, vertexDescriptor src, ExecutionInfo & info, bool * finished=NULL)override{}
219 
220 
221 };
222 
223 #endif
Definition: configurator.h:17
Information about what the configurator is doing (current Task, current vertex), what it wants to do ...
Definition: planner.h:48
Performs iterative deepening search over one unit of modular expansion (see below),...
Definition: planner.h:168
void addToPriorityQueue(const Frontier &f, std::vector< Frontier > &queue, TransitionSystem &g, const std::set< vertexDescriptor > &closed, vertexDescriptor goal=TransitionSystem::null_vertex())
Adds frontier to priority queue.
Definition: planner.cpp:177
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:72
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:20
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:194
Does not extract a plan.
Definition: planner.h:216
Searches the transition system and extracts a plan.
Definition: planner.h:130
virtual std::vector< vertexDescriptor > plan(TransitionSystem &g, vertexDescriptor src, ExecutionInfo &info, bool *finished)=0
Implements custom algorithm to search transition system for a plan.
A closed hybrid control loop. It has an initial disturbance representing the continuous state and a d...
Definition: task.h:45
std::vector< Frontier > frontierVertices(vertexDescriptor v, TransitionSystem &g, ExecutionInfo &info)
Performs iterative deepening search to find the frontier.
Definition: planner.cpp:100
EndedResult estimateCost(const State &state, b2Transform start, Direction d, Task &_goal)
Provides a breakdown of the cost function into its components: past cost (gamma): the position relati...
Definition: planner.cpp:13
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
Predicate which compares evaluation functions in State-Frontier pairs.
Definition: planner.h:34
Provides information on whether a Task has ended and with what heuristic -estimated- cost (chi) and p...
Definition: measurement.h:122
Contains the frontier (first) and the connecting vertices.
Definition: planner.h:16
Hybrid states in the transition system.
Definition: graphTools.h:69