T
- The class of chromosomes to work with.public abstract class Crossover<T extends Chromosome> extends Operator<T>
spread
parent and the same number of children; the operation is executed according to a crossover probability specified at the creation time.
The actual crossover is implemented by subclassing this abstract class and providing the spread
and cross(Individual[])
implementations: the former is required to specify the number of parents and children involved in each crossover operation; the
second is required to specify what crossover algorithm to use.
Offsprings have not to be created in the cross(Individual[])
method implementation: they
are provided by the specified array; these ones have to be modify according to the crossover strategy.
At the cross(Individual[])
invocation time, the abstract crossover makes each of the array individuals
equals to each one of the parents.
A Crossover.Statistics
is associated to each crossover operator.
Individual
,
Population
Modifier and Type | Class and Description |
---|---|
class |
Crossover.Statistics
A statistics object holding the number of crossover performed and the time spent to execute them.
|
Modifier and Type | Field and Description |
---|---|
protected double |
probability
Crossover probability
|
random, statistics
biggerIsBetter, fitness, ga
Constructor and Description |
---|
Crossover(double probability)
Constructs a new crossover instance with the specified crossover probability
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
cross(Individual<T>[] offsprings)
Executes the crossover.
|
double |
getProbability()
Returns the crossover probability
|
void |
init(GeneticAlgorithm<T> ga)
Initializes this stage according to the genetic algorithm
that uses it
|
void |
process(Population<T> in,
Population<T> out)
Processes the input population and tranforms it into the output population.
|
void |
setProbability(double probability)
Sets the crossover probability
|
abstract int |
spread()
Returns the number of individuals involved by this crossover operator
|
getStatistics, updateStatistics
dispose, getFitness, isBiggerBetter, isFitnessChanged, setBiggerIsBetter, setBiggerIsBetter, setFitness, setFitness
public Crossover(double probability)
probability
- public final double getProbability()
public final void setProbability(double probability)
probability
- the new crossover probabilitypublic abstract int spread()
public final void init(GeneticAlgorithm<T> ga) throws StageException
AbstractStage
init
in class AbstractStage<T extends Chromosome>
ga
- the Genetic Algorithm in wchic this stage runStageException
public final void process(Population<T> in, Population<T> out) throws StageException
AbstractStage
process
in class AbstractStage<T extends Chromosome>
in
- the input populationout
- the output populationStageException
protected abstract void cross(Individual<T>[] offsprings)
offsprings
- the individuals to be modified.