In this tutorial we shows how to use SimpleGA, a standard GeneticAlgorithm subclass. It represents the classical configuration of a genetic algorithm, using only the main operators (selector, crossover and mutator) in a very simple pipe. It's useful when no complex operators are needed and a fast ga set-up is required. The goal of this tutorial is to minimize the Shannon entropy of a set of values within the range [0,1].
A DoubleChromosome is suitable for this problem with each allele within the range [0,1].
To use SimpleGA we have to define only the fitness function coding. In this case the fitness of each individual is equal to the entropy value according to the classical entropy definition: entropy is the measure of the amount of information that is missing before reception and is sometimes referred to as Shannon entropy.SimpleGA our genetic algorithm is already configured regarding the operators to use. By default it uses tournament selection (attemps = 2), one-point crossover (probability = 0.8) and simple mutator (probability = 0.2). Besides SimpleGA uses by default a random replacing strategy for elitism. Anyway, it's possibile to modify this default configuration providing different parameters to operators and/or a different elitism strategy. In our case we use the default SimpleGA configuration.
The whole configuration code is listed below:
As you can see, the genetic algorithm has been initialized without the definition of the fitness function to use. This is possibile in that cases in wich the fitness could be determinated only at a later time in respect the creation of the genetic algorithm. Anyway the definition of a fitness function it required before the evolve method of GeneticAlgorithm is invoked, and this is possible just making the following method call: