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>
7 
14 //typedef std::pair<vertexDescriptor, std::vector<vertexDescriptor>> Frontier;
15 
16 
17 struct Frontier{
18  vertexDescriptor frontier=TransitionSystem::null_vertex();
19  std::vector<vertexDescriptor> connecting;
20 
21  Frontier()=default;
22 
23  Frontier(vertexDescriptor _f, const std::vector<vertexDescriptor>&_c):frontier(_f), connecting(_c){}
24 
25  bool operator==(const Frontier &f)const{
26  return frontier==f.frontier && connecting==f.connecting;
27  }
28 };
29 
30 
35 struct ComparePhi{
36 
37  ComparePhi(){}
38 
39  bool operator()(const std::pair<State*, Frontier>& p1, const std::pair<State*, Frontier>& p2) const{
40  return (*p1.first).phi<(*p2.first).phi;
41  }
42 };
43 
44 
50  private:
51  vertexDescriptor m_currentVertex=0, m_goalVertex=TransitionSystem::null_vertex();
52  Task m_currentTask;
53  Task m_overarchingGoal;
54  bool m_been; //has a plan been made to fulfill this overarching goal before?
55  std::vector <vertexDescriptor> m_plan;
56  protected:
57  friend class Configurator;
58 
59  void been(bool b){m_been=b;}
60 
61  void goalVertex(vertexDescriptor gv){m_goalVertex=gv;}
62 
63 
64  public:
65  ExecutionInfo(){}
66 
67  ExecutionInfo( vertexDescriptor _cv, vertexDescriptor _goal, Task & _ct, Task & _gt, bool _been, std::vector<vertexDescriptor> _plan){
68  m_currentVertex=_cv;
69  m_goalVertex=_goal;
70  m_currentTask=_ct;
71  m_overarchingGoal=_gt;
72  m_been=_been;
73  m_plan=_plan;
74  }
75  void overarchingGoal(const Task & og){m_overarchingGoal=og;}
76 
77 
78  vertexDescriptor currentVertex()const{return m_currentVertex;}
79 
80  vertexDescriptor goalVertex()const{return m_goalVertex;}
81 
82  Task& currentTask(){return m_currentTask;}
83 
84  Task& overarchingGoal() {return m_overarchingGoal;}
85 
86  bool been()const{return m_been;}
87 
88  std::vector<vertexDescriptor> plan()const{return m_plan;}
89 
90 };
91 
92 
102 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
103 
112 float evaluationFunction(EndedResult er, const vertexDescriptor &v, std::vector<vertexDescriptor>& p);
113 
124 EndedResult estimateCost(const State &state, b2Transform start, Direction d, Task & _goal); //returns whether the controlGoal has ended and fills node with cost and error
125 
126 
131 class Planner{
132  protected:
133 
134  public:
135 
136  Planner()=default;
137 
147  virtual std::vector<vertexDescriptor> plan(TransitionSystem g, vertexDescriptor src, ExecutionInfo & info, bool *finished)=0;
148 
149 
150 };
151 
170  protected:
171 
180  void path2add2(std::vector<std::vector<vertexDescriptor>>::reverse_iterator & path, const std::vector <vertexDescriptor> & add, std::vector<std::vector<vertexDescriptor>> &paths, TransitionSystem &g);
181 
192  std::vector <vertexDescriptor> best_path(const std::vector<std::vector<vertexDescriptor>>& paths, vertexDescriptor goal, vertexDescriptor cv, bool change, const TransitionSystem& g);
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  // struct CostMap{
206  // std::map<vertexDescriptor, float> map;
207 
208  // void init(TransitionSystem & g){
209  // auto vs=boost::vertices(g);
210  // for (auto vi=vs.first; vi!=vs.first; vi++){
211  // if (g[*vi].visited()){
212  // map.emplace(std::make_pair(*vi,g[*vi].phi));
213  // }
214  // }
215  // }
216  // }costMap;
217 
218 public:
219 
220  std::vector<vertexDescriptor> plan(TransitionSystem g, vertexDescriptor src, ExecutionInfo & info, bool * finished=NULL)override;
221 
222 };
223 
228 class NoPlanner:public Planner{
229 
230  std::vector<vertexDescriptor> plan(TransitionSystem g, vertexDescriptor src, ExecutionInfo & info, bool * finished=NULL)override{
231  return std::vector<vertexDescriptor>();
232  }
233 
234 
235 };
236 
237 #endif
Definition: configurator.h:17
Information about what the configurator is doing (current Task, current vertex), what it wants to do ...
Definition: planner.h:49
Performs iterative deepening search over one unit of modular expansion (see below),...
Definition: planner.h:169
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 > plan(TransitionSystem g, vertexDescriptor src, ExecutionInfo &info, bool *finished=NULL) override
Implements custom algorithm to search transition system for a plan.
Definition: planner.cpp:199
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
Does not extract a plan.
Definition: planner.h:228
Searches the transition system and extracts a plan.
Definition: planner.h:131
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:47
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:35
Provides information on whether a Task has ended and with what heuristic -estimated- cost (chi) and p...
Definition: measurement.h:126
Contains the frontier (first) and the connecting vertices.
Definition: planner.h:17
Hybrid states in the transition system.
Definition: graphTools.h:69