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]. Package: jenes.tutorials.problem4 Files: EntropyProblem.java EntropyFitness.java 1. Choose a problem suitable chromosome and create the initial population;A DoubleChromosome is suitable for this problem with each allele within the range [0,1].
55 Individual<DoubleChromosome> sample = new Individual<DoubleChromosome> (new DoubleChromosome(CHROMOSOME_LENGTH,0,1));
2. Set-up the genetic algorithm 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.
38 @Override 3. Choose the operators to be used by genetic algorithm and add them as stages in the gaWith 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.4. Customize the genetic algorithmThe whole configuration code is listed below: 55 Individual<DoubleChromosome> sample = new Individual<DoubleChromosome>(new DoubleChromosome(CHROMOSOME_LENGTH,0,1)); 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: 68 ga.setFitness(fitness);
|
Tutorials >