Go to the documentation of this file.00001
00012 #ifndef LGL_PURSUIT_GRAPH_HPP
00013 #define LGL_PURSUIT_GRAPH_HPP
00014
00015 #include <lgl/VisibilityMap.hpp>
00016 #include <lgl/PursuitGNode.hpp>
00017 #include <lgl/PursuitNavigator.hpp>
00018 #include <lgl/CellID.hpp>
00019
00020 #include <vector>
00021
00022 #include <boost/shared_ptr.hpp>
00023 #include <boost/weak_ptr.hpp>
00024
00025 #ifndef DEFAULT_PURSUIT_TEMPORAL_TOLERANCE
00026 #define DEFAULT_PURSUIT_TEMPORAL_TOLERANCE 15
00027 #endif
00028
00029 #ifndef DEFAULT_RISK_TERM_MAX_VALUE
00030 #define DEFAULT_RISK_TERM_MAX_VALUE 15
00031 #endif
00032
00033 namespace jafar {
00034 namespace lgl {
00035
00037 struct tr1Node
00038 {
00039 RISK_LEVEL b ;
00040 Cell_ID r;
00041 Cell_ID t;
00042 unsigned int rt;
00043
00044 bool operator< (const tr1Node &rhs) const
00045 {
00046 if ( b!=rhs.b ) return ( b < rhs.b ) ;
00047 if ( r!=rhs.r ) return ( r < rhs.r ) ;
00048 if ( t!=rhs.t ) return ( t < rhs.t ) ;
00049 if ( rt!=rhs.rt ) return ( rt < rhs.rt) ;
00050
00051 return (false);
00052 }
00053
00054 bool operator== (const tr1Node &rhs) const
00055 {
00056 if ( b==rhs.b && r==rhs.r && t==rhs.t && rt==rhs.rt ) return true ;
00057 return false;
00058 }
00059 };
00060
00061 struct tr2Node
00062 {
00063 RISK_LEVEL b ;
00064 Cell_ID r;
00065 unsigned int rt;
00066 std::vector < boost::shared_ptr< PursuitGNode> > p;
00067
00068 bool operator< (const tr2Node &rhs) const
00069 {
00070 if ( b!=rhs.b ) return ( b < rhs.b ) ;
00071 if ( r!=rhs.r ) return ( r < rhs.r ) ;
00072 if ( rt!=rhs.rt ) return ( rt < rhs.rt ) ;
00073 if ( p!=rhs.p ) return ( p < rhs.p ) ;
00074
00075 return (false);
00076 }
00077
00078 bool operator== (const tr2Node &rhs) const
00079 {
00080 if ( b==rhs.b && r==rhs.r && rt==rhs.rt && p==rhs.p ) return true ;
00081 return false;
00082 }
00083 };
00084
00085
00092 class PursuitGraph {
00094
00095 private :
00096
00097
00098 PursuitNavigator* navigator ;
00099
00100
00101 VisibilityMap *visibilityMap;
00102
00103
00104
00105 unsigned int ysize ;
00106 unsigned int xsize ;
00107
00108
00109 boost::shared_ptr<PursuitGNode> root;
00110
00111
00112 std::vector< boost::weak_ptr<PursuitGNode> > risk;
00113 std::vector< boost::weak_ptr<PursuitGNode> > danger;
00114 std::vector< boost::weak_ptr<PursuitGNode> > front;
00115
00116
00117 std::set< boost::shared_ptr<PursuitGNode> > setOfNodes;
00118
00119
00120
00121
00122 std::multimap< Cell_ID, boost::weak_ptr<PursuitGNode> > nodeMap;
00123
00124
00125
00126 unsigned int horizon ;
00127
00128
00129 unsigned long int time ;
00130
00131
00132
00133 unsigned int pursuitTemporalTolerance;
00134
00135
00136
00137 unsigned int riskTermMaxValue ;
00138
00139
00140 double d_est ;
00141
00142 public :
00143
00145 PursuitGraph( PursuitNavigator &_navigator,
00146 VisibilityMap & _visibilityMap,
00147 unsigned int _pursuitTemporalTolerance = DEFAULT_PURSUIT_TEMPORAL_TOLERANCE,
00148 unsigned int _riskTermMaxValue = DEFAULT_RISK_TERM_MAX_VALUE
00149 ) :
00150 navigator(&_navigator),
00151 visibilityMap(&_visibilityMap),
00152 horizon(0),
00153 time(0),
00154 pursuitTemporalTolerance(_pursuitTemporalTolerance),
00155 riskTermMaxValue (_riskTermMaxValue)
00156 {
00157 ysize = visibilityMap->getysize();
00158 xsize = visibilityMap->getxsize();
00159
00160
00161 }
00162
00164 ~PursuitGraph() {}
00165
00171 void computeAll ( Cell_ID cellR, Cell_ID cellT, const unsigned int _horizon = 10 );
00172 void computeAll ( int xR, int yR, int xT, int yT, const unsigned int _horizon = 10 );
00173
00179 void computeAllBefore ( Cell_ID cellR, Cell_ID cellT, const double tMax = 5000.0 );
00180 void computeAllBefore ( int xR, int yR, int xT, int yT, const double tMax = 5000.0 );
00181
00182
00183
00184
00185
00186
00187
00188
00189 bool updatePG( Cell_ID newtargetPos, Cell_ID &newrobotPos);
00190 bool updatePG( int xT, int yT, int &xR, int &yR );
00191
00192
00193 void completeToHorizon();
00194 void completeToHorizonBefore( const double &tMax );
00195
00196
00197
00198 unsigned int gethorizon() const ;
00199
00200 const std::vector< boost::weak_ptr<PursuitGNode> > & getrisk() const ;
00201 const std::vector< boost::weak_ptr<PursuitGNode> > & getdanger() const ;
00202 const std::vector< boost::weak_ptr<PursuitGNode> > & getfront() const ;
00203
00204 const std::set< boost::shared_ptr<PursuitGNode> > & getsetOfNodes() const ;
00205
00206 const std::multimap< Cell_ID, boost::weak_ptr<PursuitGNode> > & getnodeMap() const ;
00207
00208 const boost::shared_ptr<PursuitGNode> & getroot() const ;
00209
00210 PursuitNavigator* getnavigator();
00211
00212 unsigned int getysize() const;
00213 unsigned int getxsize() const;
00214
00215 unsigned long int gettime() const;
00216
00217 void disp() ;
00218 void disp_risk() ;
00219 void disp_danger() ;
00220
00221 private :
00222
00227 void computeAll ( const boost::shared_ptr <PursuitGNode> &_root, const unsigned int _horizon = 10 );
00228
00233 void computeAllBefore ( const boost::shared_ptr <PursuitGNode> &_root, const double tMax = 5.0 );
00234
00235
00237 void setRoot() ;
00238
00240 void computeNewStage();
00241
00243 void clean() ;
00244
00248
00249 void reorient() ;
00250
00251
00252
00253 void makeNewNodes( std::vector< boost::shared_ptr < PursuitGNode > > &newNodes,
00254 const unsigned int &riskTerm,
00255 const Cell_ID &robotPos,
00256 const std::set< Cell_ID > &robotAccess,
00257 const std::set< Cell_ID > &targetAccess
00258 );
00259
00260
00261
00262
00263 void completeStage( unsigned long int stage) ;
00264
00265
00266 void manageRisk( const Cell_ID &robotPos,
00267 const boost::shared_ptr<PursuitGNode> &risk,
00268 std::vector< boost::shared_ptr< PursuitGNode > > &solution
00269 );
00270
00271
00272
00273 void findIdealPositions( const std::set<Cell_ID> &targetPos, std::set<Cell_ID> &positions);
00274
00275
00276
00277 void findAnyPositions( const std::set<Cell_ID> &targetPos, std::set<Cell_ID> &positions);
00278
00279
00280
00281
00282
00283 RISK_LEVEL computeRiskLevel(const Cell_ID &robotPos, const Cell_ID &targetPos);
00284
00285 };
00286
00287 }
00288 }
00289
00290 #endif