jenes.algorithms
Class SimpleGA<T extends Chromosome>

java.lang.Object
  extended by jenes.GeneticAlgorithm<T>
      extended by jenes.algorithms.SimpleGA<T>
Type Parameters:
T - extends Chromosome

public abstract class SimpleGA<T extends Chromosome>
extends GeneticAlgorithm<T>

A facade providing a simple interface to GeneticAlgorithm.

SimpleGA implements a three stages genetic algorithm made of

The class provides a set of constructors by which to instantiate a SimpleGA algorithm. SimpleGA is abstract as the evalation of individuals is problem dependent. It is possible to subclass SimpleGA in different ways. For instance

  SimpleGA sga = new SimpleGA(pop, GENERATION_LIMIT) {
  
          protected void evaluateIndividual(Individual individual) {
      // Make your evaluation here ... 
    }
                        
   };
 
provides an anonimous inner subclass of SimpleGA.

Constructors allows to decide which selection method (i.e. Tournament or Roulette Wheel) or crossover method (i.e. One Point or Two Points) to adopt. Also crossover and mutation probability can be specified at constraction time.

SimpleGA is a GeneticAlgorithm subclass. Thus, it is possible to use all inheritated methods and properties. For example,

  sga.setElitism(10);
  sga.setMutationRate(0.2);
  sga.setBiggerIsBetter(false);
  sga.evolve();
 

Among the available method, there are those able to alter the algorithm's body. Although this is possible, we discourage from using them as this would result in lesser comphrensible code. Instead we suggest to directly subclass GeneticAlgorithm.

Since:
1.0
Version:
1.2
Author:
Luigi Troiano, Pierpaolo Lombardi, Giuseppe Pascale, Thierry Bodhuin

Nested Class Summary
static class SimpleGA.CrossoverMethod
          Provides the available crossover methods
static class SimpleGA.SelectionMethod
          Provides the available selection methods
 
Nested classes/interfaces inherited from class jenes.GeneticAlgorithm
GeneticAlgorithm.ElitismStrategy, GeneticAlgorithm.ResizeStrategy, GeneticAlgorithm.Statistics
 
Field Summary
static SimpleGA.CrossoverMethod DEFAULT_CROSSOVER_METHOD
          The default crossover method
static double DEFAULT_CROSSOVER_PROBABILITY
          The default crossover probability
static int DEFAULT_ELITISM
          The default elitism factor
static GeneticAlgorithm.ElitismStrategy DEFAULT_ELITISM_STRATEGY
          The default elitism strategy
static int DEFAULT_GENERATION_LIMIT
          The default generation limit
static double DEFAULT_MUTATION_PROBABILITY
          The default mutation probability
static SimpleGA.SelectionMethod DEFAULT_SELECTION_METHOD
          The default selection method
 
Fields inherited from class jenes.GeneticAlgorithm
algorithmListeners, body, DEFAULT_HISTORY_SIZE, elitism, elitismStrategy, generation, generationLimit, generationListeners, initialPopulation, MAX_HISTORY_SIZE, MIN_HISTORY_SIZE, random, randomization, resizeStrategy, statistics
 
Constructor Summary
SimpleGA(Population<T> population)
          Builds a new SimpleGa with the default generation limit, crossover and mutation probability, elitism, selection and crossover methods, and elitism strategy.
SimpleGA(Population<T> population, int generations)
          Builds a new SimpleGa with the default crossover and mutation probability, elitism, selection and crossover methods, and elitism strategy.
SimpleGA(Population<T> population, int generations, double crossover, double mutation)
          Builds a new SimpleGa with the default elitism, selection and crossover methods, and elitism strategy.
SimpleGA(Population<T> population, int generations, double crossover, double mutation, int elitism)
          Builds a new SimpleGa with the default selection and crossover methods, and elitism strategy.
SimpleGA(Population<T> population, int generations, double crossover, double mutation, int elitism, SimpleGA.SelectionMethod selmethod, SimpleGA.CrossoverMethod crossmethod)
          Builds a new SimpleGa with the default elitism strategy.
SimpleGA(Population<T> population, int generations, double crossover, double mutation, int elitism, SimpleGA.SelectionMethod selmethod, SimpleGA.CrossoverMethod crossmethod, GeneticAlgorithm.ElitismStrategy es)
          Builds a new SimpleGa.
 
Method Summary
 Crossover<T> getCrossover()
          Returns the crossover used by this genetic algorithm.
 double getCrossoverProbability()
          Returns the crossover probability.
 double getMaxIllegalRate()
          Returns the maximum rate of illegal individuals.
 double getMutationProbability()
          Returns the mutation probability.
 Mutator<T> getMutator()
          Returns the mutator used by this genetic algorithm.
 Selector<T> getSelector()
          Returns the selector used by this genetic algorithm
 void setCrossoverProbability(double p)
          Sets the crossover probability.
 void setMaxIllegalRate(double rate)
          Sets the max rate of illegal individuals.
 void setMutationProbability(double p)
          Sets the mutation probability.
 
