68 lines
2.2 KiB
C++
68 lines
2.2 KiB
C++
#include "AbstractIndividual.h"
|
|
#include "genome/strategies/GenotypeToPhenotypeStrategy.h"
|
|
#include <iostream>
|
|
|
|
Individual::Individual(const Individual& father, const Individual& mother)
|
|
{
|
|
this->genToPhenStrategy = GenotypeToPhenotypeStrategies::getInstance("inoutbreeding");
|
|
this->phenToFitStrategy = PhenotypeToFitnessStrategy::getInstance("inoutbreeding");
|
|
this->recombinationStrategy = RecombinationStrategies::getInstance("Simple recombination");
|
|
|
|
genotype = new Genotype(
|
|
father.getGenotype().recombinantHaploidGenotype(recombinationStrategy),
|
|
mother.getGenotype().recombinantHaploidGenotype(recombinationStrategy));
|
|
// Ìîæíî ñäåëàòü ðåêîìáèíàöèîííûå ñòðàòåãèè ïàïû è ìàìû ðàçíûå
|
|
|
|
// Ñóáñòðàòíûé êýø äîäåëàòü
|
|
this->substrateCache = new InnerSubstratesPool();
|
|
|
|
phenotype= new Phenotype(father.getPhenotype());
|
|
this->age = 0;
|
|
this->calculateFitness();
|
|
|
|
}
|
|
|
|
Individual::Individual(Genotype* gType, Phenotype* pType, InnerSubstratesPool* sub, Gender _gender, Region* _reg):
|
|
genotype(gType), phenotype(pType), substrateCache(sub),
|
|
gender(_gender), region(_reg)
|
|
{
|
|
this->genToPhenStrategy = GenotypeToPhenotypeStrategies::getInstance("inoutbreeding");
|
|
this->phenToFitStrategy = PhenotypeToFitnessStrategy::getInstance("inoutbreeding");
|
|
this->recombinationStrategy = RecombinationStrategies::getInstance("Simple recombination");
|
|
|
|
this->age = 0;
|
|
|
|
//this->calculateFitness();
|
|
//this->phenotype
|
|
}
|
|
|
|
|
|
Individual::~Individual(){
|
|
// std::cerr<<"Destructor works"<<std::endl;
|
|
delete this->genotype;
|
|
delete this->phenotype;
|
|
|
|
delete this->genToPhenStrategy;
|
|
delete this->phenToFitStrategy;
|
|
delete this->recombinationStrategy;
|
|
|
|
if(this->substrateCache != 0)
|
|
delete this->substrateCache;
|
|
}
|
|
|
|
/*bool compareOnFitness(const Individual& a, const Individual& b){
|
|
return a.getFitness() < b.getFitness();
|
|
}*/
|
|
|
|
bool compareOnFitness(const Individual* a, const Individual* b){
|
|
return a->getFitness() < b->getFitness();
|
|
}
|
|
|
|
void Individual::calculateFitness(){
|
|
this->genToPhenStrategy->calculatePhenotype(this);
|
|
this->fitness = this->phenToFitStrategy->calculateFitness(this->phenotype);
|
|
}
|
|
|
|
void Individual::calculatePhenotype(){
|
|
this->genToPhenStrategy->calculatePhenotype(this);
|
|
} |