-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopulation.cpp
82 lines (67 loc) · 1.93 KB
/
population.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "population.hpp"
using namespace std;
Population::Population(int tamPopulation, int dimension, double lowerBound, double upperBound){
this->tamPopulation = tamPopulation;
this->dimension = dimension;
this->lowerBound = lowerBound;
this->upperBound = upperBound;
srand(time(NULL));
}
Population::Population(){}
Population::~Population(){}
void Population::initializePopulation(){
this->population.clear();
std::vector<double> position;
Fish *tmpFish;
for(int i=0; i< tamPopulation; i++){
position.clear();
for(int j=0; j<dimension; j++){
position.push_back(fRand(lowerBound, upperBound));
}
tmpFish = new Fish(2500, position);
this->population.push_back(*tmpFish);
}
}
void Population::updatePopulationDisplacement(){
std::vector<double> displacement;
for(int i=0; i< tamPopulation; i++){
if(population[i].getImproved()){
displacement.clear();
// cout << "displacement: " << i << " - ";
for(int j=0; j<dimension; j++){
displacement.push_back(population[i].getCurrentPosition()[j] - population[i].getPreviuosPosition()[j]);
// cout << " * " << displacement[j];
}
// cout << endl;
population[i].setIndividualDisplacement(displacement);
}
}
}
std::vector<Fish> Population::getPopulation(){
return population;
}
Fish * Population::getFish(int pos){
return &population[pos];
}
void Population::updateFish(Fish fish, int pos){
this->population[pos] = fish;
}
int Population::getTamPopulation(){
return tamPopulation;
}
double Population::getMinWeight(){
return this->minWeight;
}
double Population::getMaxWeight(){
return this->maxWeight;
}
void Population::setMinWeight(double minWeight){
this->minWeight = minWeight;
}
void Population::setMaxWeight(double maxWeight){
this->maxWeight = maxWeight;
}
double Population::fRand(double fMin, double fMax){
double f = (double)rand() / RAND_MAX;
return fMin + f * (fMax - fMin);
}