diff --git a/src/genetic_algorithm.py b/src/genetic_algorithm.py index 91d9136..50d4306 100644 --- a/src/genetic_algorithm.py +++ b/src/genetic_algorithm.py @@ -146,13 +146,18 @@ def group_parents(parents): return parent_pairs -def crossover(mode, parents, m): +def crossover(mode, parents, m, probability=0.7): parent_groups = group_parents(parents) offspring = [] if mode == "uniform": - for element in parent_groups: + expected_crossovers = int(len(parents) * probability) + cutoff = expected_crossovers // 2 + for element in parent_groups[:cutoff]: offspring.append(uniform_crossover(element, m)) offspring.append(uniform_crossover(element, m)) + for element in parent_groups[cutoff:]: + offspring.append(element[0]) + offspring.append(element[1]) else: for element in parent_groups: first_offspring, second_offspring = position_crossover(element)