This tutorial shows how to use the ObjectChromosome in Jenes. The
ObjectChromosome represents a complex chromosome with genes containing
an object allele value. Given a search space made of object chromosome
variables, we aim at finding the nearest sequence of values
(representable with specified objects) to a target one. In our example
problem each chromosome has five genes belonging to different object
allele values. The first gene is an integer in the range [0,9], the
second is also an integer but in the range [10,30], the third is a real
number in the range [0,1], the fourth is a boolean and the last is a
gene which alphabet is {BLACK, RED, WHITE } Package: jenes.tutorial.problem5 Files: OCProblem.java Color.java DoubleAlleleSet.java IntegerAlleleSet.java. 1. Choose a problem suitable chromosome and create the initial population;An ObjectChromosome is suitable for this problem. It will have five genes each of them with a different allele set: two integer allele sets for the first two genes, the first with the range [0,9] and the second with range [10,30], a double allele set for the third gene with range [0,1], a boolean allele set for the forth gene and an enumeration based allele set containing {BLACK, RED, WHITE } for the last gene.To instantiate an allele set we can implement the AlleleSet interface or use the GenericAlleleSet class. The integer allele set is obtained by subclassing the GenericAlleleSet class and implementing two factory methods, used to instantiate the integer values in their specified ranges (the values are chosen at random or with a uniform probability distribution within the specified ranges). The real allele set is obtained in the same way. The boolean allele set is obtained by creating a GenericAlleleSet object containg the boolean values "true" and "false". Finally, we define an enumeration, called Color, containing the values "BLACK", "RED" and "WHITE", then we create a GenericAlleleSet object with the values of Color enumeration. The code is showed below. We can now build our chromosome representation.
2. Set-up the genetic algorithmThe code to evaluate an individual in our problem is shown below.
In our example the best individuals are those with the highest values
for the integer and double genes, with a true value for the boolean gene
and with any value for the "Color" gene.Therefore, the best individual that we expect running this example could be: [ 9, 30, 0.99, true, BLACK ]. 3. Choose the operators to be used by genetic algorithm and add them as stages in the gaIn this tutorial we use the classical simple algorithm configuration.
4. Customize the genetic algorithmThe global genetic algorithm goal is to maximize the fitness values. The whole code is visible in the files listed above. |
Tutorials >