### CS63 Fall 1005 Lab 10: Experimenting with Genetic Algorithms In class exercise only, nothing to handin

#### INTRODUCTION

In this lab you will learn how to use Pyro's implementation of various evolutionary algorithms. You will then perform a series of experiments to better understand how the parameters of a GA affect its ability to find solutions. You will also compare a GA to a simpler hill climbing method. These exercises are adapted from Melanie Mitchell's An Introduction to Genetic Algorithms.

#### LAB INSTRUCTIONS

• There is a collection of materials available online to help you learn how to use Pyro's evolutionary algorithms. Read through the first half of PyroModuleEvolutionaryAlgorithms. You can move on to the experiments below once you have reviewed the section on GA Implementation Details.

• EXPERIMENT 1:You will do a series of experiments for a problem, varying the mutation and crossover rates, to see how the variations affect the average time required for the GA to find the optimal string. Use the GAMaxBits.py example which we discussed in class as the basis for your experiments. Recall that it uses a fitness function that sums the number of ones in the bit string. Update this program in the following ways:
• The string length should be 100.
• The population size should be 100.
• Use an elite percentage of 0.05.
• Use single-point crossover with a rate of 0.7.
• Use a bitwise mutation rate of 0.001.
• Set the maximum generation to be 300.
Perform 10 runs, and compute the average generation at which the string of all ones is discovered. Perform the same experiment with crossover turned off. Do several other similar experiments, varying the mutation and crossover rates. Create a table to display the average results for each variation you tried. What can you conclude from these results?

• EXPERIMENT 2:You will do a series of experiments for a problem, keeping the mutation rate and crossover rate fixed while varying the population size. Copy the program from the previous experiment and update it to use a fitness function that interprets the bit string as a binary number. Change the isDone method to stop when the largest possible binary number has been found. Then set the remaining paramenters as follows:
• The string length should be 30.