CS44 W00: Homework 2

Assigned: Friday, January 14, 2000
Due: Sunday, January 23, 2000, at midnight. Create a directory called hmw1 with all your files and a separate file called best_gene. Email popescu@cs the path to that directory. Make sure the files are readable and executable by us.

Automated Design with Genetic Algorithms

In this assignment we will look at the genetic programming computational paradigm. The problem is about designing killer species that live in an imaginary world called PAC-world, created by Donald Knuth at Stanford University and used in AI classes at Stanford, Cornell, and Dartmouth.

PAC-world is inhabited by several species of tiny creatures called PAC-mites, all of which are engaged in a constant struggle for survival with every other species. Each individual mite lives out its short lifetime by following a small set of deterministic rules and interacting only with its immediate surroundings. However, in large numbers, the PAC-mites of a species combine to form complex patterns of behavior which enable them to compete with PAC-mites of other species. Your goal is to design a species that will annihilate every other species in this world in a one-on-one duel.

The laws of PAC-world:

  1. PAC-world consists of a grid of discrete cells measuring 21 cells horizontally by 11 cells vertically. The world is completely surrounded by insurmountable barriers that occupy the outermost cells. Therefore, the actual world measures 19 cells by 9 cells. (In the simulator the barriers are not displayed so only the 19x9 region is visible.)
  2. Each cell may be occupied by either a barrier, a blob (which is an empty cell) or a PAC-mite. The PAC-mites are represented by pacman-like symbols facing in any of the four directions. Each PAC-mite has an age (represented by the number of rings at its center) and is colored according to the species to which it belongs (in the simulator this is either blue or red.)
  3. Each PAC-mite may face in any of the four directions. Direction 0 is udes to indicate a right-facing mite, 1 indicates an upward-facing mite, 2 indicates a left-facing mite, and 3 indicates a down-facing mite. In addition, each mite is 0, 1, 2, or 3 rounds old, independently of direction. Thus, there are sixteen possible configurations for a PAC-mite of a given species.
  4. The contents of PAC-world changes deterministically in discrete steps of time called rounds. This transition function is completely local -- that is, the contents of a cell at time t + 1 depends only upon the content of that cell and its four neighbouring cells at time t. In this transition, which is described in item 7 below, each mite ages, possibly changes direction, possibly causes a baby mite to be born in the cell that it was facing, possibly dies, or is replaced by a mite of opposite species.
  5. The number of rings in a PAC-mite corresponds to both the age of the mite and its power. A ringless mite has just been born while a mite with three rings has been around for the past three rounds. All mites die after four time rounds so no mite has more than three rings.
  6. Each PAC-mite of a given species shares a common genetic code, which determines its behavior in the transition function. This genetic code consists of 50 genes, each of which may be 0, 1, 2, or 3. Thus there are 4^{50} possible species of PAC-mites. (In this discussion, a turn is a rotation of 90 degrees counter-clockwise; l represents an age between 0 and 3, e is the difference between directions of mites A and B (in the number of turns it takes A to face B's direction) and k is an age between 0 and 2. The genes and their general functions are:
  7. The transition function can be determined as follows:
  8. Here are a few examples to aid in the understanding of the PAC-world.

The Simulator

The simulator is located in ~popescu/AI/PacWar. The simulator is executed with the command pacwar.

  1. The Display menu controls the display of the simulation. You have three choices: small, medium, and large, which controls the size of the simulation display.
  2. The Test and Duel buttons allow you to switch between the two modes of the simulation. Test mode allows you to study the behavior of a single species in isolation (e.g., its growth patterns and gross behavior changes upon perturbing sets of genes). Duel mode allows you to run a duel between two species; you can specify the candidate species by selecting from the pop-up menu that appears when you click on one or the other's name.
  3. The Step button advances the current simulation by one round.

A running count of the population of the species is provided in the simulation display. The file PacWarGuts.c has the simulator functions you need to write the GA program. The display is set up to help you design appropriate representations for the GA and for you to develop a qualitative understanding of the interactions between the various parts of the genetic code of a species.

The rules for scoring duels between species are explained below. Duels will be help only between pairs of species. Duels will continue until one species has been completely eliminated, or until 500 time units have passed. If neither species has won after 500 time units, the relative populations of the two species will be used to determine the score of the duel. Each duel is worth a total of 20 points. These 20 points will be divided as follows:

Observe that this scoring system gives significant advantage to species that actually destroy the opposite species rather than just outnumbering them. This is the recommended fitness function for your GA species designer. You can experiment with other scores though.

Instructions for the assignment

To copy the pacwar directory to your account:

  1. Login to your computer science account on an SGI station* or a Linux machine (you can do this from any Unix console)
  2. Change your directory to the directory in which you want the pacwar directory to be placed (use the cd command)
  3. Enter: cp -r ~popescu/AI/PacWar/* .
  4. Enter: pacwar to run the pacwar simulator

To compile the genes program:

  1. Change your directory to the pacwar directory
  2. Enter: make

A driver for your GA is in the file genes.c. You can see a sample run by executing sample. Your job is to write the reproduction, cross-over, and mutation stages of the GA. The sample input and sample output are in sample.input and sample.output. You can enter the genes you generate in duels with the best Cornell and Stanford genes by pressing the Genes button in the simulation window. There will be a tournament between the genes discovered by the class.

* The program works on most SGI stations in Lab 001 and most Linux machines in 005. If all machines are occupied, you can also work on any UNIX console by remotely logining to a machine.

What to hand in

Hand in a listing of your genes.c program together with the best gene you found. Tell us how you found this gene. Make sure you comment on how you picked the initial population, the selection for mating mechanism, the crossover, and the mutation. Hand this in at the beginning of class, on Monday, January 24

Email a copy of your genes.c program and a file containing your name on the first line and your best gene on the second line. For full credit, email this information by 11pm on Sunday, January 23.

Grading

Correctness and Completness:                      50 points
Testing:                                          20 points
Written work:                                     20 points
Documentation:                                    10 points


Switch to:


vasilis@cs.dartmouth.edu