-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnode.h
More file actions
65 lines (56 loc) · 1.94 KB
/
node.h
File metadata and controls
65 lines (56 loc) · 1.94 KB
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
#ifndef NODE_H
#define NODE_H
#include <unordered_set>
#include <tuple>
struct Node
{
int i, j; //grid cell coordinates
int g;
double F, H; //f-, g- and h-values of the search node
Node *parent; //backpointer to the predecessor node (e.g. the node which g-value was used to set the g-velue of the current node)
int conflictsCount;
int speed;
int angleId;
int primitiveId;
Node(int x = 0, int y = 0, Node *p = nullptr, int g_ = 0, double H_ = 0,
int ConflictsCount = 0, int PrimitiveId = -1, int AngleType = 0, int Speed = 0) {
i = x;
j = y;
parent = p;
g = g_;
H = H_;
F = g_ + H_;
conflictsCount = ConflictsCount;
primitiveId = PrimitiveId;
speed = Speed;
angleId = AngleType;
}
bool operator== (const Node &other) const {
return i == other.i && j == other.j;
}
bool operator!= (const Node &other) const {
return i != other.i || j != other.j;
}
bool operator< (const Node &other) const {
return std::tuple<int, int, int, int, int, int>(F, -g, i, j, speed, angleId) <
std::tuple<int, int, int, int, int, int>(other.F, -other.g, other.i,
other.j, other.speed, other.angleId);
}
virtual int convolution(int width, int height, bool withTime = false) const {
int res = withTime ? width * height * g : 0;
return 2 * 8 * (res + i * width + j) + 2 * angleId + speed;
}
};
struct NodeHash {
size_t operator()(const Node& node) const {
return (node.i + node.j) * (node.i + node.j + 1) + node.j;
}
};
struct NodePairHash {
size_t operator()(const std::pair<Node, Node>& pair) const {
NodeHash nodeHash;
size_t hash1 = nodeHash(pair.first), hash2 = nodeHash(pair.second);
return (hash1 + hash2) * (hash1 + hash2 + 1) + hash2;
}
};
#endif