Bratmobile
focused.h
1 #ifndef FOCUSED_H
2 #define FOCUSED_H
3 #include "configurator.h"
4 
8 class FocusedConfigurator:public virtual Configurator{
9  protected:
10  StateMatcher* matcher=new StateMatcher();
18 ExecutionInfo package_info(vertexDescriptor gv=TransitionSystem::null_vertex(), bool been=false){
19  return ExecutionInfo(currentVertex, gv, currentTask, controlGoal, been, m_plan);
20 }
21 
35 virtual Disturbance getDisturbance(TransitionSystem&g, vertexDescriptor v, b2World & world, const Direction & dir, const b2Transform& start);
36 
48 virtual void backtrack(std::vector <vertexDescriptor>& evaluation_q, std::vector <vertexDescriptor>&priority_q, std::set<vertexDescriptor>& closed, std::vector <vertexDescriptor>& plan_prov, vertexDescriptor module_src=MOVING_VERTEX, vertexDescriptor startRecycle=MOVING_VERTEX);
49 
58 virtual std::vector <vertexDescriptor> splitTask(vertexDescriptor v, Direction d, vertexDescriptor src=TransitionSystem::null_vertex());
59 
70 virtual bool propagateD(vertexDescriptor v1, vertexDescriptor v0);
71 
72 //if in plan the vertex gets priority
73 void planPriority(TransitionSystem&, vertexDescriptor);
74 
75 
76 //adjust real-world task
77 void adjust_rw_task(const vertexDescriptor&, TransitionSystem &, Task*, const b2Transform &);
78 
79 
91 virtual VertexMatch hardMatch(State s, Direction dir=Direction::UNDEFINED, StateMatcher::MATCH_TYPE match_type=StateMatcher::_TRUE, StateDifference * _sd=NULL); //matches to most likely
92 
93 
105 virtual VertexMatch findMatch(State s, Direction dir=Direction::UNDEFINED, StateMatcher::MATCH_TYPE match_type=StateMatcher::_TRUE, StateDifference * _sd=NULL, vertexDescriptor src=TransitionSystem::null_vertex()); //matches to most likely
106 
116 virtual std::vector<vertexDescriptor> explorer(vertexDescriptor v, TransitionSystem&g, b2World &w); //evaluates only after DEFAULT, internal one step lookahead
117 
122 void resetPhi();
123 
124 
134 std::pair <edgeDescriptor, bool> add_vertex_now(const vertexDescriptor & src, vertexDescriptor & v1, Disturbance obs,Edge edge=Edge(), bool topDown=0);
135 
144 std::pair <edgeDescriptor, bool> add_vertex_retro(vertexDescriptor &src, vertexDescriptor &v1, Edge edge=Edge(), bool topDown=0);
145 
147 std::vector <Direction> getExploredDirections(vertexDescriptor v, const std::vector<Direction>& directions);
148 
153 virtual bool preventTransition(vertexDescriptor v){
154  return v==currentVertex && (!m_plan.empty()||!currentTask.is_over());
155 }
156 
158 virtual void removeExploredTransitions(vertexDescriptor v);
159 
161 void removePointlessTransitions(vertexDescriptor v);
162 
163 
170 virtual void transitionMatrix(vertexDescriptor v, Direction d, vertexDescriptor src);
171 
181 void applyTransitionMatrix(vertexDescriptor v0, Direction d, bool ended, vertexDescriptor src, std::vector<vertexDescriptor>& plan_prov);
182 
191 void addToPriorityQueue(vertexDescriptor v, std::vector<vertexDescriptor>& queue, const std::set <vertexDescriptor>& closed);
192 
193 vertexDescriptor getNextSrc(const std::vector<vertexDescriptor>& q);
194 
195 //removes singleton vertices and self-edges
196 void ts_cleanup();
197 
198 //apply affine transformation to states (e.g. if the same situation encountered in the past is reencountered)
199 void shift_states(TransitionSystem &, const std::vector<vertexDescriptor>&, const b2Transform &); //shifts a sequence of states by a certain transform
200 
201 //return vertex from which exploration of the environment starts (explorer)
202 vertexDescriptor get_explore_start(TransitionSystem &);
203 
209 void pre_explore();
210 
211 
212 //std::vector <State> output_plan(const std::vector<vertexDescriptor> &, const TransitionSystem &);
213 
214 void explore_plan(b2World&)override;
215 
226 std::vector<Direction>::iterator get_next_option(vertexDescriptor v, vertexDescriptor src, std::vector<vertexDescriptor> full_plan);
227 
243 virtual bool recycle_plan(vertexDescriptor v, vertexDescriptor &v0, vertexDescriptor & task_start, StateMatcher::MATCH_TYPE &matchType,
244  b2Transform & shift_start, b2Transform& sk_first_start, std::pair<edgeDescriptor, bool>&edge,
245  std::vector<vertexDescriptor> &plan_prov, Direction t_get_direction){
246  return false;
247  }
248 
249 
261 std::pair<State, Edge> simulation_setup(b2World& w, Task & t, vertexDescriptor v0, b2Transform shift, b2Transform &start, std::vector<Direction>v0_options);
262 
269 void reassign_direction(vertexDescriptor bestNext, Direction& direction);
270 
271 // /**
272 // * @brief if the match is a crashed task
273 // *
274 // * @param match
275 // * @param other_matches
276 // * @return true if changes match
277 // */
278 // bool matchToSafe(VertexMatch &match,const std::vector<VertexMatch> &other_matches=std::vector<VertexMatch>());
279 
292 std::pair<edgeDescriptor, bool> setup_match_edge(VertexMatch &match, vertexDescriptor &v0, vertexDescriptor & v1,const Edge& k, Direction direction, bool changedMatch);
293 
300 virtual std::vector <vertexDescriptor> task_vertices(vertexDescriptor v, std::pair<bool, edgeDescriptor>* ep=NULL);
301 
308 bool isPreviousState(const State & s, const State & candidate);
309 // /**
310 // * @brief Returns a visited edge if present, or if the current
311 // *
312 // * @param es
313 // * @param g
314 // * @param cv
315 // * @return std::vector <vertexDescriptor>
316 // */
317 // std::vector <vertexDescriptor> visitedOrVisitingEdge(const std::vector <edgeDescriptor>& es, TransitionSystem& g, vertexDescriptor cv=TransitionSystem::null_vertex());
318 
327 vertexDescriptor getRecyclingStart(vertexDescriptor v, vertexDescriptor v1, vertexDescriptor taskStart);
328 
334 std::vector <edgeDescriptor> inEdges(vertexDescriptor v, Direction d = UNDEFINED); //returns a vector containing all the in-edges of a vertex which have the specified direction
335 
336 virtual bool closeVertex(std::set<vertexDescriptor> & closed, vertexDescriptor v);
337 
348 std::pair<edgeDescriptor, bool> addEdgeRetrospectively(vertexDescriptor v, vertexDescriptor &v1, const State & s_tmp,std::pair<edgeDescriptor, bool> first_edge, Direction d, float linearSpeed);
349 
360 bool correctQueue(std::vector<vertexDescriptor>& queue, vertexDescriptor v, vertexDescriptor startRecycle, int planProvSize);
361 
367 void adjustProbability(const edgeDescriptor &e);
368 
374 void abandonPlan(std::vector<vertexDescriptor>& planProv, vertexDescriptor v0, vertexDescriptor v1);
375 
382 virtual std::vector<Direction> partiallyExplorativeOptions(std::pair<bool, edgeDescriptor> ve);
383 
384 virtual Robot makeRobot(b2World & w, const Task & task);
390  protected:
391  vertexDescriptor lastAdded=TransitionSystem::null_vertex(); //last vertex added to the evaluation queue
392  public:
393 
403  void addToEvaluationQueue(std::vector <vertexDescriptor>& evaluationQueue, vertexDescriptor v1, TransitionSystem & g, vertexDescriptor v);
404 
405  void reset(vertexDescriptor v=TransitionSystem::null_vertex()){
406  lastAdded=v;
407  }
408 };
409 
410 
417 void visitedDirectionsPushBack( vertexDescriptor v, std::vector<Direction> & visitedDirections, Direction direction);
418 
419 virtual StateMatcher::MATCH_TYPE desiredMatch() {
420  return StateMatcher::MATCH_TYPE::ABSTRACT;
421 }
422 
427 void enforce_edge();
428 
432 virtual bool shouldPartiallyExplore(const std::vector<edgeDescriptor>& oe, std::pair<bool, edgeDescriptor> ve);
433 
438 virtual bool canPropagate(vertexDescriptor v);
439 
440 virtual bool canReassignOutcome(vertexDescriptor v);
441 
442 virtual float customSimulationStep(vertexDescriptor v=TransitionSystem::null_vertex());
443 
444 
445 bool hasPlanFinished(){
446  return m_plan.empty() && currentTask.is_over();
447 }
448 
449 public:
450 
451 void adjust_goal_expectation()override{}
452 
454 
456  init(_task);
457 }
458 
459 virtual ~FocusedConfigurator(){
460  delete matcher;
461  matcher=NULL;
462 }
463 
464 
465 
466 };
467 
468 #endif
Definition: configurator.h:17
virtual void init(Task _task=Task())
Initialises configurator.
Definition: configurator.cpp:20
Information about what the configurator is doing (current Task, current vertex), what it wants to do ...
Definition: planner.h:49
Adds and removes vertices from the evaluation queue.
Definition: focused.h:389
void addToEvaluationQueue(std::vector< vertexDescriptor > &evaluationQueue, vertexDescriptor v1, TransitionSystem &g, vertexDescriptor v)
Adds to evaluation queue: if the vertex represents a successful task, it is added to the end of the q...
Definition: focused.cpp:872
Configurator that only replans if the current task fails.
Definition: focused.h:8
std::pair< edgeDescriptor, bool > addEdgeRetrospectively(vertexDescriptor v, vertexDescriptor &v1, const State &s_tmp, std::pair< edgeDescriptor, bool > first_edge, Direction d, float linearSpeed)
Adds edge retrospectively (used in split task)
Definition: focused.cpp:793
virtual void transitionMatrix(vertexDescriptor v, Direction d, vertexDescriptor src)
Definition: focused.cpp:330
virtual std::vector< vertexDescriptor > explorer(vertexDescriptor v, TransitionSystem &g, b2World &w)
Constructs transition system using a Box2D simulation combined with an A* graph expansion algorithm.
Definition: focused.cpp:82
bool correctQueue(std::vector< vertexDescriptor > &queue, vertexDescriptor v, vertexDescriptor startRecycle, int planProvSize)
Edits.
Definition: focused.cpp:807
void adjustProbability(const edgeDescriptor &e)
Adjusts the probability that a continuous state (edge target) will occur after taking a discrete stat...
Definition: focused.cpp:820
bool isPreviousState(const State &s, const State &candidate)
more flexible way to estimate whether the previous state represents the previous task based on matchi...
Definition: focused.cpp:722
std::pair< edgeDescriptor, bool > add_vertex_retro(vertexDescriptor &src, vertexDescriptor &v1, Edge edge=Edge(), bool topDown=0)
Adds vertices retroactively (e.g. after a state is split)
Definition: focused.cpp:12
void explore_plan(b2World &) override
Explores and plan.
Definition: focused.cpp:599
virtual std::vector< vertexDescriptor > splitTask(vertexDescriptor v, Direction d, vertexDescriptor src=TransitionSystem::null_vertex())
Split tasks into sub-states of fixed length.
Definition: focused.cpp:161
void applyTransitionMatrix(vertexDescriptor v0, Direction d, bool ended, vertexDescriptor src, std::vector< vertexDescriptor > &plan_prov)
Sets permitted transitions out of a state, formally combines jump guard J and guard Psi.
Definition: focused.cpp:381
virtual bool recycle_plan(vertexDescriptor v, vertexDescriptor &v0, vertexDescriptor &task_start, StateMatcher::MATCH_TYPE &matchType, b2Transform &shift_start, b2Transform &sk_first_start, std::pair< edgeDescriptor, bool > &edge, std::vector< vertexDescriptor > &plan_prov, Direction t_get_direction)
Does not recycle.
Definition: focused.h:243
void enforce_edge()
Used to make sure that there is always a connection between DUMMY/MOVING to the next in plan - useful...
Definition: focused.cpp:886
void abandonPlan(std::vector< vertexDescriptor > &planProv, vertexDescriptor v0, vertexDescriptor v1)
Clears plan vector, sets current task to change and clears current vertices.
Definition: focused.cpp:837
void visitedDirectionsPushBack(vertexDescriptor v, std::vector< Direction > &visitedDirections, Direction direction)
Pushes directions visited at this iteration (not using phi) to input vector.
Definition: focused.cpp:288
virtual VertexMatch findMatch(State s, Direction dir=Direction::UNDEFINED, StateMatcher::MATCH_TYPE match_type=StateMatcher::_TRUE, StateDifference *_sd=NULL, vertexDescriptor src=TransitionSystem::null_vertex())
Searches transition System for a match to a state provided. Continuous states are matched,...
Definition: focused.cpp:536
std::vector< Direction > getExploredDirections(vertexDescriptor v, const std::vector< Direction > &directions)
Definition: focused.cpp:297
vertexDescriptor getRecyclingStart(vertexDescriptor v, vertexDescriptor v1, vertexDescriptor taskStart)
Returns the vertex from which to start recycling plan.
Definition: focused.cpp:765
void removePointlessTransitions(vertexDescriptor v)
Definition: focused.cpp:318
std::pair< State, Edge > simulation_setup(b2World &w, Task &t, vertexDescriptor v0, b2Transform shift, b2Transform &start, std::vector< Direction >v0_options)
Sets up for simulation.
Definition: focused.cpp:624
void resetPhi()
Resets all vertices evaluation function phi to a default unitialised value of 10 Also resets all vert...
Definition: focused.cpp:20
ExecutionInfo package_info(vertexDescriptor gv=TransitionSystem::null_vertex(), bool been=false)
Package task/goal execution details into an Execution Info instance.
Definition: focused.h:18
void addToPriorityQueue(vertexDescriptor v, std::vector< vertexDescriptor > &queue, const std::set< vertexDescriptor > &closed)
Adds vertexDescriptor to priority queue according to a custom heuristic.
Definition: focused.cpp:433
virtual void removeExploredTransitions(vertexDescriptor v)
Definition: focused.cpp:307
virtual void backtrack(std::vector< vertexDescriptor > &evaluation_q, std::vector< vertexDescriptor > &priority_q, std::set< vertexDescriptor > &closed, std::vector< vertexDescriptor > &plan_prov, vertexDescriptor module_src=MOVING_VERTEX, vertexDescriptor startRecycle=MOVING_VERTEX)
Iterates through vertices, if they result in crash, it splits the tasks and recalculates evaluation f...
Definition: focused.cpp:221
virtual bool canPropagate(vertexDescriptor v)
propagates only if the previous vertex
Definition: focused.cpp:261
std::pair< edgeDescriptor, bool > setup_match_edge(VertexMatch &match, vertexDescriptor &v0, vertexDescriptor &v1, const Edge &k, Direction direction, bool changedMatch)
Given a valid match, sets up the edge with the previous vertex Creates new edge if it doesn't exist,...
Definition: focused.cpp:663
virtual std::vector< Direction > partiallyExplorativeOptions(std::pair< bool, edgeDescriptor > ve)
Assigns options to vertex which has in previous iteration been expanded. Assigns direction of success...
Definition: focused.cpp:847
virtual bool propagateD(vertexDescriptor v1, vertexDescriptor v0)
Propagate a disturbance backwards to all states representing the same task (max 1)
Definition: focused.cpp:270
virtual Disturbance getDisturbance(TransitionSystem &g, vertexDescriptor v, b2World &world, const Direction &dir, const b2Transform &start)
Use attention window to find if any previously avoided obstacle is in the way of the goal,...
Definition: focused.cpp:41
virtual std::vector< vertexDescriptor > task_vertices(vertexDescriptor v, std::pair< bool, edgeDescriptor > *ep=NULL)
Rerturns all the vertices making up a task.
Definition: focused.cpp:672
std::pair< edgeDescriptor, bool > add_vertex_now(const vertexDescriptor &src, vertexDescriptor &v1, Disturbance obs, Edge edge=Edge(), bool topDown=0)
Adds state after discovering it in exploration.
Definition: focused.cpp:4
void adjust_goal_expectation() override
Uses tracking information to adjust the position of the goal relative to the robot.
Definition: focused.h:451
void reassign_direction(vertexDescriptor bestNext, Direction &direction)
Reassigns direction as the direction of the bext task to expand next in explorer.
Definition: focused.cpp:634
std::vector< edgeDescriptor > inEdges(vertexDescriptor v, Direction d=UNDEFINED)
Returns a vector of all the in-edges of vertex.
Definition: focused.cpp:746
virtual VertexMatch hardMatch(State s, Direction dir=Direction::UNDEFINED, StateMatcher::MATCH_TYPE match_type=StateMatcher::_TRUE, StateDifference *_sd=NULL)
Searches transition System for a match to a state provided. Continuous states are matched,...
Definition: focused.cpp:468
virtual bool shouldPartiallyExplore(const std::vector< edgeDescriptor > &oe, std::pair< bool, edgeDescriptor > ve)
Psi guard: should only current task be simulated?
Definition: focused.cpp:891
std::vector< Direction >::iterator get_next_option(vertexDescriptor v, vertexDescriptor src, std::vector< vertexDescriptor > full_plan)
Returns an iterator to the next option representing a discrete Task transition. If v is in the plan,...
virtual bool preventTransition(vertexDescriptor v)
Definition: focused.h:153
void pre_explore()
Prepares transitionsystem for exploration: clears all edges of q0 with states that aren't the current...
Definition: focused.cpp:589
virtual Robot makeRobot(b2World &w, const Task &task)
Makes the robot object in the world with the given start position and task.
Definition: focused.cpp:866
Robot class for Box2D simulation.
Definition: robot.h:18
Definition: graphTools.h:466
A closed hybrid control loop. It has an initial disturbance representing the continuous state and a d...
Definition: task.h:47
bool is_over()
If task has finished executing.
Definition: task.h:369
Definition: disturbance.h:113
Edges connecting states in the transition system.
Definition: graphTools.h:40
Contains the differences between the contiuous components of two hybrid states.
Definition: graphTools.h:150
Hybrid states in the transition system.
Definition: graphTools.h:69