-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
28 lines (22 loc) · 752 Bytes
/
Copy pathexample.cpp
File metadata and controls
28 lines (22 loc) · 752 Bytes
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
#include "math/gopt.hpp"
using namespace gopt;
double fcn(const Vector<double>& x)
{
return -(4*x[0] -2*x[1] + 7*x[2] + 5*x[3] + 11*x[4] + x[5]);
}
int main()
{
unsigned int N = 1000;
Vector<double> lb(6);
lb.fill(-10);
Vector<double> ub(6);
ub.fill(10);
std::default_random_engine gen(time(0));
std::uniform_real_distribution<double> dist(lb[0], ub[0]);
std::vector<Vector<double>> x0(N);
for (int i = 0; i < N; i++)
x0[i] = Vector<double>(6).fill(dist(gen), dist(gen), dist(gen), dist(gen), dist(gen), dist(gen));
auto [best, score] = ga(fcn, x0, lb, ub, 0.2, 0.8, 100.0, 100.0, 1000);
std::cout << best << ", score: " << score << std::endl;
return 0;
}