1#ifndef UNIFORM_MUTATION_H
2#define UNIFORM_MUTATION_H
20 template <
typename GeneType>
33 : lower_m(lower), upper_m(upper) {}
41 if (mutation_rate <= 0.0)
return;
43 thread_local static std::random_device rd;
44 thread_local static std::mt19937 gen(rd());
45 std::uniform_real_distribution<GeneType> value_dist(lower_m, upper_m);
46 std::uniform_real_distribution<double> prob(0.0, 1.0);
48 std::vector<GeneType>& genotype = individual.
getGenotype();
50 for (std::size_t i = 0; i < genotype.size(); ++i) {
51 if (prob(gen) < mutation_rate) {
52 genotype[i] = value_dist(gen);
Represents a single candidate solution in the population.
std::vector< GeneType > & getGenotype()
Returns a reference to the genotype vector.
Interface for mutation operators.