Jenes offers the possibility to use local genetic algorithm goals. The global goal is that used by GeneticAlgorithm
during the evolution of the population in its main sequence of stages.
Instead, local goal is that used by the single stage (e.g. A sequence
contained in a parallel branch, etc..). This tutorials shows how to
solve the knapsack problem defining two different parallel sequences
with different inner goals. The aim of the knapsack problem is to
maximize the total utility of the items within the bag without exceeding
the maximum capacity of the bag. We have n items each one with has a
footprint and an utility value. Package: jenes.tutorial.problem6 Files: KnapsackProblem.java KnapsackGA.java 1. Choose a problem suitable chromosome and create the initial populationA candidate solution is a set of items with a weight and a utility. The solutions are coded using a boolean chromosome. The boolean values tells if an item is present or not inside the bag. For example if the i-th gene is true, then the i-th item is in the bag. A chromosome with all the genes having a false value represents an empty bag, while a chromosome with all the genes having a true value represents a bag with all the possible items.
2. Set-up the genetic algorithmWe implement the KnapsackGA class by subclassing GeneticAlgorithm and implementing the evaluation method.
The fitness of each solution is equal to the sum of the utilities of the
items it contains. If the total weight exceeds the capacity of the bag,
then the individual is set as illegal.3. Choose the operators to be used by genetic algorithm and add them as stages in the gaWe decide to process differently legal and illegal individuals. Therefore we create a sequence, called seq_legal, to process legal individual and a sequence, called seq_illegal, to process illegal individuals. These sequences have the same body ( tournament selector, one point crossover and simple mutator ), but different goals. Infact, the goal of seq_legal is to maximize the fitness of the legal individuals, while that of seq_illegal is to minimize the fitness of the illegal individuals in order to remove excess items and make the individual legal.We evolve in parallel legal and illegal individuals and at each generation we pass the legal solutions to seq_legal and the illegal solutions to seq_illegal through the use of an exclusive dispenser .
|
Tutorials >