How to Build a Population

<< Click to Display Table of Contents >>

Navigation:  Chapter 6 - Programming Your Genetic Algorithms Using the DLL >

How to Build a Population

Previous pageReturn to chapter overviewNext page

As stated in Chapter 2 , genetic algorithms work with populations of individuals.  You can build programs with GeneHunter which can run as many as 128 populations simultaneously.  The first step in building a genetic algorithm is to call the GeneHunter function, MakePopulation, which allocates the memory necessary to store information about the population.


While calling the MakePopulation function, the user should specify the number of individuals in the population.  As we know, each individual can be treated as a set of chromosomes, while each chromosome corresponds to a particular parameter of a problem.  Each individual is a point in the search space, or more simply, an individual is a set of concrete values of chromosomes.


What this means is that the number of individuals determines the number of points that are considered by the algorithm at each step (at each generation).  The number of individuals also determines the diversity of the genetic set that exists in the population.  The more points we consider at one step, the smaller the probability of missing the best solution.  It seems preferable to make this number as large as possible, but the trade-offs are the increased time required to run the algorithm and the extra memory consumed.


The typical value of individuals in the population is 20-100.  More difficult problems usually require a larger number of individuals in the population.


One of the parameters of MakePopulation is the serial number.  The sample code uses a default serial number of 1000.  You must change 1000 to the serial number on your diskette in order for the code to run.

Nonspecific Population Numbers

It is good coding practice to use a variable instead of an explicit literal population number in the GeneHunter functions.  Before using MakePopulation, use the function GetNextPopulation to set the population number as an argument of the MakePopulation function.  The reason is that if you always code the same population number as 0, for example, then two programs running at the same time will conflict with each other.  Only one copy of GALIB32.DLL is used by all applications running under Windows.

Making Chromosomes

An individual is essentially a set of chromosomes, each of which corresponds to a particular parameter of an optimization problem.  Therefore, the next step is to specify a typical individual in the population.  Note that all individuals in the population have the same set of chromosomes, but the values stored in similar chromosomes of different individuals are different.  To describe a chromosome we call the MakeChromosome function, which will define each chromosome of an individual.  For example, if we have 50 individuals in the population, each having three chromosomes, we should call the MakeChromosome function three times, since the structure of all individuals is the same.

Setting Evolutionary Parameters

After the GA population and chromosome structures are defined, but before evolution begins, we must define for the GA exactly what type of genetic operators and evolution parameters should be used.  This is done by calling the SetOperators and SetStrategy functions once.  Advanced users, however, may want to call these functions during evolution as well.  For example, one interesting strategy might be to increase the rate of mutation if better fitnesses have not been found after some number of generations.


Refer to Chapter 8 for detailed discussions of SetOperators and SetStrategy.  To get you started, the following values for crossover, mutation, and generation gap are good defaults:


crossover = .9

mutation = .01

generation gap = .9