26template <
typename Genotype,
typename FitnessT>
30 if (offspring.size() != mu) {
31 throw std::invalid_argument(
"GenerationalReplacement: offspring.size() must equal mu");
42template <
typename Genotype,
typename FitnessT>
46 if (population.size() + offspring.size() < mu) {
47 throw std::invalid_argument(
48 "MuPlusLambdaReplacement: population.size() + offspring.size() must be >= mu");
50 std::vector<Individual<Genotype, FitnessT>> combined = population;
51 combined.insert(combined.end(), std::make_move_iterator(offspring.begin()),
52 std::make_move_iterator(offspring.end()));
53 std::partial_sort(combined.begin(), combined.begin() +
static_cast<std::ptrdiff_t
>(mu),
55 [](
const auto& a,
const auto& b) { return a.fitness > b.fitness; });
66template <
typename Genotype,
typename FitnessT>
70 if (offspring.size() < mu) {
71 throw std::invalid_argument(
"MuCommaLambdaReplacement: offspring.size() must be >= mu");
73 std::partial_sort(offspring.begin(), offspring.begin() +
static_cast<std::ptrdiff_t
>(mu),
75 [](
const auto& a,
const auto& b) { return a.fitness > b.fitness; });
A genetic-algorithm candidate solution: a genotype paired with its fitness.
Definition acquisition_functions.hpp:16
std::vector< Individual< Genotype, FitnessT > > GenerationalReplacement(const std::vector< Individual< Genotype, FitnessT > > &, std::vector< Individual< Genotype, FitnessT > > offspring, size_t mu)
Generational replacement (DEAP's eaSimple): the offspring pool becomes the entire next generation; po...
Definition survivor_selection.hpp:27
std::vector< Individual< Genotype, FitnessT > > MuCommaLambdaReplacement(const std::vector< Individual< Genotype, FitnessT > > &, std::vector< Individual< Genotype, FitnessT > > offspring, size_t mu)
(mu,lambda) replacement: the next generation is the fittest mu individuals from offspring only (popul...
Definition survivor_selection.hpp:67
std::vector< Individual< Genotype, FitnessT > > MuPlusLambdaReplacement(const std::vector< Individual< Genotype, FitnessT > > &population, std::vector< Individual< Genotype, FitnessT > > offspring, size_t mu)
(mu+lambda) replacement: the next generation is the fittest mu individuals from population union offs...
Definition survivor_selection.hpp:43
A single candidate solution in a genetic algorithm population.
Definition individual.hpp:25