ExplorationGraphProva.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00026 
00030 
00034 
00036 /* @{ */
00037 
00038 #ifndef _EXPLORATION_GRAPH_H_
00039 #define _EXPLORATION_GRAPH_H_
00040 
00041 #include <Grid.h>
00042 using namespace std;
00043 
00044 enum CellComparisonSurvey{
00045  OBST_VS_OBST,//ok
00046  OBST_VS_FRONT,//conflict
00047  OBST_VS_UKWN,//ok
00048  OBST_VS_LSR,//conflict
00049  FRONT_VS_OBST,//conflict
00050  FRONT_VS_FRONT,//ok
00051  FRONT_VS_UKWN,//ok
00052  FRONT_VS_LSR,//ok
00053  UKWN_VS_OBST,//ok
00054  UKWN_VS_FRONT,//ok
00055  UKWN_VS_UKWN,//ok
00056  UKWN_VS_LSR,//ok
00057  LSR_VS_OBST,//conflict
00058  LSR_VS_FRONT,//ok
00059  LSR_VS_UKWN,//ok
00060  LSR_VS_LSR,//ok
00061  CELL_COMPARISON_SURVEY_NUM
00062 };
00063 
00064 static const char* CellComparisonSurveyName[CELL_COMPARISON_SURVEY_NUM] ={
00065  "Obstacle vs  Obstacle",
00066  "Obstacle vs Frontier",
00067  "Obstacle vs Unknown",
00068  "Obstacle vs LSR",
00069  "Frontier vs  Obstacle",
00070  "Frontier vs Frontier",
00071  "Frontier vs Unknown",
00072  "Frontier vs LSR",
00073  "Unknown vs  Obstacle",
00074  "Unknown vs Frontier",
00075  "Unknown vs Unknown",
00076  "Unknown vs LSR",
00077  "LSR vs  Obstacle",
00078  "LSR vs Frontier",
00079  "LSR vs Unknown",
00080  "LSR vs LSR",
00081 };
00082 
00084 int evalCoeff(Cell* cell);
00085 
00093 class ExplorationNode{
00094  private:
00095   int _ID;         
00096   Scan _scan;        
00097   Grid _grid;        
00098   vector<int> _adjacency;  
00099   vector<Decimal> _weight; 
00100   Time _nodeTime;
00101   
00102   
00103  public:
00104   ExplorationNode(Scan scan, int ID, ExplorationParams params, Time nodeTime, Pose gridCenter);
00105 /***************************************************************************************************
00106 ***********************************        SET FUNCTIONS         ***********************************
00107 ***************************************************************************************************/
00109   void setID(int value){
00110    _ID=value;
00111   }
00112 
00114   void setScan(Scan value){
00115    _scan=value;
00116   }
00117   
00119   void setGrid(Grid value){
00120    _grid=value;
00121   }
00122   
00124   void setAdjacency(vector<int> value){
00125    _adjacency=value;
00126   }
00127   
00129   void setWeight(vector<Decimal> value){
00130    _weight=value;
00131   }
00132   
00134   void setNodeTime(Time value){
00135    _nodeTime=value;
00136   }
00137 
00138 /***************************************************************************************************
00139 ***********************************        GET FUNCTIONS         ***********************************
00140 ***************************************************************************************************/
00142   int ID(){
00143    return _ID;
00144   }
00145 
00147   Scan scan(){
00148    return _scan;
00149   }
00150   
00152   Grid grid(){
00153    return _grid;
00154   }
00155   
00157   Grid* gridPtr(){
00158    return &_grid;
00159   }
00160   
00162   vector<int> adjacency(){
00163    return _adjacency;
00164   }
00165   
00167   vector<Decimal> weight(){
00168    return _weight;
00169   }
00170   
00172   Time nodeTime(){
00173    return _nodeTime;
00174   }
00175 };
00176 
00177 
00178 
00186 class ExplorationGraph{
00187  private:
00188  public:
00189   vector<ExplorationNode> _graph;  
00190   ExplorationParams _params;    
00191   Timer _graphTimer;        
00192   Decimal _adjacTh;         
00193   vector<int> _Amatrix;       
00194   vector<Decimal> _Wmatrix;     
00195   Pose _nextVP;
00196   
00197   pthread_mutex_t mutex;
00199   void graphAccess() { pthread_mutex_lock(&mutex);}
00200 
00201   void graphRelease(){ pthread_mutex_unlock(&mutex);}
00202   
00206   bool isAdjacent(ExplorationNode first,ExplorationNode second);
00207 
00211   ExplorationNode getNode(int ID);
00212   
00213 
00217   Time getNodeLastUpd(int ID);
00218   
00222   void updateAdj(ExplorationNode first,ExplorationNode second);
00223 
00224 
00228   void addNode(Scan scan);
00229   
00233   void setNextVP(Pose nextVP){
00234    _nextVP=nextVP;
00235   }
00236   
00237 //  public:
00239   ExplorationGraph(){}
00241   ExplorationGraph(ExplorationParams params);
00243   ExplorationGraph(ExplorationParams params,Decimal adjacTh);
00244 
00246   ~ExplorationGraph();
00247 
00249   ExplorationGraph(const ExplorationGraph &g);
00250   
00252   ExplorationGraph operator=(const ExplorationGraph &g){
00253    if (this != &g){
00254     _graph=g._graph;
00255     _params=g._params;
00256     _graphTimer=g._graphTimer;
00257     _adjacTh=g._adjacTh;
00258     _Amatrix=g._Amatrix;
00259     _Wmatrix=g._Wmatrix;
00260    }
00261    return *this;
00262   }
00263   
00268   Decimal nodeDist(ExplorationNode first,ExplorationNode second);
00269   
00272   void compA();
00273   
00276   void compW();
00277   
00278 };
00279 
00280 #endif
00281 
00282 
00283       /*************************************************************/
00284       /*               Functions for path search                   */
00285       /*************************************************************/ 
00286 
00294 //       Solution Homing(NodeMatrix sd, Solution Back, int numRobot);
00295 
00296 
00297       /*************************************************************/
00298       /*        Functions for Computing the Forward Trees          */
00299       /*************************************************************/
00300 
00301 // /*inline*/ double* FloydAPSP();
00302 
00303 
00304   
00305 /*************************************************************/
00306 /*        Functions for Computing the Forward Trees          */
00307 /*************************************************************/
00308 
00309 
00311 //  double* FloydAPSP(ListNode* ListOfNodesToExclude){}
00312 
00313 
00314  /*************************************************************/
00315  /*               Functions for path search                   */
00316  /*************************************************************/ 
00317 
00318 
00319 
00325 //                NM AdiacentNodes(IdNode nod);
00326 
00333 //                GraphPath AStar(IdNode start, IdNode dest);
00334   
00340 //                bool ConflictChecking(Solution Sol);
00341   
00347 //                IntMatrix Constraints(Solution Sol);
00348     
00356 //                GraphPath Astar_tempo(Solution Par, IdNode s, IdNode d);
00357   
00365 //                Solution Replanning(int* priority, Solution ott, NodeMatrix sd);
00366   
00373 //                void PriorityChooser(int* prty, IntMatrix vincoli, int numRobot);  
00374   
00381 //                void PriorityChooser(IntMatrix vincoli,int*pr, int numRobot);   
00382                
00383 
00389 //                double SolutionCost(Solution Sol);
00390 
00391 
00392 
00393 
00394 
00395 /***************************************************/
00396 /*                  Utility funcion                */
00397 /***************************************************/
00402 //                void PrintLGraph(int robot);//TODO
00403 
00408 //                void PrintLNodeWeights(int robot);//TODO
00409 
00414 //     void WriteGraph(string nomefile);//TODO
00415 
00420 //     void ReadGraph(string nomefile);//TODO
00421     
00426 //                void Write(string nomefile);
00427 
00432 //                void Read(string nomefile);
00433     
00434     
00435     vector<Cell*> bresenhamCircle(ExplorationNode node, Cell* start, Cell* stop, Cell* center){
00436      vector<Cell*> bres;
00437  
00438      int iStart=start->indexes().i();
00439      int jStart=start->indexes().j();
00440      int iStop=stop->indexes().i();
00441      int jStop=stop->indexes().j();
00442      int iCenter=center->indexes().i();
00443      int jCenter=center->indexes().j();
00444 
00445      int Di1 = iStart-iCenter;
00446      int Dj1 = jStart-jCenter;
00447      int Di2 = iStop-iCenter;
00448      int Dj2 = jStop-jCenter;
00449  
00450      bool mSign1=((Di1<=0)^((Dj1<=0)));
00451      bool mMod1=(abs(Di1)<=abs(Dj1));
00452      bool increasing1;
00453      if (mMod1){
00454       increasing1=(Dj1>=0);
00455      }
00456      else{
00457       increasing1=(Di1>=0);
00458      }
00459  
00460      int octant1=4*increasing1+2*mMod1+mSign1;
00461  
00462      bool mSign2=((Di2<=0)^((Dj2<=0)));
00463      bool mMod2=(abs(Di2)<=abs(Dj2));
00464      bool increasing2;
00465      if (mMod2){
00466       increasing2=(Dj2>=0);
00467      }
00468      else{
00469       increasing2=(Di2>=0);
00470      }
00471      int octant2=4*increasing2+2*mMod2+mSign2;
00472  
00473  
00474 
00475      int j = jStart;
00476      int i = iStart;
00477 
00478  
00479  
00480      int leadIndex;
00481      int followIndex;
00482      int leadVariation;
00483      int followVariation;
00484      int currLead;
00485      int currFollow;
00486      int Dlead;
00487      int Dfollow;
00488      int leadArrival;
00489  
00490      int radius = (int)sqrt(Di1*Di1+Dj1*Dj1);
00491      int d= 1-radius;
00492      int deltaE;
00493      int deltaSE;
00494 //  int index=jStart-1+((iStart-1)*columns());
00495  
00496 //  bres.push_back(octant);
00497      bres.push_back(start);
00498 
00499  
00500  
00501  
00502      deltaE = 3;
00503      deltaSE = -2*radius+5;
00504 //  CirclePoints(x, y, value);
00505      while ( j != jStop ) {
00506       if ( d < 0 ) {
00507        d = d+deltaE;
00508        deltaE = deltaE+2;
00509        deltaSE = deltaSE+2;
00510        j++;
00511       } else {
00512        d = d+deltaSE;
00513        deltaE = deltaE+2;
00514        deltaSE = deltaSE+4;
00515        j++;
00516        i--;
00517       }
00518       int index=j-1+((i-1)*node.grid().columns());
00519       bres.push_back(node.grid().getCell(index));
00520 //   CirclePoints(x, y, value);
00521      }
00522     }
00523     
00524     
00525     
00526     
00527     
00528     

Generated on Mon Feb 20 07:01:06 2017 for MIP by  doxygen 1.5.6