1#ifndef UNIFORM_CROSSOVER_H
2#define UNIFORM_CROSSOVER_H
21 template <
typename GeneType>
35 if (parent1.
size() != parent2.
size()) {
36 throw std::invalid_argument(
"Parents must have the same genotype size");
39 thread_local static std::random_device rd;
40 thread_local static std::mt19937 gen(rd());
41 thread_local static std::bernoulli_distribution pick_first(0.5);
52 for (std::size_t i = 0; i < g1.size(); ++i) {
53 if (pick_first(gen)) {
62 return {child1, child2};
Interface for crossover (recombination) operators.
Represents a single candidate solution in the population.
std::size_t size() const
Returns the number of genes in the genotype.
std::vector< GeneType > & getGenotype()
Returns a reference to the genotype vector.