-
Notifications
You must be signed in to change notification settings - Fork 44
/
Dstar.h
129 lines (100 loc) · 2.62 KB
/
Dstar.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* Dstar.h
* James Neufeld ([email protected])
* Compilation fixed by Arek Sredzki ([email protected])
*/
#ifndef DSTAR_H
#define DSTAR_H
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;
class state {
public:
int x;
int y;
pair<double,double> k;
bool operator == (const state &s2) const {
return ((x == s2.x) && (y == s2.y));
}
bool operator != (const state &s2) const {
return ((x != s2.x) || (y != s2.y));
}
bool operator > (const state &s2) const {
if (k.first-0.00001 > s2.k.first) return true;
else if (k.first < s2.k.first-0.00001) return false;
return k.second > s2.k.second;
}
bool operator <= (const state &s2) const {
if (k.first < s2.k.first) return true;
else if (k.first > s2.k.first) return false;
return k.second < s2.k.second + 0.00001;
}
bool operator < (const state &s2) const {
if (k.first + 0.000001 < s2.k.first) return true;
else if (k.first - 0.000001 > s2.k.first) return false;
return k.second < s2.k.second;
}
};
struct ipoint2 {
int x,y;
};
struct cellInfo {
double g;
double rhs;
double cost;
};
class state_hash {
public:
size_t operator()(const state &s) const {
return s.x + 34245*s.y;
}
};
typedef priority_queue<state, vector<state>, greater<state> > ds_pq;
typedef hash_map<state,cellInfo, state_hash, equal_to<state> > ds_ch;
typedef hash_map<state, float, state_hash, equal_to<state> > ds_oh;
class Dstar {
public:
Dstar();
void init(int sX, int sY, int gX, int gY);
void updateCell(int x, int y, double val);
void updateStart(int x, int y);
void updateGoal(int x, int y);
bool replan();
void draw();
void drawCell(state s,float z);
list<state> getPath();
private:
list<state> path;
double C1;
double k_m;
state s_start, s_goal, s_last;
int maxSteps;
ds_pq openList;
ds_ch cellHash;
ds_oh openHash;
bool close(double x, double y);
void makeNewCell(state u);
double getG(state u);
double getRHS(state u);
void setG(state u, double g);
double setRHS(state u, double rhs);
double eightCondist(state a, state b);
int computeShortestPath();
void updateVertex(state u);
void insert(state u);
void remove(state u);
double trueDist(state a, state b);
double heuristic(state a, state b);
state calculateKey(state u);
void getSucc(state u, list<state> &s);
void getPred(state u, list<state> &s);
double cost(state a, state b);
bool occupied(state u);
bool isValid(state u);
float keyHashCode(state u);
};
#endif