next up previous

5.1 Variable Genome Length     continued...

All mutations are to the left of the locus pointed to by flp. Every procedure that needs to access the genome, including the code that counts mutations and the code that combines genes, can be written so that it only uses the portion of the genome to the left of flp. In the loops that iterate over the words in the genome, we can use a variable named gl to control the number of words to access. gl will initially be set to 1. Whenever flp crosses over a word boundary as new mutations are added we need to add 1 to gl, thus increasing the effective length of the genome.

As an example, consider the population shown in Figure 3. Suppose we want to mate two individuals. The structure of the unoptimized code is

    for (i = 0; i < 3; i++ {
      child[i][0] = combine(mom[i]);
      child[i][1] = combine(dad[i]);
In the optimized code, we can replace the constant 3 with the variable gl as long as all the loci in the child are initialized with 0s. When gl is 1, as in the figure, only one words worth of loci are actually combined and stored in child; the other two words worth of loci remain 0. This optimization works because calling combine for values of i greater than 1 would create all 0s anyway.