Exploring Crossover
Genetic Algorithms in Elixir — by Sean Moriarity (51 / 101)
👈 Solving N-Queens with Order-One Crossover | TOC | Implementing Other Common Crossover Strategie s 👉
With the N-queens problem, you saw how much choosing the correct crossover strategy can affect your algorithms. Now, you need to develop an understanding of what crossover is and how it works.
Crossover is analogous to reproduction — the process of combining the genes of two chromosomes to create new chromosomes. The idea is that solutions will combine to create even better solutions — like how evolution slowly optimizes organisms to adapt and become stronger in their environment.
While the parallels between biological reproduction and crossover are neither perfect nor sound, you can better understand crossover if you have a general understanding of biology. In biology, traits are passed down to children from parents. These traits, for example, include hair color, eye color, and muscle composition. If both parents possess the same traits, the child is more likely to inherit those traits from their parents.
Now, imagine two sets of parents. One set of parents consists of two world-class distance runners. The other set of parents consists of two world-class weightlifters. Which set of parents is more likely to produce a better distance runner? The set of distance runners, because they possess and are more likely to pass on traits that contribute to success in distance running.
The same idea applies to crossover in genetic algorithms. Your goal is to take the strongest traits present in two solutions and pass them on to child solutions. Over time, your strategy will produce a fitter population.
The crossover strategy you use can have a big impact on the performance of your algorithm. Strategies are very problem-dependent. Some strategies are designed with certain genotypes in mind. Other strategies are built for speed or simplicity. In the next section, you’ll see how crossover can impact the performance of a genetic algorithm.
👈 Solving N-Queens with Order-One Crossover | TOC | Implementing Other Common Crossover Strategie s 👉
Genetic Algorithms in Elixir by Sean Moriarity can be purchased in other book formats directly from the Pragmatic Programmers. If you notice a code error or formatting mistake, please let us know here so that we can fix it.

