Skip to content

Commit

Permalink
Update Population.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
cppnuts-yt committed Aug 23, 2016
1 parent 1260b19 commit d7a58b9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Population.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ class Population{
int generation;
bool finished;
Dna target;
float mutatoinRate;
float mutationRate;
float perfectScore = 1;
public:
Population(Dna target,float mutationRate):target{target},mutatoinRate{mutatoinRate},finished{false}{}
Population(Dna target):target{target},finished{false}{

}

void setMutationRate(float mr){mutationRate=mr;}

void initializePopulation(int popMax){
int len = target.gens.length();
Expand Down Expand Up @@ -61,6 +65,7 @@ class Population{
float n = floor(elem.fitness/max);
for(int i=0; i<n*100; i++){
matingPool.push_back(elem);

}
}
}
Expand All @@ -71,7 +76,7 @@ class Population{
Dna partnerA = matingPool[a];
Dna partnerB = matingPool[b];
Dna child = partnerA.crossover(partnerB);
child.mutate(mutatoinRate);
child.mutate(this->mutationRate);
population[i] = child;
}
}
Expand Down

0 comments on commit d7a58b9

Please sign in to comment.