﻿ Chapter 6 - Programming Your Genetic Algorithms Using the DLL > The Evolutionary Loop

# The Evolutionary Loop

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

# The Evolutionary Loop

 At this point in the example, we have created a population of individuals, described the structure of each individual, initialized each individual with random chromosome values, and constructed the fitness function.  Evolution may now proceed.   The first step in the evolutionary loop is to retrieve the values of the chromosomes of each individual with the help of the GetChromosome function.  After we have retrieved all of an individual’s chromosome values, we should call the fitness function to calculate the fitness of this individual.  Afterwards, we should put the calculated value into the DLL structure with the help of the PutFitness function.  Obviously, the fitnesses of all individuals in the population should be calculated and should be put into the DLL.  For example, if we have 50 individuals in the population, each having 3 chromosomes, we should call the GetChromosome function 3 times, then calculate the fitness function.  We should repeat this procedure 50 times.  This process will result in 150 calls of the GetChromosome function and 50 calls of the fitness function.   At this point, a determination must be made about whether or not to stop the GA from running.  We defer the details of that decision to the next section.   The next step is to call the Reproduce function, which makes a new population out of the previous one with the help of the crossover and mutation operators (described briefly in Chapter 2 and in detail in Appendix A).  The parameters for these procedures are set with the help of the SetOperators function.  This call is optional, however, because GeneHunter can use default parameters for the operators.   After creating a new population out of the previous one by calling the Reproduce function, all fitnesses should be calculated once again.  Only then can we recall the Reproduce function.  A typical program includes a loop in which we recalculate fitnesses and make new generations out of previous ones.