Crossover creates offspring by combining genes from two parent chromosomes. Think of each chromosome as a row of candidate-solution parts: an offspring takes some parts from one parent and the rest from the other. In a genetic algorithm, this happens after parent selection. Mutation may then make small random changes to the offspring. section 4.11 section 5.1
Cut and swap once
Suppose parent A is [1, 1, 0, 0] and parent B is [0, 0, 1, 1]. Cut both after the second gene. Joining A’s first part to B’s second gives [1, 1, 1, 1]; joining B’s first part to A’s second gives [0, 0, 0, 0]. This is single-point crossover: the same cut produces two opposite mixes. section 4.12
def one_point_crossover(parent_a, parent_b, xover_point):
children = [parent_a[:xover_point] #A
➥+ parent_b[xover_point:], #B
parent_b[:xover_point] #C
➥+ parent_a[xover_point:]] #D
return children
The Python example implements that cut with slices: each child joins a prefix from one parent to a suffix from the other. section 4.12
Different crossover methods choose inherited parts differently:
- Two-point crossover makes two cuts and takes the middle part from the other parent, like splicing arrays. section 4.13
- Uniform crossover uses a mask to choose a parent for each gene; an inverse mask can produce a second child. section 4.14
- Arithmetic crossover combines parents through an arithmetic operation. It is primarily suited to continuous-valued genes, such as weights or coordinates. section 5.8
Choose the method to suit the chromosome’s encoding and check that offspring remain valid solutions. The choice can encourage or discourage diversity. Arithmetic crossover needs particular care: averaging parents can move an offspring away from a precise, high-performing solution. section 4.20 section 5.8






