T
- extends Chromosomepublic class SimpleGA<T extends Chromosome> extends GeneticAlgorithm<T>
SimpleGA
implements a three stages genetic algorithm made of
TournamentSelector
(default) or RouletteWheelSelector
OnePointCrossover
(default) or TwoPointsCrossover
SimpleMutator
SimpleGA
algorithm.
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
.
Modifier and Type | Class and Description |
---|---|
static class |
SimpleGA.CrossoverMethod
Provides the available crossover methods
|
static class |
SimpleGA.SelectionMethod
Provides the available selection methods
|
GeneticAlgorithm.ElitismStrategy, GeneticAlgorithm.ResizeStrategy, GeneticAlgorithm.Statistics
Modifier and Type | Field and Description |
---|---|
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
|
algorithmListeners, body, DEFAULT_HISTORY_SIZE, elitism, elitismStrategy, fullEvaluationForced, generation, generationLimit, generationListeners, initialPopulation, MAX_HISTORY_SIZE, MIN_HISTORY_SIZE, random, randomization, resizeStrategy, statistics
Constructor and Description |
---|
SimpleGA()
Deprecated.
|
SimpleGA(Fitness<T> fitness,
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(Fitness<T> fitness,
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(Fitness<T> fitness,
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(Fitness<T> fitness,
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(Fitness<T> fitness,
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(Fitness<T> fitness,
Population<T> population,
int generations,
double crossover,
double mutation,
int elitism,
SimpleGA.SelectionMethod selmethod,
SimpleGA.CrossoverMethod crossmethod,
GeneticAlgorithm.ElitismStrategy es)
Builds a new SimpleGa.
|
SimpleGA(Population<T> population)
Deprecated.
|
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)
Deprecated.
|
SimpleGA(Population<T> population,
int generations,
double crossover,
double mutation,
int elitism)
Deprecated.
|
SimpleGA(Population<T> population,
int generations,
double crossover,
double mutation,
int elitism,
SimpleGA.SelectionMethod selmethod,
SimpleGA.CrossoverMethod crossmethod)
Deprecated.
|
SimpleGA(Population<T> population,
int generations,
double crossover,
double mutation,
int elitism,
SimpleGA.SelectionMethod selmethod,
SimpleGA.CrossoverMethod crossmethod,
GeneticAlgorithm.ElitismStrategy es)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
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.
|
addAlgorithmEventListener, addGenerationEventListener, addStage, applyElitism, end, evaluateIndividual, evaluatePopulation, evaluatePopulation, evolve, evolve, evolve, getBody, getCurrentPopulation, getElitism, getElitismStrategy, getFitness, getGeneration, getGenerationLimit, getHistoryAt, getHistorySize, getInitialPopulation, getLastPopulation, getNextPopulation, getPool, getRandomization, getResizeStrategy, getRunner, getStatistics, isBiggerBetter, isFitnessChanged, isFullEvaluationForced, onGeneration, onInit, onStart, onStop, randomizeIndividual, randomizePopulation, removeAlgorithmEventListener, removeGenerationEventListener, setBiggerIsBetter, setElitism, setElitismStrategy, setFitness, setFullEvaluationForced, setGenerationLimit, setHistorySize, setRandomization, setRandomization, setRandomSeed, setResizeStrategy, setRunner, start, stop, toString, updateStatistics
public static final int DEFAULT_GENERATION_LIMIT
public static final double DEFAULT_CROSSOVER_PROBABILITY
public static final double DEFAULT_MUTATION_PROBABILITY
public static final int DEFAULT_ELITISM
public static final SimpleGA.SelectionMethod DEFAULT_SELECTION_METHOD
public static final SimpleGA.CrossoverMethod DEFAULT_CROSSOVER_METHOD
public static final GeneticAlgorithm.ElitismStrategy DEFAULT_ELITISM_STRATEGY
@Deprecated public SimpleGA()
public SimpleGA(Fitness<T> fitness, Population<T> population)
fitness
- the fitness to usepopulation
- the initial populationpublic SimpleGA(Fitness<T> fitness, Population<T> population, int generations)
fitness
- the fitness to usepopulation
- the initial populationgenerations
- the generation limitpublic SimpleGA(Fitness<T> fitness, Population<T> population, int generations, double crossover, double mutation)
fitness
- the fitness to usepopulation
- the initial populationgenerations
- the generation limitcrossover
- the crossover probabilitymutation
- the mutation probabilitypublic SimpleGA(Fitness<T> fitness, Population<T> population, int generations, double crossover, double mutation, int elitism)
fitness
- the fitness to usepopulation
- the initial populationgenerations
- the generation limitcrossover
- the crossover probabilitymutation
- the mutation probabilityelitism
- the elisitm factorpublic SimpleGA(Fitness<T> fitness, Population<T> population, int generations, double crossover, double mutation, int elitism, SimpleGA.SelectionMethod selmethod, SimpleGA.CrossoverMethod crossmethod)
fitness
- the fitness to usepopulation
- the initial populationgenerations
- the generation limitcrossover
- the crossover probabilitymutation
- the mutation probabilityelitism
- the elisitm factorselmethod
- the selector method to usecrossmethod
- the crossover method to usepublic SimpleGA(Fitness<T> fitness, Population<T> population, int generations, double crossover, double mutation, int elitism, SimpleGA.SelectionMethod selmethod, SimpleGA.CrossoverMethod crossmethod, GeneticAlgorithm.ElitismStrategy es)
fitness
- the fitness to usepopulation
- the initial populationgenerations
- the generation limitcrossover
- the crossover probabilitymutation
- the mutation probabilityelitism
- the elisitm factorselmethod
- the selector method to usecrossmethod
- the crossover method to usees
- the elitism strategy to use@Deprecated public SimpleGA(Population<T> population)
population
- the initial populationpublic SimpleGA(Population<T> population, int generations)
population
- the initial populationgenerations
- the generation limit@Deprecated public SimpleGA(Population<T> population, int generations, double crossover, double mutation)
population
- the initial populationgenerations
- the generation limitcrossover
- the crossover probabilitymutation
- the mutation probability@Deprecated public SimpleGA(Population<T> population, int generations, double crossover, double mutation, int elitism)
population
- the initial populationgenerations
- the generation limitcrossover
- the crossover probabilitymutation
- the mutation probabilityelitism
- the elisitm factor@Deprecated public SimpleGA(Population<T> population, int generations, double crossover, double mutation, int elitism, SimpleGA.SelectionMethod selmethod, SimpleGA.CrossoverMethod crossmethod)
population
- the initial populationgenerations
- the generation limitcrossover
- the crossover probabilitymutation
- the mutation probabilityelitism
- the elisitm factorselmethod
- the selector method to usecrossmethod
- the crossover method to use@Deprecated public SimpleGA(Population<T> population, int generations, double crossover, double mutation, int elitism, SimpleGA.SelectionMethod selmethod, SimpleGA.CrossoverMethod crossmethod, GeneticAlgorithm.ElitismStrategy es)
population
- the initial populationgenerations
- the generation limitcrossover
- the crossover probabilitymutation
- the mutation probabilityelitism
- the elisitm factorselmethod
- the selector method to usecrossmethod
- the crossover method to usees
- the elitism strategy to usepublic final Selector<T> getSelector()
public final double getMaxIllegalRate()
public void setMaxIllegalRate(double rate)
rate
- the new maximum rate of illegal individualspublic final Crossover<T> getCrossover()
public final double getCrossoverProbability()
public void setCrossoverProbability(double p)
p
- the new crossover probabilitypublic final Mutator<T> getMutator()
public final double getMutationProbability()
public void setMutationProbability(double p)
p
- the new mutation probability