Init version
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
#include "NeutralEvolutionBreedStrat.h"
|
||||
#include "../../individual/Phenotype.h"
|
||||
#include "../../processor/Settings.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
void NeutralEvolutionBreedingStrategy::breed(Population* _pop){
|
||||
|
||||
BisexualPopulation* pop = dynamic_cast<BisexualPopulation*>(_pop);
|
||||
if(pop == NULL){
|
||||
std::cerr<<"Wrong dynamic cast to BisexualPopulation\n";
|
||||
return;
|
||||
}
|
||||
|
||||
int numMales = pop->males.size();
|
||||
int numFemales = pop->females.size();
|
||||
int inds = numMales + numFemales;
|
||||
|
||||
srand((unsigned int)time(NULL));
|
||||
//srand(0);
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int toDie = int (inds * deathRate);
|
||||
for(int i = 0; i < toDie; i++){
|
||||
int indToDie = rand() % (inds-i);
|
||||
if(indToDie < numMales){
|
||||
std::list<Individual*>::iterator it = pop->males.begin();
|
||||
std::advance(it,indToDie); // it += indToDie;
|
||||
delete *it;
|
||||
pop->males.erase(it);
|
||||
numMales--;
|
||||
}
|
||||
else{
|
||||
std::list<Individual*>::iterator it = pop->females.begin();
|
||||
std::advance(it,indToDie-numMales); // it += indToDie;
|
||||
delete *it;
|
||||
pop->females.erase(it);
|
||||
numFemales--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//std::cout<<"PopulationBreedingStrategy::breed: "<<toDie<<" individs have died\n";
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
int toBorn = int (inds * birthRate);
|
||||
numMales = pop->males.size();
|
||||
numFemales = pop->females.size();
|
||||
inds = numMales + numFemales;
|
||||
|
||||
for(int i = 0; i < toBorn; i++) {
|
||||
int fatherNum = rand() % numMales;
|
||||
int motherNum = rand() % numFemales;
|
||||
int gender = rand() % 2;
|
||||
|
||||
std::list<Individual*>::iterator itFather = pop->males.begin();
|
||||
std::advance(itFather, fatherNum);
|
||||
std::list<Individual*>::iterator itMother = pop->females.begin();
|
||||
std::advance(itMother, motherNum);
|
||||
|
||||
Genotype* genotype;
|
||||
|
||||
double prob = Settings::ProbMtDNARecomb;
|
||||
if(prob > 0.0){
|
||||
int invProb = (int)(1/prob);
|
||||
int recombine = rand() % invProb;
|
||||
if(recombine == 0){
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//std::cerr<<"Recomb\n";
|
||||
ChromosomeRearrangementStrategy* recombinator = RecombinationStrategies::getInstance("dummy");
|
||||
HaploidGenotype recombGenotype = recombinator->buildRecombinantGenotype(
|
||||
(*itFather)->getGenotype().getMotherGenome(), (*itMother)->getGenotype().getMotherGenome());
|
||||
genotype = new Genotype(recombGenotype, recombGenotype);
|
||||
}
|
||||
else{
|
||||
genotype = new Genotype(
|
||||
(*itMother)->getGenotype().getMotherGenome(), (*itMother)->getGenotype().getMotherGenome());
|
||||
}
|
||||
}
|
||||
else{
|
||||
genotype = new Genotype(
|
||||
(*itMother)->getGenotype().getMotherGenome(), (*itMother)->getGenotype().getMotherGenome());
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
|
||||
Phenotype* phenotype= new Phenotype((*itFather)->getPhenotype());
|
||||
|
||||
Individual* ind = new Individual(genotype, phenotype, 0, Individual::Gender(gender));
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20>.<2E>.
|
||||
if(gender == 0){
|
||||
pop->males.push_back(ind);
|
||||
}
|
||||
else{
|
||||
pop->females.push_back(ind);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user