Modeling asexual reproduction is simple: each child is an exact duplicate of its parent, so to create a new individual just copy the integer that represents the parent. As mutations are introduced, they simply add to the count of the number of mutations in the child.
To model sexual reproduction, we need to model the underlying process of recombination. The easiest way to describe this is through an example. In this and later examples we will write the genes as two strings of 1s and 0s, with one string on the top line and the other string directly below it. A locus will correspond to a single column, i.e. locus i will be the two characters found in the ith column.
Suppose two individuals have the following genes:
01110... 00010.... 00010... 00111...Recall that each locus of a child is formed by taking one gene from each parent. Thus to form column i of the child, we pick randomly from column i of each parent to get the two genes that will make up column i of the child.