-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathnode.h
61 lines (52 loc) · 1.68 KB
/
node.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
#ifndef NODE_H
#define NODE_H
#include <unordered_set>
#include <tuple>
#include "gl_const.h"
struct Node
{
int i, j; //grid cell coordinates
int g; //f-, g- and h-values of the search node
double F, H;
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;
Node(int x = 0, int y = 0, Node *p = nullptr, int g_ = 0, double H_ = 0, int ConflictsCount = 0) {
i = x;
j = y;
parent = p;
g = g_;
H = H_;
F = (g_ == CN_INFINITY) ? g_ : g_ + H_;
conflictsCount = ConflictsCount;
}
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>(F, -g, i, j) <
std::tuple<int, int, int, int>(other.F, -other.g, other.i, other.j);
}
virtual int convolution(int width, int height, bool withTime = false) const {
int res = withTime ? width * height * g : 0;
return res + i * width + j;
}
virtual int getHC() const {
return 0;
}
};
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