1#ifndef BOUNDARY_MUTATION_H
2#define BOUNDARY_MUTATION_H
21 template <
typename GeneType>
34 : lower_m(lower), upper_m(upper) {}
42 if (mutation_rate <= 0.0)
return;
44 thread_local static std::random_device rd;
45 thread_local static std::mt19937 gen(rd());
46 std::uniform_real_distribution<double> prob(0.0, 1.0);
47 std::uniform_int_distribution<int> coin(0, 1);
49 std::vector<GeneType>& genotype = individual.
getGenotype();
51 for (std::size_t i = 0; i < genotype.size(); ++i) {
52 if (prob(gen) < mutation_rate) {
53 genotype[i] = (coin(gen) == 0) ? lower_m : upper_m;
Performs boundary mutation.
void mutate(Individual< GeneType > &individual, double mutation_rate) override
Randomly resets genes to lower or upper bounds.
BoundaryMutation(GeneType lower, GeneType upper)
Constructs a boundary mutation operator.
Represents a single candidate solution in the population.
std::vector< GeneType > & getGenotype()
Returns a reference to the genotype vector.
Interface for mutation operators.