-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathfocalsearch.cpp
96 lines (84 loc) · 2.83 KB
/
focalsearch.cpp
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
#include "focalsearch.h"
template<typename NodeType>
int FocalSearch<NodeType>::Time = 0;
template<typename NodeType>
FocalSearch<NodeType>::FocalSearch(bool WithTime, double FocalW, double HW, bool BT) :
Astar<NodeType>(WithTime, HW, BT) {
auto focalCmp = [](const NodeType &lhs, const NodeType &rhs) {
return lhs.hc < rhs.hc || lhs.hc == rhs.hc && lhs < rhs;
};
focal = SearchQueue<NodeType>(focalCmp);
focalW = FocalW;
}
template<typename NodeType>
bool FocalSearch<NodeType>::checkOpenEmpty() {
return this->open.empty() && focal.empty();
}
template<typename NodeType>
NodeType FocalSearch<NodeType>::getCur(const Map& map) {
if (!this->open.empty()) {
double minF = this->open.getFront().F;
if (!focalF.empty()) {
minF = std::min(minF, *focalF.begin());
}
this->open.moveByUpperBound(focal, minF * focalW, map, focalF, this->withTime);
}
NodeType cur = focal.getFront();
return cur;
}
template<typename NodeType>
void FocalSearch<NodeType>::removeCur(const NodeType& cur, const Map& map) {
focal.erase(map, cur, this->withTime);
auto it = focalF.find(cur.F);
focalF.erase(focalF.find(cur.F));
}
template<typename NodeType>
bool FocalSearch<NodeType>::updateFocal(const NodeType& neigh, const Map& map) {
NodeType old = focal.getByIndex(map, neigh, this->withTime);
if (old.i != -1) {
if (focal.insert(map, neigh, this->withTime, true, old)) {
auto it = focalF.find(old.F);
focalF.erase(focalF.find(old.F));
focalF.insert(neigh.F);
}
return true;
}
return false;
}
template<typename NodeType>
double FocalSearch<NodeType>::getMinFocalF() {
if (focalF.empty()) {
return CN_INFINITY;
}
return *focalF.begin();
}
template<typename NodeType>
void FocalSearch<NodeType>::clearLists() {
ISearch<NodeType>::clearLists();
focal.clear();
focalF.clear();
}
template<typename NodeType>
void FocalSearch<NodeType>::setHC(NodeType &neigh, const NodeType &cur,
const ConflictAvoidanceTable &CAT, bool isGoal) {
neigh.hc = cur.hc + neigh.conflictsCount;
if (isGoal) {
addFutureConflicts(neigh, CAT);
}
}
template<typename NodeType>
void FocalSearch<NodeType>::addFutureConflicts(NodeType &neigh, const ConflictAvoidanceTable &CAT) {
neigh.futureConflictsCount = CAT.getFutureConflictsCount(neigh, neigh.g);
neigh.hc += neigh.futureConflictsCount;
}
template<typename NodeType>
void FocalSearch<NodeType>::updateFocalW(double newFocalW, const Map& map) {
focalW = newFocalW;
if (focal.empty()) {
return;
}
double minF = *focalF.begin();
this->focal.moveByLowerBound(this->open, minF * focalW, map, focalF, this->withTime);
}
template class FocalSearch<FSNode>;
template class FocalSearch<SCIPPNode>;