org.apache.commons.math.genetics
public class GeneticAlgorithm extends Object
Modifier and Type | Field and Description |
---|---|
private CrossoverPolicy |
crossoverPolicy
the crossover policy used by the algorithm.
|
private double |
crossoverRate
the rate of crossover for the algorithm.
|
private int |
generationsEvolved
the number of generations evolved to reach
StoppingCondition in the last run. |
private MutationPolicy |
mutationPolicy
the mutation policy used by the algorithm.
|
private double |
mutationRate
the rate of mutation for the algorithm.
|
private static RandomGenerator |
randomGenerator
Static random number generator shared by GA implementation classes.
|
private SelectionPolicy |
selectionPolicy
the selection policy used by the algorithm.
|
Constructor and Description |
---|
GeneticAlgorithm(CrossoverPolicy crossoverPolicy,
double crossoverRate,
MutationPolicy mutationPolicy,
double mutationRate,
SelectionPolicy selectionPolicy) |
Modifier and Type | Method and Description |
---|---|
Population |
evolve(Population initial,
StoppingCondition condition)
Evolve the given population.
|
CrossoverPolicy |
getCrossoverPolicy()
Returns the crossover policy.
|
double |
getCrossoverRate()
Returns the crossover rate.
|
int |
getGenerationsEvolved()
Returns the number of generations evolved to
reach
StoppingCondition in the last run. |
MutationPolicy |
getMutationPolicy()
Returns the mutation policy.
|
double |
getMutationRate()
Returns the mutation rate.
|
static RandomGenerator |
getRandomGenerator()
Returns the (static) random generator.
|
SelectionPolicy |
getSelectionPolicy()
Returns the selection policy.
|
Population |
nextGeneration(Population current)
Evolve the given population into the next generation.
|
static void |
setRandomGenerator(RandomGenerator random)
Set the (static) random generator.
|
private static RandomGenerator randomGenerator
setRandomGenerator(RandomGenerator)
to supply an alternative
to the default JDK-provided PRNG.private final CrossoverPolicy crossoverPolicy
private final double crossoverRate
private final MutationPolicy mutationPolicy
private final double mutationRate
private final SelectionPolicy selectionPolicy
private int generationsEvolved
StoppingCondition
in the last run.public GeneticAlgorithm(CrossoverPolicy crossoverPolicy, double crossoverRate, MutationPolicy mutationPolicy, double mutationRate, SelectionPolicy selectionPolicy)
crossoverPolicy
- The CrossoverPolicy
crossoverRate
- The crossover rate as a percentage (0-1 inclusive)mutationPolicy
- The MutationPolicy
mutationRate
- The mutation rate as a percentage (0-1 inclusive)selectionPolicy
- The SelectionPolicy
public static void setRandomGenerator(RandomGenerator random)
random
- random generatorpublic static RandomGenerator getRandomGenerator()
public Population evolve(Population initial, StoppingCondition condition)
generationsEvolved
property with the number of generations evolved before the StoppingCondition
is satisfied.initial
- the initial, seed population.condition
- the stopping condition used to stop evolution.public Population nextGeneration(Population current)
Evolve the given population into the next generation.
current
generation, using its nextGeneration methodcurrent
getCrossoverRate()
, apply
configured CrossoverPolicy
to parentsgetMutationRate()
, apply
configured MutationPolicy
to each of the offspringcurrent
- the current population.public CrossoverPolicy getCrossoverPolicy()
public double getCrossoverRate()
public MutationPolicy getMutationPolicy()
public double getMutationRate()
public SelectionPolicy getSelectionPolicy()
public int getGenerationsEvolved()
StoppingCondition
in the last run.Copyright (c) 2003-2014 Apache Software Foundation