1 #ifndef HRICS_MULTI_AGENT_GRID_HPP
2 #define HRICS_MULTI_AGENT_GRID_HPP
6 #define DRAW_OPTIMIZE_FRONTIER
8 #include "API/planningAPI.hpp"
9 #include "API/Grids/gridsAPI.hpp"
15 class MetaFrontierCells;
19 typedef std::tr1::shared_ptr<FrontierCells> FrontierPtr;
20 typedef std::tr1::shared_ptr<MetaFrontierCells> MetaFrontierPtr;
38 typedef std::tr1::shared_ptr<MetaAgentInGrid> s_ptr;
40 MetaAgentInGrid::s_ptr shared_clone();
41 std::vector<AgentInGrid*> & getAgentsInGrid(
void){
return this->_realAgents;}
47 Robot* getCylinder(
void){
return _cylinder;}
48 double getCylinderRadius(
void){
return _cyl_radius;}
49 void setCylinder(
Robot * c);
51 std::vector<MultiAgentCell*> &
reachable(){
return _reachable;}
53 std::vector<MultiAgentCell*> &
boundaries(){
return _boundaries;}
55 std::vector<MultiAgentCell* > &
frontiers(MetaAgentInGrid::s_ptr other){
return _frontiers[other.get()];}
56 std::vector<MultiAgentCell* > & frontiers_ok(MetaAgentInGrid::s_ptr other){
return _frontiers_ok[other.get()];}
57 bool frontierFullyChecked(MetaAgentInGrid::s_ptr other){
return _frontierFullyChecked[other.get()];}
58 void setFrontierFullyChecked(MetaAgentInGrid::s_ptr other,
bool b=
true){_frontierFullyChecked[other.get()]=b;}
59 bool isFrontierComputed(MetaAgentInGrid::s_ptr other){
return _frontiersComputed[other.get()];}
60 void setFrontierComputed(MetaAgentInGrid::s_ptr other,
bool b=
true){_frontiersComputed[other.get()]=b;}
66 std::vector<MultiAgentCell*> _reachable;
69 std::vector<MultiAgentCell*> _boundaries;
71 std::map<MetaAgentInGrid*, std::vector<MultiAgentCell* > > _frontiers;
72 std::map<MetaAgentInGrid*, std::vector<MultiAgentCell* > > _frontiers_ok;
73 std::map<MetaAgentInGrid*, bool> _frontierFullyChecked;
74 std::map<MetaAgentInGrid*, bool> _frontiersComputed;
76 std::vector<AgentInGrid*> _realAgents;
77 static char _letter_id_cnt;
86 void setRobot(
Robot* r){_robot=r;}
90 void setMaxDist(
double d){_maxDist=d;}
92 MultiAgentCell* getOrigin(){
return this->_origin;}
93 void setOrigin(MultiAgentCell* c){this->_origin=c;}
94 MultiAgentCell* getTarget(){
return this->_target;}
95 void setTarget(MultiAgentCell* c){this->_target=c;}
97 std::vector<MultiAgentCell*> &
reachable(){
return _metaAgent->reachable();}
99 std::vector<MultiAgentCell*> &
boundaries(){
return _metaAgent->boundaries();}
101 std::vector<MultiAgentCell* > &
frontiers(AgentInGrid *other){
return getMetaAgent()->frontiers(other->getMetaAgent());}
102 bool frontierFullyChecked(AgentInGrid* other){
return _metaAgent->frontierFullyChecked(other->getMetaAgent());}
103 void setFrontierFullyChecked(
AgentInGrid* other,
bool b=
true){_metaAgent->setFrontierFullyChecked(other->getMetaAgent(),b);}
105 double getSpeed(
void){
return _speed;}
106 void setSpeed(
double s){_speed=s;}
108 void setDistanceComputed(
bool b=
true){_distanceComputed=b;}
109 void setMetaAgent(MetaAgentInGrid::s_ptr meta){_metaAgent=meta;}
110 MetaAgentInGrid::s_ptr getMetaAgent(
void){
return _metaAgent;}
115 bool _distanceComputed;
116 MetaAgentInGrid::s_ptr _metaAgent;
117 MultiAgentCell *_origin,*_target;
122 timespec access_total_time;
123 std::vector<timespec> reachability_time;
124 timespec reachability_total_time;
125 std::vector<timespec> frontiers_time;
126 std::vector<unsigned int> frontiers_iterations;
127 timespec frontiers_total_time;
128 unsigned int frontiers_total_iterations;
130 access_total_time.tv_nsec = 0;
131 access_total_time.tv_sec = 0;
132 reachability_time.clear();
133 reachability_total_time.tv_nsec=0;
134 reachability_total_time.tv_sec=0;
137 void reset_frontiers(
unsigned int size){
138 frontiers_time.assign(size,null_ts());
139 frontiers_iterations.assign(size,0);
140 frontiers_total_iterations=0;
141 frontiers_total_time=null_ts();
143 static timespec null_ts(
void){timespec nts;nts.tv_nsec=nts.tv_sec=0;
return nts;}
160 MultiAgentGrid(
double pace, std::vector<double> envSize, std::vector<Robot *> &agents);
163 void resetData(
void);
170 void setAgents(std::vector<Robot*> &agents);
171 std::vector<Robot*> & getAgents() {
return mAgents; }
172 AgentInGrid* getAgentStructAt(
unsigned int index){
return mAgentsInGrid[index];}
174 void setAgentTarget(
unsigned int a);
176 double getNbCellX() {
return _nbCellsX;}
177 double getNbCellY() {
return _nbCellsY;}
179 void setAsNotSorted() {gridIsSorted =
false;}
199 void computeAccessAndDistCombined(
void);
215 std::vector<MultiAgentCell*>
computeOtherTrajectory(MultiAgentCell * cell_origin, MultiAgentCell *cell_dest,
unsigned int agent_index,
double epsilon=1,
double dist_max=-1,
int max_expansions=-1);
229 void computeDistancesForAgent(MultiAgentCell* cell,
unsigned int agent_index);
230 void computeAltDistancesForAgent(MultiAgentCell* origin,
unsigned int agent_index);
231 void enableAltDistancesSums(
bool b=
true){_enable_alt_distances_sums=b;
if(b){this->clearAltDistancesInCells();}}
232 void clearAltDistancesInCells(
void);
234 unsigned int getMaxAlternativeDistancesForCells(
void){
return _max_alternative_distances_for_cells;}
235 void getMaxAlternativeDistancesForCells(
unsigned int v){_max_alternative_distances_for_cells=v;}
246 std::pair<MultiAgentCell*,MultiAgentCell*>
neighborSolution(
unsigned int agent_1,
unsigned int agent_2,std::pair<MultiAgentCell*,MultiAgentCell*> solution);
247 void searchAllFrontiers();
256 std::vector<FrontierPtr >
searchFrontiers(
unsigned int agent_1,
unsigned int agent_2,
double keep_distance);
257 std::vector<FrontierPtr > simulatedAnnealingFrontierSearch(
unsigned int agent_1,
unsigned int agent_2,
double keep_distance);
258 std::vector<MetaFrontierPtr > hillClimberFrontierSearch(
unsigned int agent1,
unsigned int agent2,
double keep_distance);
259 std::vector<FrontierPtr > frontierSearch(
unsigned int agent1,
unsigned int agent2,
double keep_distance);
260 std::vector<FrontierPtr > exhaustiveFrontierSearch(
unsigned int agent1,
unsigned int agent2,
double keep_distance);
261 std::vector<FrontierPtr > handInHandFrontierSearch(
unsigned int agent1,
unsigned int agent2,
double keep_distance);
263 void saveFrontiers(std::ofstream & output);
264 bool loadFrontiers(std::ifstream & input);
275 std::vector<MultiAgentCell*>
const & getFrontierCells(
unsigned int i,
unsigned int j);
277 double getArmReach(
unsigned int i);
278 double getArmReach(AgentInGrid *a);
289 void addFrontier(
unsigned int agent,
unsigned int other, MultiAgentCell * cell);
290 FrontierPtr getRandomFrontier(
unsigned int a1,
unsigned int a2,
double timeout_ms=-1);
291 std::vector<MultiAgentCell*> & getFrontierCheckedOk(
unsigned int a1,
unsigned int a2);
293 double getFrontierSearchTempDecrease(
void){
return _frontier_search_temp_decrease;}
294 void setFrontierSearchTempDecrease(
double v){_frontier_search_temp_decrease=v;}
295 double getFrontierSearchStartTemp(
void){
return _frontier_search_start_temp;}
296 void setFrontierSearchStartTemp(
double v){_frontier_search_start_temp=v;}
297 unsigned int getFrontierSearchMaxIt(
void){
return _frontier_search_max_it;}
309 double getFrontierSearchStopDist(
void){
return _frontier_search_stop_dist;}
317 ComputationStat & getComputationStats(
void){
return this->_computation_stat;}
329 void _drawCell(MultiAgentCell *cell,
double *color);
332 void setAgentIndexToDrawGrid(
int index){
333 this->_agent_index_to_draw_grid=index;
335 void setDrawAgentAccessibilityGrid(
bool b,
bool boundariesOnly=
false){this->_drawAgentReachGrid=b; this->_drawBoundariesOnly=boundariesOnly;}
336 void setDrawAStar(
bool b){_draw_a_star=b;}
337 void setDrawFrontiers(
bool b,
unsigned int i=0,
unsigned int j=0){_drawFrontiers=b;_drawFrontierIndices.first=i;_drawFrontierIndices.second=j;}
338 void setDrawFrontiersSearchLog(
bool b){_drawLog=b;}
339 unsigned int getFrontierSearchLogSize(
void);
340 void setFrontierSearchLogIndex(
unsigned int i){_log_draw_window=i;}
341 void setFrontierSearchLogWindow(
unsigned int i){_log_draw_window_size=i;}
343 #ifdef DRAW_OPTIMIZE_FRONTIER
344 void setDrawGridForOptim(
bool b,std::vector<std::pair<MultiAgentCell*,unsigned int> > &cells_agents){_draw_grid_for_optim=b;_draw_grid_for_optim_cells_agents=cells_agents;}
345 void unsetDrawGridForOptim(
void){_draw_grid_for_optim=
false;_draw_grid_for_optim_cells_agents.clear();}
347 #if defined(DRAW_FRONTIER_HAND_IN_HAND) || defined(DRAW_OPTIMIZE_FRONTIER)
348 void setDrawOptimizeFrontier(MultiAgentCell *c1,MultiAgentCell* c2,
bool ok){_draw_frontier_search_cells.first=c1;_draw_frontier_search_cells.second=c2;_draw_frontier_search_is_pair_ok=ok;_draw_frontier_search=
true;}
349 void unsetDrawOptimizeFrontier(
void){_draw_frontier_search=
false;}
352 void setDrawExtraCells(std::vector<MultiAgentCell*>::iterator first,std::vector<MultiAgentCell*>::iterator last,
double ratio_max){
354 _draw_extra_cells=std::make_pair(first,last);
355 _temp_color_max_ratio=ratio_max;
357 void unsetDrawExtraCells(){_draw_extra=
false;_draw_extra_cells.first=_draw_extra_cells.second;_temp_color_max_ratio=1;}
380 void resetDistances(
void);
391 std::vector<Robot*> mAgents;
392 std::vector<AgentInGrid*> mAgentsInGrid;
400 std::vector<std::pair<double,MultiAgentCell*> > sortedGrid;
409 unsigned int _max_alternative_distances_for_cells;
410 bool _enable_alt_distances_sums;
411 std::pair<MultiAgentCell*,double> _best_cell_in_alt_dist_sum;
414 bool _use_reachable_for_frontier_search;
416 double _frontier_search_temp_decrease;
417 double _frontier_search_start_temp;
418 unsigned int _frontier_search_max_it;
419 double _frontier_search_stop_dist;
420 std::vector<std::vector<std::pair<double,std::pair<MultiAgentCell*,MultiAgentCell*> > > > _log_frontier_seeking;
421 unsigned int _log_draw_window;
422 unsigned int _log_draw_window_size;
423 bool _save_log_frontier;
427 bool _drawAgentReachGrid;
428 bool _drawBoundariesOnly;
430 #if defined(DRAW_FRONTIER_HAND_IN_HAND) || defined(DRAW_OPTIMIZE_FRONTIER)
431 bool _draw_frontier_search;
432 std::pair<MultiAgentCell*,MultiAgentCell*> _draw_frontier_search_cells;
433 bool _draw_frontier_search_is_pair_ok;
435 #ifdef DRAW_OPTIMIZE_FRONTIER
436 bool _draw_grid_for_optim;
437 std::vector<std::pair<MultiAgentCell*,unsigned int> > _draw_grid_for_optim_cells_agents;
439 #ifdef DRAW_FRONTIER_STEPS
440 bool _draw_frontier_steps;
441 std::vector<MultiAgentCell*> _draw_frontier_steps_cells;
443 int _agent_index_to_draw_grid;
446 std::pair<unsigned int, unsigned int> _drawFrontierIndices;
447 ComputationStat _computation_stat;
449 std::pair<std::vector<MultiAgentCell*>::iterator,std::vector<MultiAgentCell*>::iterator > _draw_extra_cells;
450 double _temp_color_max_ratio;
471 typedef std::tr1::shared_ptr<CylinderInCell> s_ptr;
473 _cylinder(cyl),_accessible(accessible),_access_computed(access_computed){}
474 bool isAccessible(){
return _accessible;}
475 bool isAccessibilityComputed(){
return _access_computed;}
476 void setAccessible(
bool accessible){_accessible=accessible; _access_computed=
true;}
477 void unsetAccessibilityComputed(){_accessible=_access_computed=
false;}
478 Robot* getCylinder(){
return _cylinder;}
483 bool _access_computed;
489 typedef std::tr1::shared_ptr<MetaAgentInCell> s_ptr;
490 MetaAgentInCell(MultiAgentGrid::MetaAgentInGrid::s_ptr meta_in_grid,CylinderInCell::s_ptr cyl,
bool reach_computed=
false,
bool reach=
false,
bool boundary=
false):
491 _cylInCell(cyl),_reachable(reach),_reachComputed(reach_computed),_boundary(boundary), _metaAgentInGrid(meta_in_grid),letter_id(_letter_cnt++){}
492 MetaAgentInCell::s_ptr shared_clone(MultiAgentGrid::MetaAgentInGrid::s_ptr meta_in_grid);
495 bool isAccessible(){
return _cylInCell->isAccessible();}
496 bool isAccessibilityComputed(){
return _cylInCell->isAccessibilityComputed();}
497 void setAccessible(
bool accessible){this->getCylinderInCell()->setAccessible(accessible);}
498 void unsetAccessibilityComputed(){getCylinderInCell()->unsetAccessibilityComputed();}
499 bool isReachable(){
return _reachable;}
500 bool isReachabilityComputed(){
return _reachComputed;}
501 void setReachability(
bool b){_reachable=b;_reachComputed=
true;}
502 void unsetReachabilityComputed(){_reachable=_reachComputed=
false;}
503 bool isBoundary(){
return _boundary;}
504 void setBoundary(
bool b){_boundary=b;}
506 CylinderInCell::s_ptr getCylinderInCell(
void){
return _cylInCell;}
507 MultiAgentGrid::MetaAgentInGrid::s_ptr getMetaAgentInGrid(){
return _metaAgentInGrid;}
509 std::vector<MetaFrontierPtr> & getFrontiers(MetaAgentInCell::s_ptr other){
return _meta_frontiers[other->getMetaAgentInGrid().get()];}
510 std::vector<MetaFrontierPtr> & getFrontiers(MultiAgentGrid::MetaAgentInGrid::s_ptr other){
return _meta_frontiers[other.get()];}
514 CylinderInCell::s_ptr _cylInCell;
518 MultiAgentGrid::MetaAgentInGrid::s_ptr _metaAgentInGrid;
519 std::vector<AgentInCell*> _realAgents;
520 static char _letter_cnt;
521 std::map< MultiAgentGrid::MetaAgentInGrid*,std::vector<MetaFrontierPtr > > _meta_frontiers;
530 void initFrontiersVector(
unsigned int size){_frontiers.assign(size,std::vector<FrontierPtr>(0));}
533 std::vector<Eigen::Vector2d,Eigen::aligned_allocator<Eigen::Vector2d> > vect_traj;
534 std::vector<MultiAgentCell*>
traj;
538 void setAccessible(
bool b){getMetaAgent()->setAccessible(b);}
539 void unsetAccessibilityComputed(){getMetaAgent()->unsetAccessibilityComputed();}
543 bool isReachable(){
return checkMetaAgent() && getMetaAgent()->isReachable();}
547 void setReachability(
bool b){assert(this->checkMetaAgent()); getMetaAgent()->setReachability(b);}
548 void unsetReachabilityComputed(){assert(checkMetaAgent());getMetaAgent()->unsetReachabilityComputed();}
555 std::deque<MultiAgentCell*> origin_alternatives;
556 std::deque<MultiAgentCell*> come_from_alternatives;
563 void setBoundary(
bool b){getMetaAgent()->setBoundary(b);}
564 std::vector<std::tr1::shared_ptr<FrontierCells> > & frontiers(AgentInCell* other){
return _frontiers[other->index];}
565 std::vector<MetaFrontierPtr> & getMetaFrontier(AgentInCell* other){
return getMetaAgent()->getFrontiers(other->getMetaAgent());}
566 std::vector<MetaFrontierPtr> & getMetaFrontier(MultiAgentGrid::MetaAgentInGrid::s_ptr other){
return getMetaAgent()->getFrontiers(other);}
569 CylinderInCell::s_ptr getCylinderInCell(
void){
return this->getMetaAgent()->getCylinderInCell();}
570 MetaAgentInCell::s_ptr getMetaAgent(){
return _metaAgentInCell;}
571 void setMetaAgent(MetaAgentInCell::s_ptr meta){_metaAgentInCell=meta;metaLetter=_metaAgentInCell->letter_id;}
572 bool checkMetaAgent(){
return (this->
agentInGrid->getMetaAgent()==this->getMetaAgent()->getMetaAgentInGrid());}
576 MetaAgentInCell::s_ptr _metaAgentInCell;
577 std::vector<std::vector<FrontierPtr > > _frontiers;
583 MultiAgentCell(
int i, Eigen::Vector2i coord, Eigen::Vector2d corner, MultiAgentGrid* grid);
585 ~MultiAgentCell() { }
598 unsigned int getAgentNumber(){
return _agentsInCell.size();}
599 MultiAgentGrid::MetaAgentInGrid::s_ptr getMetaFromGrid(
unsigned int a){
return this->
getAgentAt(a)->
agentInGrid->getMetaAgent();}
605 void setDistance(
unsigned int index,
double value) {
getAgentAt(index)->
distance = value; }
606 void setAltDistance(
unsigned int index,
double value, MultiAgentCell* alt_origin, MultiAgentCell *previous_cell=0);
608 double getAltDistance(
unsigned int index,MultiAgentCell* alt_origin);
618 std::vector<MultiAgentCell*> getTrajAny(
unsigned int agent, MultiAgentCell *origin);
621 std::vector<MultiAgentCell*>
getAltTraj(
unsigned int agent, MultiAgentCell *alt_origin,
bool reverse=
false);
624 bool getOpen() {
return _Open; }
625 void setOpen() { _Open =
true; }
627 bool getClosed() {
return _Closed; }
628 void setClosed() { _Closed =
true; }
630 double getTempColor(){
return _tmp_color;}
631 void setTempColor(
double c){_tmp_color=c;}
633 void resetExplorationStatus() { _Open =
false; _Closed =
false; }
637 std::vector<Eigen::Vector2d,Eigen::aligned_allocator<Eigen::Vector2d> > & getVectorTraj(
unsigned int index) {
return getAgentAt(index)->vect_traj;}
638 void setVectorTraj(
unsigned int index,std::vector<Eigen::Vector2d,Eigen::aligned_allocator<Eigen::Vector2d> > & vec_traj) {
getAgentAt(index)->vect_traj = vec_traj; }
640 std::vector<MultiAgentCell*> & getTraj(
unsigned int index) {
return getAgentAt(index)->
traj;}
642 void setTraj(
unsigned int index, std::vector<MultiAgentCell*> & traj) {this->
getAgentAt(index)->
traj = traj; }
643 double getTempDist(
void){
return _temp_dist;}
644 void setTempDist(
double v){_temp_dist=v;}
645 double getTempEstim(
void){
return _temp_estim;}
646 void setTempEstim(
double v){_temp_estim=v;}
647 MultiAgentCell* getTempCameFrom(
void) {
return _temp_came_from;}
648 void setTempCameFrom(MultiAgentCell * f) {_temp_came_from=f;}
651 MultiAgentCell* getAltCameFrom(
unsigned int index, MultiAgentCell* alt_origin);
654 bool isAccessible(
unsigned int index){
return getAgentAt(index)->getCylinderInCell()->isAccessible();}
655 void setAccessible(
unsigned int index,
bool v){
getAgentAt(index)->getCylinderInCell()->setAccessible(v);}
656 bool isAccessibilityComputed(
unsigned int index){
return getAgentAt(index)->getCylinderInCell()->isAccessibilityComputed();}
662 bool isFrontier(
unsigned int a1,
unsigned int a2){
return (
getAgentAt(a1)->frontiers(
getAgentAt(a2)).size() > 0);}
664 bool checkIsInCollision(
unsigned int agent_this,MultiAgentCell* other,
unsigned int agent_other);
671 std::vector<MetaFrontierPtr> & getMetaFrontier(
unsigned int a1,
unsigned int a2){
672 assert (isReachable(a1));
674 return getAgentAt(a1)->getMetaFrontier(getMetaFromGrid(a2));
676 std::vector<MetaFrontierPtr> & getMetaFrontier(
unsigned int a1,MultiAgentGrid::MetaAgentInGrid::s_ptr m2){
677 assert (isReachable(a1));
683 FrontierPtr
getRealFrontier(
unsigned int a1,
unsigned int a2,MetaFrontierPtr mfrontier);
686 void setBlankCost() { _costIsComputed =
false;}
691 Eigen::Vector2i getCoord() {
return _Coord; }
731 void resetDistances(
unsigned int index);
732 void resetAllDistances(
void);
744 std::vector<MultiAgentCell*>
getNeighbors(
unsigned int index);
746 std::vector<MultiAgentCell*> findNeighborsInRange(
unsigned int agent,
double range);
761 std::vector<MultiAgentCell*>
getCrown(
double min,
double max);
764 std::tr1::shared_ptr<MetaFrontierCells> addMetaFrontier(MultiAgentCell *other,
bool over_obstacle,
unsigned int agent_this,
unsigned int agent_other,
double dist,
bool check_exists=
false);
765 std::tr1::shared_ptr<MetaFrontierCells> addMetaFrontier(MultiAgentCell *other,
bool over_obstacle, MetaAgentInCell::s_ptr agent_this, MetaAgentInCell::s_ptr agent_other,
double dist,
bool check_exists=
false);
766 std::tr1::shared_ptr<FrontierCells> addFrontierComplete(MultiAgentCell *other,
bool over_obstacle,
unsigned int agent_this,
unsigned int agent_other,
double dist,
bool check_exists=
false);
770 std::vector<AgentInCell*> _agentsInCell;
771 std::vector<CylinderInCell::s_ptr> _cylinders;
772 std::vector<MetaAgentInCell::s_ptr> _metaAgents;
777 Eigen::Vector2i _Coord;
789 bool _costIsComputed;
796 MultiAgentCell * _temp_came_from;
801 double _alt_distance_sum;
808 _metaA(agentA),_metaB(agentB),_cellA(cellA),_cellB(cellB), _dist(distance), _checked_ok(0), _over_obstacle(over_obstacle) {}
809 MultiAgentCell * cellOf(MultiAgentGrid::MetaAgentInGrid::s_ptr meta){
810 if(meta==_metaA){
return _cellA;}
811 if(meta==_metaB){
return _cellB;}
816 return _implementations_of_this[std::make_pair(a1,a2)];
820 _implementations_of_this[std::make_pair(a1,a2)] = frontier;
824 double getDistance(){
return _dist;}
827 cell1(cell1),cell2(cell2),a1(a1),a2(a2){}
828 CheckCellsAre(MetaFrontierPtr & val){cell1=val->_cellA;cell2=val->_cellB;a1=val->_metaA;a2=val->_metaB;}
829 bool operator()(MetaFrontierPtr other){
830 if(other->cellOf(a1) == cell1 && other->cellOf(a2) == cell2){
836 MultiAgentGrid::MetaAgentInGrid::s_ptr a1,a2;
839 bool getCheckedOk(){
return _checked_ok;}
840 void setCheckedOk(
bool b=
true){_checked_ok=b;}
841 confPtr_t getObjectPosition(){
return object_position;}
842 void setObjectPosition(confPtr_t q_obj){this->object_position = q_obj;}
843 bool isOverObstacle(){
return _over_obstacle;}
846 std::map<std::pair<MultiAgentGrid::AgentInGrid*,MultiAgentGrid::AgentInGrid*>, FrontierPtr> _implementations_of_this;
847 MultiAgentGrid::MetaAgentInGrid::s_ptr _metaA;
848 MultiAgentGrid::MetaAgentInGrid::s_ptr _metaB;
849 MultiAgentCell * _cellA;
850 MultiAgentCell * _cellB;
853 confPtr_t object_position;
858 enum FrontierCheckStatus {FCS_NONE=0, FCS_OBJECT, FCS_GRAB_CONFS, FCS_HANDOVER,FCS_TRAJECTORIES,FCS_ENUM_SIZE};
859 FrontierCells() : agentA(0),agentB(0),agentA_ind(0),agentB_ind(0),
860 confA(),confB(),check_status(FCS_NONE),status_ok(FCS_ENUM_SIZE,
false),
862 cell(0), meta_frontier() {status_ok[FCS_NONE]=
true;}
868 unsigned int agentA_ind;
869 unsigned int agentB_ind;
872 confPtr_t r_confA,r_confB;
873 double dist(){
return meta_frontier->getDistance();}
878 std::vector<bool> status_ok;
879 std::vector<bool> r_status_ok;
882 Eigen::Vector3d grabA;
883 Eigen::Vector3d grabB;
884 Eigen::Vector3d r_grabA,r_grabB;
892 bool isSymetric(){
return _symetric;}
899 if(agent==agentA_ind){
return cellA();}
900 if(agent==agentB_ind){
return cellB();}
903 confPtr_t confOf(
Robot *r){
904 if(agentA->robot()==r){
return confA;}
905 else if(agentB->robot()==r){
return confB;}
906 else {confPtr_t p;
return p;}
913 std::vector<FrontierPtr> findNeighbourFrontiers(
double keep_distance,
double min_distance=0);
914 std::vector<FrontierPtr> findNeighbourFrontiersJumping(
double keep_distance,
double min_distance,
unsigned int number);
915 MultiAgentCell *cell;
916 MetaFrontierPtr meta_frontier;
917 bool isOverObstacle(){
return meta_frontier->isOverObstacle();}
923 #endif // HRICS_TWODGRID_HPP
void init(void)
initialisation of the grid (find cylinders corresponding to each agent)
Definition: HRICS_MultiAgentGrid.cpp:171
void computeAccessibility(unsigned int index_agent)
test if there is a collision with a BB (the cylinders) for the agent referenced in the the MultiAgent...
Definition: HRICS_MultiAgentGrid.cpp:2270
bool computeBestRobotPos()
compute best robot pos
void setFrontierSearchMaxIt(unsigned int v)
set the computational cost limit in # of iterations for the frontier search algorithm.
Definition: HRICS_MultiAgentGrid.hpp:308
double distance
distance of this cell from initial position of agent (shortest)
Definition: HRICS_MultiAgentGrid.hpp:553
void addFrontier(unsigned int agent, unsigned int other, MultiAgentCell *cell)
add a frontier cell to the agent 'agent'
Definition: HRICS_MultiAgentGrid.cpp:1901
bool distanceIsComputed
whether the distance have been computed or is unknown false either means that it is unreachable (inf ...
Definition: HRICS_MultiAgentGrid.hpp:550
Definition: HRICS_MultiAgentGrid.hpp:121
void setCellsToblankCost()
call setBlankCost() in each cell
Definition: HRICS_MultiAgentGrid.cpp:697
std::vector< MultiAgentCell * > getAltTraj(unsigned int agent, MultiAgentCell *alt_origin, bool reverse=false)
returns the shortest path FROM alt_origin TO this except if reverse is set to true, its the other way around
Definition: HRICS_MultiAgentGrid.cpp:2102
std::vector< MultiAgentCell * > traj
the shortest path to come to this cell from starting position
Definition: HRICS_MultiAgentGrid.hpp:534
API::TwoDCell * createNewCell(unsigned int index, unsigned int x, unsigned int y)
function that creates a new Cell.
Definition: HRICS_MultiAgentGrid.cpp:392
FrontierPtr createRealFrontierFor(unsigned int a1, unsigned int a2, MetaFrontierPtr mfrontier)
creates and set a real frontier as a specialization of the given MetaFrontier, for agents a1 and a2 r...
Definition: HRICS_MultiAgentGrid.cpp:2210
bool select_reverse
used as flag/argument for functions, to use symetric/direct direction or reverse direction ...
Definition: HRICS_MultiAgentGrid.hpp:891
Robot * getCylinder()
the cylinder for collision computation.
Definition: HRICS_MultiAgentGrid.hpp:87
std::vector< MultiAgentCell * > & reachable()
the list of cells where the agent can go, reachable space, it's included in accessible.
Definition: HRICS_MultiAgentGrid.hpp:96
unsigned int getFrontierIndex(unsigned int i, unsigned int j)
computes the index int the frontier vector corresponding to the frontiers between agents at i and j...
Definition: HRICS_MultiAgentGrid.cpp:1834
double computeCost()
compute move cost for an agent, according to it's speed.
void resetAllAccessibility()
call resetReacheability() in each cell
Definition: HRICS_MultiAgentGrid.cpp:724
void setFrontierSearchStopDist(double v)
set at which distance the frontier search should stop.
Definition: HRICS_MultiAgentGrid.hpp:316
double getHandOverReach(unsigned int i, unsigned int j)
an approximation of the maximal distance for a handover (touching hands) The sum of the arm reachs of...
Definition: HRICS_MultiAgentGrid.cpp:1897
std::vector< MultiAgentCell * > & frontiers(AgentInGrid *other)
the cells that are frontiers for the agent with other agents
Definition: HRICS_MultiAgentGrid.hpp:100
void computeAccessibility(void)
compute the Accessibility for each agent.
void resetTraj()
reset the Trajectories computing
Definition: HRICS_MultiAgentGrid.cpp:2419
API::Trajectory * r_trajB
idem, in the handover from B to A
Definition: HRICS_MultiAgentGrid.hpp:886
Plannar HRI Grid considering multiple agents systems for HRi operations.
Definition: HRICS_MultiAgentGrid.hpp:28
This class holds a the robot represented by a kinematic chain.
Definition: robot.hpp:42
std::vector< MultiAgentCell * > computeOtherTrajectory(MultiAgentCell *cell_origin, MultiAgentCell *cell_dest, unsigned int agent_index, double epsilon=1, double dist_max=-1, int max_expansions=-1)
computeOtherTrajectory uses A* algo to find shortest path between 2 cells.
Definition: HRICS_MultiAgentGrid.cpp:843
Definition: TwoDCell.hpp:19
AgentInCell * getAgentAt(unsigned int i)
getAgentAt
Definition: HRICS_MultiAgentGrid.hpp:597
bool isHuman()
whether it's a human or not.
Definition: HRICS_MultiAgentGrid.hpp:103
void initVectorFrontiers(void)
inits the frontier container to the good size.
Definition: HRICS_MultiAgentGrid.cpp:1823
void resetAccessibility()
reset the reacheability computing for all agents
Definition: HRICS_MultiAgentGrid.cpp:2393
std::tr1::shared_ptr< Configuration > object_position
a position of the object where it may be reachable by the two agents (when from A to B or symetric) ...
Definition: HRICS_MultiAgentGrid.hpp:880
bool isAccessible()
true if the Agent (its cylinder) can fit in this cell, not if it actually can go there ...
Definition: HRICS_MultiAgentGrid.hpp:536
structure defining the data for an agent in a cell
Definition: HRICS_MultiAgentGrid.hpp:529
bool isReachabilityComputed()
check if the meta agent is correctly set, if it is, return reachability computation status...
Definition: HRICS_MultiAgentGrid.hpp:545
void initAllCellState()
call resetexplorationstatus() in each cell
Definition: HRICS_MultiAgentGrid.cpp:708
std::vector< MultiAgentCell * > getNeighbors(unsigned int index)
find the direct neighbors of this cell (used when computing distance propagation) ...
Definition: HRICS_MultiAgentGrid.cpp:2313
std::pair< MultiAgentCell *, MultiAgentCell * > neighborSolution(unsigned int agent_1, unsigned int agent_2, std::pair< MultiAgentCell *, MultiAgentCell * > solution)
find a neighhbour solution for the simulated annealing algorithm.
Definition: HRICS_MultiAgentGrid.cpp:1196
bool areCellsInNeighbourhood(MultiAgentCell *c1, MultiAgentCell *c2, unsigned int a, double dist)
check if the agent 'a' can go straight from one cell to another
Definition: HRICS_MultiAgentGrid.cpp:954
std::vector< FrontierPtr > searchFrontiers(unsigned int agent_1, unsigned int agent_2, double keep_distance)
searchFrontiers
Definition: HRICS_MultiAgentGrid.cpp:1235
This file implements macros to help with the logging, in a way similar to ROS, using log4cxx...
void resetData(void)
reset data as for a new cell, set agents list according to the grid ones.
Definition: HRICS_MultiAgentGrid.cpp:2025
bool isDistanceComputed()
whether the distances (reachability) have been computed or not.
Definition: HRICS_MultiAgentGrid.hpp:106
bool isBoundary(void)
true if this cell is a boundary for this agent, i.e.
Definition: HRICS_MultiAgentGrid.hpp:562
Definition: TwoDGrid.hpp:25
void draw()
drawing the grid
Definition: HRICS_MultiAgentGrid.cpp:421
API::Trajectory * trajB
owned by this, deleted when this is deleted
Definition: HRICS_MultiAgentGrid.hpp:885
void initAllTrajs()
call resetTrajs() in each cell
Definition: HRICS_MultiAgentGrid.cpp:716
void initCylinders(void)
init agents cylinders for reachability computation.
Definition: HRICS_MultiAgentGrid.cpp:353
double getSpeed(void)
for cost computation.
Definition: HRICS_MultiAgentGrid.hpp:104
bool isAccessibilityComputed()
whether the accessibility have been computed or is unknown
Definition: HRICS_MultiAgentGrid.hpp:537
AgentInGrid * agentInGrid
pointer to the AgentInGrid structure in the Grid
Definition: HRICS_MultiAgentGrid.hpp:531
Definition: HRICS_MultiAgentGrid.hpp:468
Definition: trajectory.hpp:40
std::deque< double > distance_alternatives
distances of this cell from cell origin_alternatives (others online defined cells) ...
Definition: HRICS_MultiAgentGrid.hpp:554
Plannar HRI Cell.
Definition: HRICS_MultiAgentGrid.hpp:462
void computeDistances()
using the method of distance propagation to compute distances.
Definition: HRICS_MultiAgentGrid.cpp:748
std::vector< MultiAgentCell * > & boundaries()
a subset of reachable where all cells are near an obstacle (have a not accesscible neighbour) ...
Definition: HRICS_MultiAgentGrid.hpp:98
void setAgents(std::vector< Robot * > &agents)
set the agents list to use in this HRI computation.
Definition: HRICS_MultiAgentGrid.cpp:192
FrontierPtr neighbourFrontier(double keep_distance, double min_distance=0)
create or find a similar frontier, changing positions of agents
Definition: HRICS_MultiAgentGrid.cpp:2487
double getDistanceAny(unsigned int agent, MultiAgentCell *other)
get distance either using getDistance or getAltDistance, on this or other according to the origins se...
Definition: HRICS_MultiAgentGrid.cpp:2127
Robot * getRobot()
pointer to the robot.
Definition: HRICS_MultiAgentGrid.hpp:85
Definition: HRICS_MultiAgentGrid.hpp:857
bool isReachable()
check if the meta agent is correctly set, if it is, return reachability status, false otherwise meta ...
Definition: HRICS_MultiAgentGrid.hpp:543
double getMaxDist()
the maximum distance the agent can cover (for display purpose, computed during distance computation)...
Definition: HRICS_MultiAgentGrid.hpp:88
FrontierCells::FrontierCheckStatus r_check_status
the results of the tests are in object_ok, grab_confs_ok, handover_ok
Definition: HRICS_MultiAgentGrid.hpp:874
Holds all the data concerning an agent in the MultiAgentGrid class.
Definition: HRICS_MultiAgentGrid.hpp:83
void setReachability(bool b)
set the reachability of the corresponging meta agent, ABORT otherwise
Definition: HRICS_MultiAgentGrid.hpp:547
void addPoint(double Rz)
add a point to the random vector in order to draw it (the red arrows)
FrontierPtr getRealFrontier(unsigned int a1, unsigned int a2, MetaFrontierPtr mfrontier)
returns the real Frontier that is a specification of the MetaFrontier mfrontier returns empty ptr if ...
Definition: HRICS_MultiAgentGrid.cpp:2259
std::pair< unsigned int, unsigned int > getFrontierAgentIndices(unsigned int i)
the reverse of getFrontierIndex().
Definition: HRICS_MultiAgentGrid.cpp:1843
std::vector< MultiAgentCell * > getCrown(double min, double max)
return the crown arround the cell taking the min and max value
void deSymetrize()
use this when the frontiers diverge according to its direction it duplicates data to their "reverse" ...
Definition: HRICS_MultiAgentGrid.cpp:2613
std::vector< std::tr1::shared_ptr< FrontierCells > > createAllRealFrontiersFor(unsigned int a1, unsigned int a2)
calls createRealFrontierFor(a1,a2,meta) for each meta frontier in which a1 and a2 are concerned ...
Definition: HRICS_MultiAgentGrid.cpp:2199
double computeDist(MultiAgentCell *neighCell)
compute distance between two cells
Definition: HRICS_MultiAgentGrid.cpp:2388
HRI_AGENT * getHriAgent()
return hri_agent related to the robot if possible
Definition: robot.cpp:107
std::tr1::shared_ptr< Configuration > r_object_position
a position of the object where it may be reachable by the two agents (when from B to A) ...
Definition: HRICS_MultiAgentGrid.hpp:881
bool checkMetaAgent(unsigned int index)
return true if meta agent is OK, false if it have been changed
Definition: HRICS_MultiAgentGrid.cpp:1981