#include "AbstractIndividual.h" #include "genome/strategies/GenotypeToPhenotypeStrategy.h" #include 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"<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); }