-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectives.cpp
64 lines (59 loc) · 1.73 KB
/
Objectives.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <random>
#include "Benchmark.hpp"
#include "Objectives.hpp"
using namespace std;
Objectives::Objectives()
{
}
Objectives::Objectives(int NObjectivesByIndividual)
{
this->NObjectivesByIndividual = NObjectivesByIndividual;
}
void Objectives::setObjectivesByIndividual(int N)
{
this->NObjectivesByIndividual = N;
}
bool Objectives::Dominate(Objectives &objB)
{
for(int i = 0; i < this->NObjectivesByIndividual; i++)
{
if(this->SpaceObjectives[i].Type== MAXIMIZE )
{
if( this->SpaceObjectives[i].Fitness < objB.SpaceObjectives[i].Fitness)
{
return false;
}
}
else if(this->SpaceObjectives[i].Type == MINIMIZE )
{
if( this->SpaceObjectives[i].Fitness > objB.SpaceObjectives[i].Fitness)
{
return false;
}
}
}
return true;
}
void Objectives::Eval()
{
vector <double> obj(this->NObjectivesByIndividual);
this->ObjBenchmark->Eval(this->DecisionVariables, obj);
for(int i = 0; i < obj.size(); i++)
this->SpaceObjectives[i].Fitness = obj[i];
}
void Objectives::setBenchmark(Benchmark *ObjBenchmark)
{
this->ObjBenchmark = ObjBenchmark;
this->SpaceObjectives.resize(ObjBenchmark->getNObjectives());
for(int i =0 ;i< ObjBenchmark->getNObjectives(); i++)
{
this->SpaceObjectives[i].Type = ObjBenchmark->getTypeDuality()[i];
}
this->DecisionVariables.resize(ObjBenchmark->getDimension());
this->NObjectivesByIndividual = ObjBenchmark->getNObjectives();
this->Dimension = ObjBenchmark->getDimension();
}