forked from milsto/differential-evolution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_2.cpp
44 lines (33 loc) · 841 Bytes
/
example_2.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
#include "de/DifferentialEvolution.h"
#include <ctime>
class SimpleQuadriatic : public de::IOptimizable
{
public:
double EvaluteCost(std::vector<double> inputs) const override
{
assert(inputs.size() == 2);
double x = inputs[0];
double y = inputs[1];
return x * x + 2 * x * y + 3 * y * y;
}
unsigned int NumberOfParameters() const override
{
return 2;
}
std::vector<Constraints> GetConstraints() const override
{
std::vector<Constraints> constr(NumberOfParameters());
for (auto& c : constr)
{
c = Constraints(-100.0, 100.0, true);
}
return constr;
}
};
int main()
{
SimpleQuadriatic cost;
de::DifferentialEvolution de(cost, 100, std::time(nullptr));
de.Optimize(1000, true);
return 0;
}