next up previous

4.1.5 Inner Loop: Building the Next Generation     continued...

r is often very large compared to k; in the extreme cases k is 2 and r is 10,000. In these situations it does not make sense to create all potential offspring only to draw k at random to fill up the new generation. Instead, we use a loop that iterates a maximum of times and exit the loop as soon as k survivors are found. Note that during the meltdown phase fewer than k offspring will survive to form the next generation and the loop will exit after generating all potential offspring.

The outline of the build_next_generation procedure is:

  limit = n * r;			/* max number of iterations */
  for (i = 0; i < limit; i++) {
    j = random() % n;			/* select a random parent */
    mom = g[j];
    kid = mom + poisson(mu);		/* kid is a clone of mom */
    if (survivor(kid)) {		/*   plus new mutations */
      ng[nkids] = kid;
      nkids = nkids + 1;
      if (nkids == k)			/* exit loop if the new gen */
        break;				/*   now has k individuals */
    }
  }
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.