Example #1
0
  Individual<Phenotype, Genotype> mutate(Individual<Phenotype, Genotype> i,
                                         const Codec<Phenotype, Genotype>& codec) override
  {
    Population<Phenotype, Genotype> children;
    children.reserve(numChildren_);

    for (std::size_t k = 0; k < numChildren_; ++k)
    {
      children.emplace_back(mutation_->mutate(i, codec));
    }

    PopulationFitness f = fitness_->calculate(children);
    auto maxFitnessIt = std::max_element(f.begin(), f.end());
    Individual<Phenotype, Genotype>& best = children[maxFitnessIt - f.begin()];
    return std::move(best);
  }