-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndividual.cpp
More file actions
36 lines (31 loc) · 844 Bytes
/
Individual.cpp
File metadata and controls
36 lines (31 loc) · 844 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
29
30
31
32
33
34
35
36
#include "pch.h"
#include "Individual.h"
Individual::Individual() {}
Individual::Individual(int geneSize, Problem *problem) {
problem_ = problem;
std::random_device rd;
std::mt19937 rng(rd());
std::uniform_real_distribution<> dist_float(problem->x_min, problem->x_max);
for (int i = 0; i < geneSize; i++) {
genes.push_back(dist_float(rng));
}
distance = 0;
}
void Individual::evaluation() {
problem_->evaluation(genes, objectiveSet);
}
bool Individual::dominate(Individual q) {
for (int i = 0; i < objectiveSet.size(); i++) {
if (objectiveSet[i] > q.objectiveSet[i]) {
return false;
}
}
return true;
}
bool Individual::descending(Individual *a, Individual *b) {
if ((a->rank < b->rank) || ((a->rank == b->rank) && (a->distance > b->distance))) {
return true;
} else {
return false;
}
}