00001
00013 #ifndef LGL_PURSUIT_NAVIGATOR_HPP
00014 #define LGL_PURSUIT_NAVIGATOR_HPP
00015
00016 #include <lgl/GeoData.hpp>
00017 #include <lgl/CellID.hpp>
00018
00019 #include <string>
00020 #include <set>
00021 #include <vector>
00022 #include <list>
00023 #include <queue>
00024
00025 #include <boost/shared_ptr.hpp>
00026
00027 namespace jafar {
00028 namespace lgl {
00029
00030
00031 class pNavPos
00032 {
00033
00034 public :
00035 int x ;
00036 int y ;
00037
00038 double g ;
00039 double h ;
00040
00041 unsigned int t ;
00042
00043 std::list< boost::shared_ptr< pNavPos> > prev;
00044
00045 pNavPos(int _x, int _y, double _g, double _h, unsigned int _t) :
00046 x (_x),
00047 y (_y),
00048 g (_g),
00049 h (_h),
00050 t (_t)
00051 { }
00052
00053 pNavPos(int _x, int _y, double _g, double _h, unsigned int _t, boost::shared_ptr< pNavPos > &_prev) :
00054 x (_x),
00055 y (_y),
00056 g (_g),
00057 h (_h),
00058 t (_t)
00059 { prev.push_back(_prev) ; }
00060
00061 bool operator< (const pNavPos &rhs) const
00062 {
00063
00064 return ( g < rhs.g );
00065 }
00066
00067 bool operator> (const pNavPos &rhs) const
00068 {
00069
00070 return ( (g+h) > (rhs.g + rhs.h));
00071 }
00072
00073 };
00074
00075
00076 template <typename Pointer> struct ptr_less
00077 {
00078 bool operator()( const Pointer & lhs, const Pointer & rhs)
00079 {
00080 return (*lhs < *rhs) ;
00081 }
00082 };
00083 template <typename Pointer> struct ptr_greater
00084 {
00085 bool operator()( const Pointer & lhs, const Pointer & rhs)
00086 {
00087 return (*lhs > *rhs) ;
00088 }
00089 };
00090
00091 struct ptr_cmp
00092 {
00093 bool operator()( const boost::shared_ptr< pNavPos > & lhs, const boost::shared_ptr< pNavPos > & rhs)
00094 {
00095 return ( (lhs->x < rhs->x) || (lhs->x == rhs->x && lhs->y < rhs->y ) );
00096 }
00097 };
00098
00099
00100
00106 class PursuitNavigator {
00108
00109 private :
00110
00111
00112
00113
00114
00115 GeoData* robGeoData ;
00116 GeoData* tarGeoData ;
00117
00118
00119
00120 unsigned int ysize ;
00121 unsigned int xsize ;
00122
00123 public :
00124
00129 PursuitNavigator( const std::string &robotAccessMapPath, const std::string &targetAccessMapPath)
00130 {
00131 robGeoData = new GeoData (robotAccessMapPath );
00132 tarGeoData = new GeoData (targetAccessMapPath );
00133
00134 ysize = 2 * robGeoData->getysize() + 1 ;
00135 xsize = 2 * robGeoData->getxsize() + 1 ;
00136
00137 }
00138
00139 ~PursuitNavigator()
00140 {
00141 if ( robGeoData != NULL )
00142 delete robGeoData ;
00143
00144 if ( tarGeoData != NULL )
00145 delete tarGeoData ;
00146 }
00147
00148
00149
00150
00151 void findRobotAccessibility( const Cell_ID ¤tRobotPos, std::set<Cell_ID> &robotAccess);
00152
00153
00154
00155
00156 void findTargetAccessibility( const std::set<Cell_ID> ¤tTargetPos, std::set<Cell_ID> &targetAcess );
00157
00158
00159 double distCellID ( Cell_ID a, Cell_ID b) ;
00160
00161
00162 double distPos ( pNavPos A, pNavPos B ) ;
00163 double distPos ( int xA, int yA, int xB, int yB) ;
00164
00165
00166
00167
00168
00169
00170
00171
00172 bool navAStar ( Cell_ID start, Cell_ID goal, std::vector<Cell_ID> &Path);
00173 bool navAStar ( int xStart, int yStart, int xGoal, int yGoal, std::vector<Cell_ID> &Path);
00174
00175
00176
00177
00178
00179
00180
00181
00182 bool nav2Set ( Cell_ID start, const std::set< Cell_ID > &goals, std::vector<Cell_ID> &Path);
00183 bool nav2Set ( int xStart, int yStart, const std::set<Cell_ID> &goals, std::vector<Cell_ID> &Path);
00184
00185 bool nav2Set ( Cell_ID start, const std::set< Cell_ID > &goals, std::vector<Cell_ID> &Path, const unsigned int &pursuitTemporalTolerance);
00186
00187
00188
00189
00190 double heuristic(int xA, int yA, int xB, int yB) ;
00191
00192
00193
00194 void addNeighbours( boost::shared_ptr< pNavPos> &currPos,
00195 const int &xGoal, const int &yGoal,
00196 std::set< boost::shared_ptr<pNavPos>, ptr_cmp > &visitedPos,
00197 std::list< boost::shared_ptr<pNavPos> > &queue);
00198
00199
00200
00201 void addNeighbours_classic( boost::shared_ptr< pNavPos> &currPos,
00202 std::set< boost::shared_ptr<pNavPos>, ptr_cmp > &visitedPos,
00203 std::list< boost::shared_ptr<pNavPos> > &queue);
00204
00205
00206
00207 void findIdealPositions( const std::set<Cell_ID> &targetPos, std::set<Cell_ID> &positions);
00208
00209
00210 GeoData* getrobGeoData() ;
00211 GeoData* gettarGeoData() ;
00212
00213 unsigned int getysize() const;
00214 unsigned int getxsize() const;
00215
00216 };
00217
00218 }
00219 }
00220
00221 #endif