-
Notifications
You must be signed in to change notification settings - Fork 0
/
objective.cpp
34 lines (27 loc) · 1.14 KB
/
objective.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
#include "objective.h"
/////////////////////////////////////////////////////
/// Schwefel Function ///
/////////////////////////////////////////////////////
RealVec& Schwefel::eval(RealVec& solution, Real& w1, Real& w2) {
Real obj = 0.; Real pnlt = 0.;
for(auto&& s: solution)
obj += -s * sin(pow(abs(s),0.5));
static RealVec ans(2);
ans[0] = obj; ans[1] = pnlt;
penalize(ans, w1, w2);
return ans;
}
void Schwefel::penalize(RealVec& answer, Real& w1, Real& w2) {answer[0] *= pow(w1*(1 + answer[1]), w2);}
/////////////////////////////////////////////////////
/// Sphere Function ///
/////////////////////////////////////////////////////
RealVec& Sphere::eval(RealVec& solution, Real& w1, Real& w2) {
Real obj = 0.; Real pnlt = 0.;
for(auto&& s: solution)
obj += pow(s,2.);
static RealVec ans(2);
ans[0] = obj; ans[1] = pnlt;
penalize(ans, w1, w2);
return ans;
}
void Sphere::penalize(RealVec& answer, Real& w1, Real& w2) {answer[0] *= pow(w1*(1 + answer[1]), w2);}