-
Notifications
You must be signed in to change notification settings - Fork 0
/
dgv1.cpp
40 lines (31 loc) · 1.04 KB
/
dgv1.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
#include"dgv1.hpp"
#include <algorithm>
#include <limits>
using std::abs;
using std::tuple;
using std::vector;
DGv1::DGv1() {}
DGv1::DGv1(const DGv1& o) : DG(o) {}
DGv1::~DGv1() {}
std::string DGv1::info() {
return "Differential Grouping version 1 (DGv1)";
}
tuple<vector<size_t>, vector<vector<size_t>>> DGv1::run(TestFuncBounds& ifunc) {
initRun(ifunc);
_epsilon = calc_epsilon();
return DG::run(ifunc);
}
double DGv1::epsilon(double a, double b, double c, double d) {
return _epsilon;
}
double DGv1::calc_epsilon() {
auto x = vector<vector<double>>(np, vector<double>(func->dim));
auto xf = vector<double>(np);
std::uniform_real_distribution<double> dist(0.0,1.0);
for (int i = 0; i < np; i++) for (int j = 0; j < func->dim; j++) x[i][j] = func->x_bound_max[j] - func->x_bound_min[j] * dist(rand_gen) + func->x_bound_min[j];
for (int i = 0; i < np; i++) xf[i] = eval(x[i].data());
auto minf = abs(xf[0]);
for (int i = 1; i < np; i++) if (minf > abs(xf[i])) minf = abs(xf[i]);
auto epsilon = alpha * minf;
return alpha * minf;
}