-
Notifications
You must be signed in to change notification settings - Fork 2
/
evaluationrecords.cpp
158 lines (133 loc) · 4.43 KB
/
evaluationrecords.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
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
#include "evaluationrecords.h"
#include <functional>
#include <iostream>
#include <sstream>
using namespace std;
EvaluationRecords::EvaluationRecords()
//: evaluations(new unordered_map<Pose, double>())
{}
EvaluationRecords::~EvaluationRecords() {
// delete evaluations;
}
void EvaluationRecords::putEvaluation(Pose &frontier, double value) {
if (evaluations.empty()) {
minValue = value;
maxValue = value;
}
string s = getEncodedKey(frontier);
evaluations.emplace(s, value);
if (value >= maxValue)
maxValue = value;
if (value <= minValue)
minValue = value;
}
double EvaluationRecords::getEvaluation(Pose &frontier) {
string s = getEncodedKey(frontier);
return evaluations[s];
}
unordered_map<string, double> EvaluationRecords::getEvaluations() {
return evaluations;
}
bool EvaluationRecords::contains(Pose &frontier) {
string s = getEncodedKey(frontier);
unordered_map<string, double>::const_iterator got = evaluations.find(s);
if (got == evaluations.end()) {
return false;
} else
return true;
}
int EvaluationRecords::size() { return evaluations.size(); }
list<Pose> EvaluationRecords::getFrontiers() {
vector<string> list;
list.reserve(evaluations.size());
for (unordered_map<string, double>::iterator it = evaluations.begin();
it != evaluations.end(); it++) {
list.push_back((*it).first);
}
std::list<Pose> toRet;
for (vector<string>::iterator it = list.begin(); it != list.end(); it++) {
// create a pose object for every string string in the list
string s = *it;
Pose p = getPoseFromEncoding(s);
toRet.push_back(p);
}
return toRet;
}
void EvaluationRecords::removeFrontier(Pose &frontier) {
for (unordered_map<string, double>::iterator it = evaluations.begin();
it != evaluations.end(); it++) {
string s1 = (*it).first;
string s2 = getEncodedKey(frontier);
if (s1 == s2) {
evaluations.erase(s2);
break;
}
}
}
void EvaluationRecords::normalize() {
vector<string> list;
list.reserve(evaluations.size());
for (unordered_map<string, double>::iterator it = evaluations.begin();
it != evaluations.end(); it++) {
list.push_back((*it).first);
}
for (vector<string>::iterator it = list.begin(); it != list.end(); it++) {
for (unordered_map<string, double>::iterator it2 = evaluations.begin();
it2 != evaluations.end(); it2++) {
if ((*it) == (*it2).first) {
double value = (*it2).second;
value = (value - minValue) / (maxValue - minValue);
evaluations.erase((*it2).first);
pair<string, double> newPair(*it, value);
evaluations.insert(newPair);
}
}
}
}
string EvaluationRecords::getEncodedKey(Pose &p) {
string key = to_string(p.getX()) + "/" + to_string(p.getY()) + "/" +
to_string(p.getOrientation()) + "/" + to_string(p.getRange()) +
"/" + to_string(p.getFOV());
return key;
}
Pose EvaluationRecords::getPoseFromEncoding(string &encoding) {
stringstream ss;
string s;
ss << s;
char delimiter('/');
string x, y, orientation, r, phi;
// cout << encoding << endl;
std::string::size_type pos = encoding.find('/');
x = encoding.substr(0, pos);
float xValue = atof(x.c_str());
// cout << x << endl;
string newString = encoding.substr(pos + 1, encoding.size());
// cout << newString << endl;
std::string::size_type newPos = newString.find('/');
y = newString.substr(0, newPos);
float yValue = atof(y.c_str());
// cout << y << endl;
newString = newString.substr(newPos + 1, encoding.size());
// cout << newString << endl;
newPos = newString.find('/');
orientation = newString.substr(0, newPos);
float orientationValue = atof(orientation.c_str());
// cout << orientation << endl;
newString = newString.substr(newPos + 1, encoding.size());
// cout << newString << endl;
newPos = newString.find('/');
r = newString.substr(0, newPos);
int rValue = atoi(r.c_str());
// cout << r << endl;
newString = newString.substr(newPos + 1, encoding.size());
// cout << newString << endl;
newPos = newString.find('/');
phi = newString.substr(0, newPos);
double phiValue = atof(phi.c_str());
// cout << phi << endl;
Pose p(xValue, yValue, orientationValue, rValue, phiValue);
return p;
}
void EvaluationRecords::clear(){
this->evaluations.clear();
}