next up previous

4.2.4 Relative Fitness and Survival     continued...

Another ``trick'' is to use the exclusive OR operator to detect loci that have one but not two mutations, and use bitwise AND to find loci with two mutations. The following C code sets n1 to the number of heterozygous mutations in an individual, and n2 to the number of homozygous mutations:

  n1 = n2 = 0;
  for (i = 0, p0 = &x[0], p1 = &x[1]; i < glb; i++, p0++, p1++) {
    s = *p0 ^ *p1;
    n1 += bit_count[s];
    s = *p0 & *p1;
    n2 += bit_count[s];
  }
Here glb is the number of bytes in the genome (if your machine has 32-bit words and you are using the variable gl to count the number of words in the genome, glb == 4*gl). p0 and p1 are pointers to unsigned characters (you will have to cast them to suppress compiler warnings, or use some sophisticated type definitions). At the beginning of the loop they are initialized to point to the beginning of the first and second strand in individual x. Each time through the loop pick up one 8-bit segment and count the number of single mutations (at least one but not two bits of x equal 1) and double mutations (both bits are 1).

The survivor procedure must return 1 or 0, depending on whether the new offspring would survive if some number of new mutations are added to its genome. It totals the number of homozygous and heterozygous mutations, and then computes the fitness as

Because s is between 0 and 1 (as is the product of d and s) we know w will also be between 0 and 1, and the more mutations an individual has the lower the value of w.