Hybrid A* Planner
 All Classes Namespaces Files Functions Variables Friends Pages
node2d.h
1 #ifndef NODE2D_H
2 #define NODE2D_H
3 
4 #include <cmath>
5 
6 #include "constants.h"
7 namespace HybridAStar {
8 
14 class Node2D {
15  public:
17  Node2D(): Node2D(0, 0, 0, 0, nullptr) {}
19  Node2D(int x, int y, float g, float h, Node2D* pred) {
20  this->x = x;
21  this->y = y;
22  this->g = g;
23  this->h = h;
24  this->pred = pred;
25  this->o = false;
26  this->c = false;
27  this->d = false;
28  this->idx = -1;
29  }
30  // GETTER METHODS
32  int getX() const { return x; }
34  int getY() const { return y; }
36  float getG() const { return g; }
38  float getH() const { return h; }
40  float getC() const { return g + h; }
42  int getIdx() const { return idx; }
44  bool isOpen() const { return o; }
46  bool isClosed() const { return c; }
48  bool isDiscovered() const { return d; }
50  Node2D* getPred() const { return pred; }
51 
52  // SETTER METHODS
54  void setX(const int& x) { this->x = x; }
56  void setY(const int& y) { this->y = y; }
58  void setG(const float& g) { this->g = g; }
60  void setH(const float& h) { this->h = h; }
62  int setIdx(int width) { this->idx = y * width + x; return idx;}
64  void open() { o = true; c = false; }
66  void close() { c = true; o = false; }
68  void reset() { c = false; o = false; }
70  void discover() { d = true; }
72  void setPred(Node2D* pred) { this->pred = pred; }
73 
74  // UPDATE METHODS
76  void updateG() { g += movementCost(*pred); d = true; }
78  void updateH(const Node2D& goal) { h = movementCost(goal); }
80  float movementCost(const Node2D& pred) const { return sqrt((x - pred.x) * (x - pred.x) + (y - pred.y) * (y - pred.y)); }
81 
82  // CUSTOM OPERATORS
84  bool operator == (const Node2D& rhs) const;
85 
86  // GRID CHECKING
88  bool isOnGrid(const int width, const int height) const;
89 
90  // SUCCESSOR CREATION
92  Node2D* createSuccessor(const int i);
93 
94  // CONSTANT VALUES
96  static const int dir;
98  static const int dx[];
100  static const int dy[];
101 
102  private:
104  int x;
106  int y;
108  float g;
110  float h;
112  int idx;
114  bool o;
116  bool c;
118  bool d;
121 };
122 }
123 #endif // NODE2D_H
int x
the x position
Definition: node2d.h:104
int getX() const
get the x position
Definition: node2d.h:32
void setG(const float &g)
set the cost-so-far (real value)
Definition: node2d.h:58
int getY() const
get the y position
Definition: node2d.h:34
float movementCost(const Node2D &pred) const
The heuristic as well as the cost measure.
Definition: node2d.h:80
int y
the y position
Definition: node2d.h:106
void open()
open the node
Definition: node2d.h:64
Node2D * getPred() const
get a pointer to the predecessor
Definition: node2d.h:50
This is a collection of constants that are used throughout the project.
static const int dx[]
Possible movements in the x direction.
Definition: node2d.h:98
float h
the cost-to-go
Definition: node2d.h:110
bool isOpen() const
determine whether the node is open
Definition: node2d.h:44
bool d
the discovered value
Definition: node2d.h:118
static const int dy[]
Possible movements in the y direction.
Definition: node2d.h:100
int setIdx(int width)
set and get the index of the node in the 2D array
Definition: node2d.h:62
int getIdx() const
get the index of the node in the 2D array
Definition: node2d.h:42
float g
the cost-so-far
Definition: node2d.h:108
float getH() const
get the cost-to-come (heuristic value)
Definition: node2d.h:38
bool c
the closed value
Definition: node2d.h:116
Node2D(int x, int y, float g, float h, Node2D *pred)
Constructor for a node with the given arguments.
Definition: node2d.h:19
static const int dir
Number of possible directions.
Definition: node2d.h:96
Node2D()
The default constructor for 2D array initialization.
Definition: node2d.h:17
void setX(const int &x)
set the x position
Definition: node2d.h:54
A two dimensional node class used for the holonomic with obstacles heuristic.
Definition: node2d.h:14
bool isClosed() const
determine whether the node is closed
Definition: node2d.h:46
void updateH(const Node2D &goal)
Updates the cost-to-go for the node x' to the goal node.
Definition: node2d.h:78
bool isDiscovered() const
determine whether the node is discovered
Definition: node2d.h:48
bool o
the open value
Definition: node2d.h:114
void reset()
set the node neither open nor closed
Definition: node2d.h:68
bool operator==(const Node2D &rhs) const
Custom operator to compare nodes. Nodes are equal if their x and y position is the same...
Definition: node2d.cpp:30
void setH(const float &h)
set the cost-to-come (heuristic value)
Definition: node2d.h:60
void setPred(Node2D *pred)
set a pointer to the predecessor of the node
Definition: node2d.h:72
void updateG()
Updates the cost-so-far for the node x' coming from its predecessor. It also discovers the node...
Definition: node2d.h:76
void setY(const int &y)
set the y position
Definition: node2d.h:56
void close()
close the node
Definition: node2d.h:66
float getC() const
get the total estimated cost
Definition: node2d.h:40
float getG() const
get the cost-so-far (real value)
Definition: node2d.h:36
bool isOnGrid(const int width, const int height) const
Validity check to test, whether the node is in the 2D array.
Definition: node2d.cpp:14
int idx
the index of the node in the 2D array
Definition: node2d.h:112
Node2D * createSuccessor(const int i)
Creates a successor on a eight-connected grid.
Definition: node2d.cpp:21
Node2D * pred
the predecessor pointer
Definition: node2d.h:120
void discover()
discover the node
Definition: node2d.h:70