next up previous
Next: Discussion Up: GAGSa flexible Previous: Applications

How to program using GAGS


In this section we will describe how to set up a GA using the library, step by step.

First of all, the population must be created: {setup Setting up a population

A population object called people is created, with numChroms chromosomes, each one of size (in genes) NUMGENES; each gene has got SIZEGENES bits; the mutation rate will be 1% (0.01). The replacement strategy is steady state (setElite), subtituting 20% of the population (0.2) each generation. An iterator censo is added to the population, so that loops can be run over it. A view vista is added to the population, so that each chromosome can be seen as an array of SIZEGENES floating point numbers with a range -1.0, 1.0.

Then, a GA is run on the population (see figure 4. In this case, it is a simple evaluation function: the sum of all the genes; the optimum will be when all values of the genes is 1.

{ga Running a GA 

The GA is run for a number of preset GENERATIONS. The iterator is reset, so that it points to the first member of the population, then the while loop runs over the population evaluating each member. The fitness is assigned to the current member of the population, which at the same times arease is from the ``non-evaluated members'' list and sends it to the ordered ``evaluated members list''. eval is an iterator over this list. Using vista, the first member of the list, which will be the chromosome with the higher fitness, is printed, along with its fitness, which is used as key for list sorting.

Generational substitution takes place in the method Population::newGeneration(); 20% of the population remains, while the rest is substituted by offspring of these lucky ones.

next up previous
Next: Discussion Up: GAGSa flexible Previous: Applications

[JJ J. J. Merelo *[E-MAIL]
Equipo GeNeura -- GeNeura Team
Departamento de Electrónica y Tecnología de los Computadores
Universidad de Granada Granada (Espaņa)
Phone: +34-58-243162; Fax: +34-58-243230