-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRastriging.cpp
More file actions
59 lines (46 loc) · 1.04 KB
/
Copy pathRastriging.cpp
File metadata and controls
59 lines (46 loc) · 1.04 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
#include "Rastriging.h"
#include <vector>
#include <math.h>
Rastriging::Rastriging() {
decDim = 2;
name = "Rastriging";
}
Rastriging::Rastriging(const int dim) {
decDim = dim;
name = "Rastriging";
}
Rastriging::~Rastriging() {
}
std::vector<std::vector<float>> Rastriging::getSearchRange() {
std::vector<std::vector<float>> res(decDim);
float lim = 5.12f;
for(int i = 0; i < decDim; i++) {
std::vector<float> upLow(2);
upLow[0] = -lim;
upLow[1] = lim;
res[i] = upLow;
}
return res;
}
std::vector<float> Rastriging::getKnownOptimumPoint() {
std::vector<float> res(decDim, 0.f);
return res;
}
/*
Definition := A*n + sum(x_i^2 - A cos(2*PI*x_i)) where A = 10
and n is the dimension of objective space.
*/
float Rastriging::evaluateOriginalObjective(std::vector<float> &point) {
float A = 10.f;
float res = A * point.size();
for(const auto& xi : point) {
res += xi * xi - A * (float)cos(2 * PI * xi);
}
return res;
}
/*
Rastring is unconstrained.
*/
float Rastriging::evaluatePenalty(std::vector<float> &point) {
return 0.f;
}