Class PatternGA

  extended by jenes.GeneticAlgorithm<IntegerChromosome>
      extended by jenes.tutorials.problem2.PatternGA

public class PatternGA
extends GeneticAlgorithm<IntegerChromosome>

Tutorial showing how to extend GeneticAlgorithm and how to use the flexible and configurable breeding structure in Jenes. The problem consists in searching a pattern of integers with a given precision. Solutions flow through two different crossovers in parallel. Some are processed by a single point crossover, the other by a double point crossover. After solutions are mutated. This class implements the algorithm by extending GeneticAlgorithm.

Luigi Troiano, Pierpaolo Lombardi

Nested Class Summary
Nested classes/interfaces inherited from class jenes.GeneticAlgorithm
GeneticAlgorithm.ElitismStrategy, GeneticAlgorithm.ResizeStrategy, GeneticAlgorithm.Statistics
Field Summary
Fields inherited from class jenes.GeneticAlgorithm
algorithmListeners, body, DEFAULT_GENERATION_LIMIT, DEFAULT_HISTORY_SIZE, elitism, elitismStrategy, fullEvaluationForced, generation, generationLimit, generationListeners, initialPopulation, MAX_HISTORY_SIZE, MIN_HISTORY_SIZE, random, randomization, resizeStrategy, statistics
Constructor Summary
PatternGA(Population<IntegerChromosome> pop, int numGen)
Method Summary
protected  boolean end()
          Provides the algorithm termination condition.
 void evaluateIndividual(Individual<IntegerChromosome> individual)
          Evaluates a single individual.
 void setPrecision(int precision)
 void setTarget(int[] target)
Methods inherited from class jenes.GeneticAlgorithm
addAlgorithmEventListener, addGenerationEventListener, addStage, applyElitism, evaluatePopulation, evaluatePopulation, evolve, evolve, evolve, getBody, getCurrentPopulation, getElitism, getElitismStrategy, getGeneration, getGenerationLimit, getHistoryAt, getHistorySize, getInitialPopulation, getNextPopulation, getRandomization, getResizeStrategy, getStatistics, isBiggerBetter, isFullEvaluationForced, onGeneration, onInit, onStart, onStop, randomizeIndividual, randomizePopulation, removeAlgorithmEventListener, removeGenerationEventListener, setBiggerIsBetter, setElitism, setElitismStrategy, setFullEvaluationForced, setGenerationLimit, setHistorySize, setRandomization, setRandomization, setResizeStrategy, start, stop, toString, updateStatistics
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail


public PatternGA(Population<IntegerChromosome> pop,
                 int numGen)
Method Detail


public void setTarget(int[] target)


public void setPrecision(int precision)


public void evaluateIndividual(Individual<IntegerChromosome> individual)
Description copied from class: GeneticAlgorithm
Evaluates a single individual. This evaluation of individuals is specifically related to the problem to solve, thus it is an abstract method requiring an implementation by the sublass.

Specified by:
evaluateIndividual in class GeneticAlgorithm<IntegerChromosome>
individual - the individual to be evaluated


protected boolean end()
Description copied from class: GeneticAlgorithm
Provides the algorithm termination condition. By default it returns false as reaching the generation limit is the sole ending criterion Subclasses can override this method in order to provide a problem specific termination condition.

end in class GeneticAlgorithm<IntegerChromosome>
true if the ga evolution reached the termination condition, false otherwise