-
Notifications
You must be signed in to change notification settings - Fork 3
/
structs.h
159 lines (144 loc) · 4.07 KB
/
structs.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef STRUCTS_H
#define STRUCTS_H
#include "gl_const.h"
#include <utility>
#include <vector>
#include <string>
#include <list>
struct conflict
{
int agent1;
int agent2;
int sec1;
int sec2;
double i;
double j;
double g;
};
struct Agent
{
std::string id;
int start_i;
int start_j;
double start_heading;
int goal_i;
int goal_j;
double goal_heading;
double size;
double rspeed;
double mspeed;
Agent(){ start_i = -1; start_j = -1; goal_i = -1; goal_j = -1;
size = CN_DEFAULT_SIZE; mspeed = CN_DEFAULT_MSPEED; rspeed = CN_DEFAULT_RSPEED;
start_heading = CN_DEFAULT_SHEADING; goal_heading = CN_DEFAULT_GHEADING; }
};
struct constraint
{
double i;
double j;
double g;
bool goal;
};
struct movement
{
double g;
int p_dir;
int s_dir;
};
struct SafeInterval
{
double begin;
double end;
int id;
SafeInterval(double begin_=0, double end_=CN_INFINITY, int id_=0):begin(begin_), end(end_), id(id_) {}
SafeInterval(const SafeInterval &other) { begin = other.begin; end = other.end; id = other.id;}
};
struct Node
{
Node(int _i=-1, int _j=-1, double _g=-1, double _F=-1):i(_i),j(_j),g(_g),F(_F),Parent(nullptr){expanded = false;consistent = 0;best_Parent = nullptr; best_g = CN_INFINITY; parents.clear();}
~Node(){ Parent = nullptr; }
int i, j;
double size;
double g;
double F;
double heading;
const Node* Parent;
SafeInterval interval;
int interval_id;
int consistent;
bool expanded;
double h;
double best_g;
const Node* best_Parent;
std::list<std::pair<const Node*, double>> parents;
bool operator<(const Node& n) const
{
if(this->i == n.i)
return this->j < n.j;
return this->i < n.i;
}
};
struct obstacle
{
std::string id;
double size;
double mspeed;
std::vector<Node> sections;
obstacle(){ id = -1; size = CN_DEFAULT_SIZE; mspeed = CN_DEFAULT_MSPEED; }
};
struct section
{
section(int _i1=-1, int _j1=-1, int _i2=-1, int _j2=-1, double _g1=-1, double _g2=-1)
:i1(_i1), j1(_j1), i2(_i2), j2(_j2), g1(_g1), g2(_g2){}
section(const Node &a, const Node &b):i1(a.i), j1(a.j), i2(b.i), j2(b.j), g1(a.g), g2(b.g){}
int i1;
int j1;
int i2;
int j2;
double size;
double g1;
double g2;//is needed for goal and wait actions
double mspeed;
bool operator == (const section &comp) const {return (i1 == comp.i1 && j1 == comp.j1 && g1 == comp.g1);}
};
class Vector2D {
public:
Vector2D(double _i = 0.0, double _j = 0.0):i(_i),j(_j){}
double i, j;
inline Vector2D operator +(const Vector2D &vec) { return Vector2D(i + vec.i, j + vec.j); }
inline Vector2D operator -(const Vector2D &vec) { return Vector2D(i - vec.i, j - vec.j); }
inline Vector2D operator -() { return Vector2D(-i,-j); }
inline Vector2D operator /(const double &num) { return Vector2D(i/num, j/num); }
inline Vector2D operator *(const double &num) { return Vector2D(i*num, j*num); }
inline double operator *(const Vector2D &vec){ return i*vec.i + j*vec.j; }
inline void operator +=(const Vector2D &vec) { i += vec.i; j += vec.j; }
inline void operator -=(const Vector2D &vec) { i -= vec.i; j -= vec.j; }
};
class Point {
public:
double i;
double j;
Point(double _i = 0.0, double _j = 0.0):i (_i), j (_j){}
Point operator-(Point &p){return Point(i - p.i, j - p.j);}
int operator== (Point &p){return (i == p.i) && (j == p.j);}
int classify(Point &pO, Point &p1)
{
Point p2 = *this;
Point a = p1 - pO;
Point b = p2 - pO;
double sa = a.i * b.j - b.i * a.j;
if (sa > 0.0)
return 1;//LEFT;
if (sa < 0.0)
return 2;//RIGHT;
if ((a.i * b.i < 0.0) || (a.j * b.j < 0.0))
return 3;//BEHIND;
if ((a.i*a.i + a.j*a.j) < (b.i*b.i + b.j*b.j))
return 4;//BEYOND;
if (pO == p2)
return 5;//ORIGIN;
if (p1 == p2)
return 6;//DESTINATION;
return 7;//BETWEEN;
}
};
#endif