-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPopulation.cpp
More file actions
49 lines (41 loc) · 1.19 KB
/
Population.cpp
File metadata and controls
49 lines (41 loc) · 1.19 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
39
40
41
42
43
44
45
46
47
48
49
#include "pch.h"
#include "Population.h"
Population::Population(int _popSize,
float probCrossover,
float probMutation,
Problem *problem) {
populationSize = _popSize;
geneSize = problem->x_num;
crossover_prob = probCrossover;
mutation_prob = probMutation;
problem_ = problem;
}
void Population::initialize() {
for (int i = 0; i < populationSize; i++) {
individualSet.push_back(Individual(geneSize, problem_));
}
}
void Population::clear() {
individualSet.clear();
}
Population Population::copy() {
return Population(populationSize, crossover_prob, mutation_prob, problem_);
}
Population Population::copy_all() {
Population _tmpPop(populationSize, crossover_prob, mutation_prob, problem_);
_tmpPop.individualSet = individualSet;
return _tmpPop;
}
Population Population::combination(Population q) {
Population _tmp(populationSize * 2, crossover_prob, 1 / (populationSize * 2), problem_);
_tmp.individualSet = individualSet;
for (auto ind : q.individualSet) {
_tmp.individualSet.push_back(ind);
}
return _tmp;
}
void Population::evaluation() {
for (auto &ind : individualSet) {
ind.evaluation();
}
}