-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSGA2.cpp
More file actions
39 lines (32 loc) · 1.08 KB
/
NSGA2.cpp
File metadata and controls
39 lines (32 loc) · 1.08 KB
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
#include <problems/ZDT1.h>
#include "pch.h"
#include "Population.h"
#include "Individual.h"
#include "GeneticAlgorithm.h"
int main() {
int generation = 2000;
GeneticAlgorithm ga;
Problem *problem = new ZDT1();
problem->reference();
Population _tmpParent(POPULATION_SIZE, CROSSOVER_PROB, MUTATION_PROB, problem);
_tmpParent.initialize();
_tmpParent.evaluation();
//非支配排序
ga.fastNonDominatedSort(_tmpParent);
Population _tmpChild = ga.next_new_pop(_tmpParent, ETA_C, ETA_M);
for (int i = 0; i < generation; i++) {
Population _tmpComb = _tmpParent.combination(_tmpChild);
ga.elitism(_tmpComb);
_tmpParent = _tmpComb;
_tmpChild = ga.next_new_pop(_tmpParent, ETA_C, ETA_M);
cout << "Parent size: " << _tmpParent.individualSet.size() << endl;
cout << "Complete generation [" << i << "]" << endl;
}
ofstream os("result_" + to_string(POPULATION_SIZE) + to_string(generation) + ".txt");
if (os.is_open()) {
for (auto i : _tmpParent.individualSet) {
os << i.objectiveSet[0] << "\t" << i.objectiveSet[1] << endl;
}
}
os.close();
}