38 const std::vector<GeneType>& parent1_genotype = parent1.
getGenotype();
39 const std::vector<GeneType>& parent2_genotype = parent2.
getGenotype();
41 if (parent1_genotype.size() != parent2_genotype.size()) {
42 throw std::invalid_argument(
"Parents must have the same genotype length for crossover.");
44 std::size_t genotype_size = parent1_genotype.size();
49 if (genotype_size > 1) {
50 thread_local static std::random_device rd;
51 thread_local static std::mt19937 gen(rd());
53 std::uniform_int_distribution<std::size_t> distribution(1, genotype_size - 1);
54 std::size_t crossover_point = distribution(gen);
56 std::vector<GeneType>& child1_genotype = child1.
getGenotype();
57 std::vector<GeneType>& child2_genotype = child2.
getGenotype();
60 child1_genotype.begin() + crossover_point,
61 child1_genotype.end(),
62 child2_genotype.begin() + crossover_point
65 return std::make_pair(child1, child2);