6 #ifndef JPS_GRAPH_SEARCH_H 7 #define JPS_GRAPH_SEARCH_H 9 #include <boost/heap/d_ary_heap.hpp> 13 #include <unordered_map> 21 bool operator()(T a1, T a2)
const 23 double f1 = a1->g + a1->h;
24 double f2 = a2->g + a2->h;
25 if( ( f1 >= f2 - 0.000001) && (f1 <= f2 +0.000001) )
35 using StatePtr = std::shared_ptr<State>;
36 using priorityQueue = boost::heap::d_ary_heap<StatePtr, boost::heap::mutable_<true>,
37 boost::heap::arity<2>, boost::heap::compare< compare_state<StatePtr> >>;
55 double g = std::numeric_limits<double>::infinity();
64 State(
int id,
int x,
int y,
int dx,
int dy )
65 : id(id), x(x), y(y), dx(dx), dy(dy)
69 State(
int id,
int x,
int y,
int z,
int dx,
int dy,
int dz )
70 : id(id), x(x), y(y), z(z), dx(dx), dy(dy), dz(dz)
94 static constexpr
int nsz[3][2] = {{8, 0}, {1, 2}, {3, 2}};
99 void Neib(
int dx,
int dy,
int norm1,
int dev,
int& tx,
int& ty);
100 void FNeib(
int dx,
int dy,
int norm1,
int dev,
101 int& fx,
int& fy,
int& nx,
int& ny);
127 static constexpr
int nsz[4][2] = {{26, 0}, {1, 8}, {3, 12}, {7, 12}};
130 void Neib(
int dx,
int dy,
int dz,
int norm1,
int dev,
int& tx,
int& ty,
int& tz);
131 void FNeib(
int dx,
int dy,
int dz,
int norm1,
int dev,
132 int& fx,
int& fy,
int& fz,
133 int& nx,
int& ny,
int& nz);
154 GraphSearch(
const char* cMap,
int xDim,
int yDim,
double eps = 1,
bool verbose =
false);
165 GraphSearch(
const char* cMap,
int xDim,
int yDim,
int zDim,
double eps = 1,
bool verbose =
false);
177 bool plan(
int xStart,
int yStart,
int xGoal,
int yGoal,
bool useJps,
int maxExpand = -1);
190 bool plan(
int xStart,
int yStart,
int zStart,
int xGoal,
int yGoal,
int zGoal,
bool useJps,
int maxExpand = -1);
193 std::vector<StatePtr> getPath()
const;
196 std::vector<StatePtr> getOpenSet()
const;
199 std::vector<StatePtr> getCloseSet()
const;
202 std::vector<StatePtr> getAllSet()
const;
206 bool plan(StatePtr& currNode_ptr,
int max_expand,
int start_id,
int goal_id);
208 void getSucc(
const StatePtr& curr, std::vector<int>& succ_ids, std::vector<double>& succ_costs);
210 void getJpsSucc(
const StatePtr& curr, std::vector<int>& succ_ids, std::vector<double>& succ_costs);
212 std::vector<StatePtr> recoverPath(StatePtr node,
int id);
215 int coordToId(
int x,
int y)
const;
217 int coordToId(
int x,
int y,
int z)
const;
220 bool isFree(
int x,
int y)
const;
222 bool isFree(
int x,
int y,
int z)
const;
225 bool isOccupied(
int x,
int y)
const;
227 bool isOccupied(
int x,
int y,
int z)
const;
230 double getHeur(
int x,
int y)
const;
232 double getHeur(
int x,
int y,
int z)
const;
235 bool hasForced(
int x,
int y,
int dx,
int dy);
237 bool hasForced(
int x,
int y,
int z,
int dx,
int dy,
int dz);
240 bool jump(
int x,
int y,
int dx,
int dy,
int& new_x,
int& new_y);
242 bool jump(
int x,
int y,
int z,
int dx,
int dy,
int dz,
int& new_x,
int& new_y,
int& new_z);
248 int xDim_, yDim_, zDim_;
252 const char val_free_ = 0;
253 int xGoal_, yGoal_, zGoal_;
255 bool use_jps_ =
false;
258 std::vector<StatePtr> hm_;
259 std::vector<bool> seen_;
261 std::vector<StatePtr> path_;
263 std::vector<std::vector<int>> ns_;
264 std::shared_ptr<JPS2DNeib> jn2d_;
265 std::shared_ptr<JPS3DNeib> jn3d_;
double h
heuristic cost
Definition: graph_search.h:57
Definition: map_util.h:11
State(int id, int x, int y, int dx, int dy)
2D constructor
Definition: graph_search.h:64
int x
Coord.
Definition: graph_search.h:45
Search and prune neighbors for JPS 2D.
Definition: graph_search.h:76
int dx
direction
Definition: graph_search.h:47
Search and prune neighbors for JPS 3D.
Definition: graph_search.h:106
Heap element comparison.
Definition: graph_search.h:19
int id
ID.
Definition: graph_search.h:43
priorityQueue::handle_type heapkey
pointer to heap location
Definition: graph_search.h:52
GraphSearch class.
Definition: graph_search.h:142
State(int id, int x, int y, int z, int dx, int dy, int dz)
3D constructor
Definition: graph_search.h:69
Node of the graph in graph search.
Definition: graph_search.h:40