flickr - Ethan Hein

Putting things together

With all these procedures, we can for example, implement a program which iterates through generations of evolution on its own using genetic algorithm. For simplicity, to do this, we may define the following functions -

The fitness function
is defined as
where it returns the level of fitness of the chromosome as a number. In the process of evaluating the fitness, the program shall first convert chromosome information into a proposed solution, then test the solution to see its fitness.
is the selection function. It selects a chromosome from the population
of chromosomes from current generation. The probablity of a particular chromosome being chosen is determined by the selection methods discussed above and as well as the fitness of that particular chromosome, that is
from the array
.
The crossover function
simply crossovers two chromosomes
and
to form a new one.
After crossover is completed,
is called. It mutates the chromosome
into a new one.
The function
creates a new population
. The number of chromosomes in
is determined by
;
populates
with chromosomes with random informations;
adds chromosome
to population
;
returns whether population
is completely filled.

Finally, the pseudo-code is the following -

   
;
   
;

    do

        for each
in

            
;        // evaluates fitness for each
.
       
;

        do

           
;
            /* selects from
according to the fitness
             * of each chromosome using the data in array

             * crossovers then mutates, adds the offspring to
*/
        until
;
       
;            // the offsprings are now parents
    while
;        // continues evolving...
 
A good tutorial to programming genetic algorithm in any software engineering applications -
http://www.obitko.com/tutorials/genetic-algorithms/