|
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.
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;
}
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):
The output of the program will be EXACTLY AS FOLLOWS:
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.71828Do not output anything else.
| 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 |
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
}
| Robert Heckendorn | Last updated: |