Cross Over
- "Sexual" reproduction combines the genes of two parents. In our
case, this is the mom and the dad.
- In a GA there are lots of ways to do this, but the code does it
by selecting the best PARENTS_BREEDING members of the population.
- It then randomly selects among them to find parents.
- Each time two parents breed, part of each is selected.
- A cross over point is randomly selected, then one child gets
mom's genes until the cross over point and dad's genes after.
The other child gets the reverse.
- So, if the alphabet is M and D, mom is MMMMM and dad is DDDDD, and the
crossover point is 2, then the children are MMDDD and DDMMM.
- In the code, getNextGeneration does this by calling the crossOver
function with the two parents.
- It's a bit tricky, but if you comment in the print in the crossOver
function (and it's easier with just one generation), you can see
how the new population is generated (though note mutate happens
afterward).