CS472 Evolutionary Computation
Assignment 2
(An experiment with the basic GA and block structured problems)
150 points
DUE: Wed Oct 15 at 5pm PST


The purpose of this exercise is to get more practice with the basic form of the code for evolutionary algorithms and look at additively separable problems. We will introduce a few more concepts. So this is another warm up. This time we will work with population, crossover, selection, and competition.

The problem

The problem is to find the all-ones solution in a problem whose bit domain is broken into blocks of consecutive bits. The fitness function is parameterized by both the number of bits in length, L, (always 32 for this problem) and by B, the blocksize. We do not require that B divide L evenly. To evaluate the fitness of an L bit string, the string is broken up into L/B blocks of adjacent bits each B in size starting with the least significant bit. If the last block of B bits does not fit evenly into L then the remainder of the bits (at the most significant end) will form a block of size less than B. The fitness is the number of blocks that have all their bits set to one.

For example: if L=12 and B=3 then fitness(100111101111) is 2 since the string is broken up as: 100 111 101 111 which has 2 blocks of all ones.
If L=32 and B=4 then the maximum fitness is 8.
if L=32 and B=3 then the maximum fitness is 11 with the last block being a 2 bit block.
Note that the gray code idea is irrelvant for this problem.

Here is a possible implementation in C for this fitness function:

int computerFitness(int bits, int blocksize)
{
    unsigned int block;   // a mask for each block
    int fitness;          // fitness accumulator

    fitness = 0; 
    block = (1<<blocksize)-1;
    while (block) { 
        if ((bits&block) == block) fitness++;
        block <<= blocksize;   // shift to next block position
    }

    return fitness;
}

The problem

Write a program named ga that finds the global optimum to the fitness function. The program should take on the command line (not from standard input):

For example when compiled I should be able to call your program: ga 3 ux .1 100 32 3
would find the optimum for 3 bit blocks using 10% chance of uniform xover and a population of 32 and tournament size of 3. The algorithm would be run 100 times. The algorithm will print the bitstring with the best score for the each at the end of each trial and at the end of the run print the mean and standard deviation of the number of evaluations it took to find the solution. If none found in a trail then use the maximum number of evaluations.

The output of the program will be EXACTLY AS FOLLOWS:

  1. two asterisks,
  2. your last name, all lower case, that you use to submit your program
  3. the number of bits per block
  4. the xover method used
  5. the xover probability as a decimal number between 0 and 1
  6. the number of trials
  7. the population size
  8. the tournament size
  9. the mean number of evaluations until the optimum is found or the limit of the number of evaluations is exceeded,
  10. the standard deviation of that number. (HINT: the standard deviation of a sample set can be calculated as:

    sqrt((sum2 - sum*sum/numSamples)/(numSamples-1))

    where sum2 is the sum of the squares of the samples and sum is the sum of the samples. Note this doesn't work if the numSamples == 1 so I guarantee that the number of trials will be >1.

For example the output might be:

** darwin 3 ux .1 100 32 3 3.14159 2.71828
Do not output anything else.

The Experiments

Algorithm Parameters

Steady State
initial population: random
selection: tournament
xover: 2pt or UX (see below)
probability of xover: various/td>
mutation: 1/L bit flipping
competition: replace worst in separate tournament
halting condition: When optima found or when
200000 evaluations reached

1/L bit flipping mutation is where each bit has a probability of 1/L of being flipped for an L bit string. If L=32 then this is 1/32. Note: this means that no bits will be flipped with a probability of (31/32)^L. For large L this means (1-1/L)^L --> e^-1 or about a 37% chance of no change. Also more than one bit can be flipped.

Use your program to try at these values:
Num Trials 100
population size: 8 and 64
Xover probabilities 0, .1, .5, .9, 1.0
Xover ux and 2pt
Block Size 1, 2, 4, 8, 16
Block Size 1, 2, 4, 8, 16
Tournament Size 2, 3, 5
and report your findings in pdf using less than a page using the report.pdf in your tar file. Be sure your name is on your paper. Thanks. I will be looking for any observations you can make about the experiments I proposed and guesses on why you saw the results you saw. Feel free to comment on any other experiments you ran.

Outline of the Steady Algorithms from Class

      initialize P = { X_1, X_2, ... X_n }   // population & initialization
      computeFitness of P 
      while (not goodenough(P)) {                // stopping criteria 
      	  X_i, X_j  = select(P)              // selection
	  if (rand() < xoverProb) {
	  	  X' = xover(X_i, X_j)       // recombination
	  }
	  X' = mutate(X')                    // mutate
	  computeFitness(X')                 // fitness
          insert(P, X')                      // compete
      }

Submission

Homework will be submitted as an uncompressed tar file to the homework submission page. You can submit as many times as you like. The LAST file you submit BEFORE the deadline will be the one graded. For all submissions you will receive email giving you some automated feedback on the unpacking and compiling and running of code and other things that can be autotested. I will read the results of the runs and the reports you submit.


Robert Heckendorn Last updated: Sep 19, 2004 20:40