next up previous

4.2.5 Inner Loop: Building the Next Generation

Building the next generation is very similar to the same procudure in the asexual simulations. The main differences are that we need to select two parents at random; instead of simply copying one parent's genes we need to call the new procedure that combines their genes; and we need the new procedure that inserts mutations into the genome of a surviving child.

The outline of the build_next_generation procedure is:

  limit = n * r;
  for (i = 0; i < limit; i++) {
    mom = random() % n;
    dad = random() % n;
    nm = poisson(mu);
    if (survivor(g[nkids]),nm) {
      nkids += 1;
      if (nkids == K)
The procedure call survivor(kid) will compute the relative fitness of the child, compare it to a random number, and return 1 (true) if the child survives. Note that for efficiency we make sure the child survives before actually inserting the mutations.