double Chromosome::getFitness () { if (evaluated) return fitness; else { fitness = evaluate(); if (!hit && fitness > getMaxFitness()) { hit = true; hitnfe = nfe+lsnfe; } return fitness; } }
void GTPopulation::selection() { matingPool.clear(); float maxFitness{getMaxFitness()}; //sort(begin(organisms), end(organisms), [](GTOrganism* a, GTOrganism* b){ return a->fitness < b->fitness; }); //matingPool.push_back(organisms[0]); //return; for(const auto& o : organisms) { float fitnessNormal{getMapped<float>(o->fitness, 0.f, getClamped(maxFitness, 0.f, 999.f), 0.f, 1.f)}; int n{static_cast<int>(pow((1 - fitnessNormal), bias) * (150 * (bias * 2)))}; n = max(1, n); for(int i{0}; i < n; ++i) matingPool.push_back(o); } }