cb_base_navigation
a_star_planner.h
Go to the documentation of this file.
1 /*******************************
2  * *
3  * Author: Rein Appeldoorn *
4  * Date: 2013-03-06 *
5  * *
6  *******************************/
7 
8 #ifndef cb_global_planner_ASTARPLANNER_H_
9 #define cb_global_planner_ASTARPLANNER_H_
10 
11 #include <float.h> // for DBL_MAX
12 #include <math.h> // for sqrt
13 
14 #include <list>
15 #include <vector>
16 #include <queue>
17 #include <stdio.h>
18 #include <iostream>
19 
20 namespace cb_global_planner {
21 
22 class AStarPlanner {
23 
24 public:
25 
26  AStarPlanner(int width, int height);
27 
28  virtual ~AStarPlanner();
29 
30  //void setCost(int x, int y, double cost);
31 
32  void setCostmap(const unsigned char* char_cost_map);
33 
34  void resize(int nx, int ny);
35 
36  bool plan(std::vector<unsigned int> mx_start, std::vector<unsigned int> my_start, int mx_goal, int my_goal, std::vector<int>& plan_xs, std::vector<int>& plan_ys, bool best_heuristic = false);
37 
38 protected:
39 
40  static constexpr double SQRT2 = 1.414213562;
41 
42  static long N_OBJECTS;
43 
44  //double** cost_map_;
45 
46  const unsigned char* char_cost_map_;
47 
48  double** visited_map_;
49  unsigned int width_;
50  unsigned int height_;
51 
52  void deleteMap();
53 
54  double getCost(int x, int y);
55 
56  struct CellInfo {
57 
58  static long N_OBJECTS;
59 
60  int x_;
61  int y_;
62  double f_; // f = g + h
63  double g_; // g = cost so far
64  double h_; // h = predicted extra cost
65  CellInfo* visited_from_; // pointer to cell from which this cell is visited
66 
67  CellInfo(double x, double y, double g, double h) : x_(x), y_(y), g_(g), h_(h), visited_from_(nullptr) {
68  f_ = g_ + h_;
69  ++N_OBJECTS;
70  }
71 
74  }
75  };
76 
78  bool operator()(const CellInfo* c1, const CellInfo* c2) const {
79  return c1->f_ > c2->f_;
80  }
81  };
82 
83  void expandCell(CellInfo* c, int dx, int dy, double cost_factor, double** visited_map,
84  int x_goal, int y_goal, double min_cell_cost,
86 
87  double calculateHeuristicCost(int x, int y, int x_goal, int y_goal, double min_cell_cost);
88 
89 };
90 
91 }
92 
93 #endif /* cb_global_planner_ASTARPLANNER_H_ */
cb_global_planner::AStarPlanner::SQRT2
static constexpr double SQRT2
Definition: a_star_planner.h:50
cb_global_planner::AStarPlanner::CellInfo::y_
int y_
Definition: a_star_planner.h:71
cb_global_planner::AStarPlanner::CellInfo::h_
double h_
Definition: a_star_planner.h:74
list
cb_global_planner::AStarPlanner::calculateHeuristicCost
double calculateHeuristicCost(int x, int y, int x_goal, int y_goal, double min_cell_cost)
Definition: a_star_planner.cpp:193
cb_global_planner::AStarPlanner::compareCellInfos::operator()
bool operator()(const CellInfo *c1, const CellInfo *c2) const
Definition: a_star_planner.h:88
vector
cb_global_planner::AStarPlanner::CellInfo::f_
double f_
Definition: a_star_planner.h:72
cb_global_planner::AStarPlanner::width_
unsigned int width_
Definition: a_star_planner.h:59
cb_global_planner::AStarPlanner::~AStarPlanner
virtual ~AStarPlanner()
Definition: a_star_planner.cpp:16
queue
iostream
cb_global_planner::AStarPlanner::compareCellInfos
Definition: a_star_planner.h:87
cb_global_planner::AStarPlanner::resize
void resize(int nx, int ny)
Definition: a_star_planner.cpp:53
cb_global_planner::AStarPlanner::CellInfo::~CellInfo
~CellInfo()
Definition: a_star_planner.h:82
cb_global_planner::AStarPlanner::CellInfo
Definition: a_star_planner.h:66
cb_global_planner::AStarPlanner::CellInfo::visited_from_
CellInfo * visited_from_
Definition: a_star_planner.h:75
cb_global_planner::AStarPlanner::CellInfo::g_
double g_
Definition: a_star_planner.h:73
cb_global_planner::AStarPlanner::CellInfo::CellInfo
CellInfo(double x, double y, double g, double h)
Definition: a_star_planner.h:77
cb_global_planner::AStarPlanner::setCostmap
void setCostmap(const unsigned char *char_cost_map)
Definition: a_star_planner.cpp:27
std::priority_queue
cb_global_planner::AStarPlanner::AStarPlanner
AStarPlanner(int width, int height)
Definition: a_star_planner.cpp:11
cb_global_planner::AStarPlanner::plan
bool plan(std::vector< unsigned int > mx_start, std::vector< unsigned int > my_start, int mx_goal, int my_goal, std::vector< int > &plan_xs, std::vector< int > &plan_ys, bool best_heuristic=false)
Definition: a_star_planner.cpp:79
cb_global_planner::AStarPlanner::CellInfo::x_
int x_
Definition: a_star_planner.h:70
cb_global_planner::AStarPlanner::height_
unsigned int height_
Definition: a_star_planner.h:60
cb_global_planner
Definition: a_star_planner.cpp:5
cb_global_planner::AStarPlanner::visited_map_
double ** visited_map_
Definition: a_star_planner.h:58
cb_global_planner::AStarPlanner::getCost
double getCost(int x, int y)
Definition: a_star_planner.cpp:31
cb_global_planner::AStarPlanner::N_OBJECTS
static long N_OBJECTS
Definition: a_star_planner.h:52
cb_global_planner::AStarPlanner::expandCell
void expandCell(CellInfo *c, int dx, int dy, double cost_factor, double **visited_map, int x_goal, int y_goal, double min_cell_cost, std::priority_queue< CellInfo *, std::vector< CellInfo * >, compareCellInfos > &Q)
Definition: a_star_planner.cpp:176
cb_global_planner::AStarPlanner::CellInfo::N_OBJECTS
static long N_OBJECTS
Definition: a_star_planner.h:68
cb_global_planner::AStarPlanner::char_cost_map_
const unsigned char * char_cost_map_
Definition: a_star_planner.h:56
cb_global_planner::AStarPlanner::deleteMap
void deleteMap()
Definition: a_star_planner.cpp:199