Methods inherited from class jenes.GeneticAlgorithm
addAlgorithmEventListener, addGenerationEventListener, addStage, applyElitism, end, evaluateIndividual, evaluatePopulation, evolve, evolve, getBody, getCurrentPopulation, getElitism, getElitismStrategy, getGeneration, getGenerationLimit, getHistoryAt, getHistorySize, getInitialPopulation, getNextPopulation, getRandomization, getResizeStrategy, getStatistics, isBiggerBetter, onGeneration, onInit, onStart, onStop, randomizeIndividual, randomizePopulation, removeAlgorithmEventListener, removeGenerationEventListener, setBiggerIsBetter, setElitism, setElitismStrategy, 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
 

Field Detail

DEFAULT_GENERATION_LIMIT

public static final int DEFAULT_GENERATION_LIMIT
The default generation limit

See Also:
Constant Field Values

DEFAULT_CROSSOVER_PROBABILITY

public static final double DEFAULT_CROSSOVER_PROBABILITY
The default crossover probability

See Also:
Constant Field Values

DEFAULT_MUTATION_PROBABILITY

public static final double DEFAULT_MUTATION_PROBABILITY
The default mutation probability

See Also:
Constant Field Values

DEFAULT_ELITISM

public static final int DEFAULT_ELITISM
The default elitism factor

See Also:
Constant Field Values

DEFAULT_SELECTION_METHOD

public static final SimpleGA.SelectionMethod DEFAULT_SELECTION_METHOD
The default selection method


DEFAULT_CROSSOVER_METHOD

public static final SimpleGA.CrossoverMethod DEFAULT_CROSSOVER_METHOD
The default crossover method


DEFAULT_ELITISM_STRATEGY

public static final GeneticAlgorithm.ElitismStrategy DEFAULT_ELITISM_STRATEGY
The default elitism strategy

Constructor Detail

SimpleGA

public SimpleGA(Population<T> population)
Builds a new SimpleGa with the default generation limit, crossover and mutation probability, elitism, selection and crossover methods, and elitism strategy.

Parameters:
population - the initial population

SimpleGA

public SimpleGA(Population<T> population,
                int generations)
Builds a new SimpleGa with the default crossover and mutation probability, elitism, selection and crossover methods, and elitism strategy.

Parameters:
population - the initial population
generations - the generation limit

SimpleGA

public SimpleGA(Population<T> population,
                int generations,
                double crossover,
                double mutation)
Builds a new SimpleGa with the default elitism, selection and crossover methods, and elitism strategy.

Parameters:
population - the initial population
generations - the generation limit
crossover - the crossover probability
mutation - the mutation probability

SimpleGA

public SimpleGA(Population<T> population,
                int generations,
                double crossover,
                double mutation,
                int elitism)
Builds a new SimpleGa with the default selection and crossover methods, and elitism strategy.

Parameters:
population - the initial population
generations - the generation limit
crossover - the crossover probability
mutation - the mutation probability
elitism - the elisitm factor

SimpleGA

public SimpleGA(Population<T> population,
                int generations,
                double crossover,
                double mutation,
                int elitism,
                SimpleGA.SelectionMethod selmethod,
                SimpleGA.CrossoverMethod crossmethod)
Builds a new SimpleGa with the default elitism strategy.

Parameters:
population - the initial population
generations - the generation limit
crossover - the crossover probability
mutation - the mutation probability
elitism - the elisitm factor
selmethod - the selector method to use
crossmethod - the crossover method to use

SimpleGA

public SimpleGA(Population<T> population,
                int generations,
                double crossover,
                double mutation,
                int elitism,
                SimpleGA.SelectionMethod selmethod,
                SimpleGA.CrossoverMethod crossmethod,
                GeneticAlgorithm.ElitismStrategy es)
Builds a new SimpleGa.

Parameters:
population - the initial population
generations - the generation limit
crossover - the crossover probability
mutation - the mutation probability
elitism - the elisitm factor
selmethod - the selector method to use
crossmethod - the crossover method to use
es - the elitism strategy to use
Method Detail

getSelector

public final Selector<T> getSelector()
Returns the selector used by this genetic algorithm

Returns:
the selection operator

getMaxIllegalRate

public final double getMaxIllegalRate()
Returns the maximum rate of illegal individuals.

Returns:
the maximum rate of illegal individuals

setMaxIllegalRate

public final void setMaxIllegalRate(double rate)
Sets the max rate of illegal individuals. This prevents that population will be dominated by invalid individuals. This is the case of constrained problems where valid solutions are sparse within the search space.

Parameters:
rate - the new maximum rate of illegal individuals

getCrossover

public final Crossover<T> getCrossover()
Returns the crossover used by this genetic algorithm.

Returns:
the crossover operator

getCrossoverProbability

public final double getCrossoverProbability()
Returns the crossover probability.

Returns:
the crossover probability

setCrossoverProbability

public final void setCrossoverProbability(double p)
Sets the crossover probability.

Parameters:
p - the new crossover probability

getMutator

public final Mutator<T> getMutator()
Returns the mutator used by this genetic algorithm.

Returns:
the mutation operator

getMutationProbability

public final double getMutationProbability()
Returns the mutation probability.

Returns:
the mutation probability

setMutationProbability

public final void setMutationProbability(double p)
Sets the mutation probability.

Parameters:
p - the new mutation probability