jenes.stage.operator
Class Crossover<T extends Chromosome>

java.lang.Object
  extended by jenes.stage.AbstractStage<T>
      extended by jenes.stage.operator.Operator<T>
          extended by jenes.stage.operator.Crossover<T>
Type Parameters:
T - The class of chromosomes to work with.
Direct Known Subclasses:
OnePointCrossover, TSPCityCenteredCrossover, TSPCrossover, TwoPointsCrossover

public abstract class Crossover<T extends Chromosome>
extends Operator<T>

A genetic class representing a crossover operator. This implementation represents a generic crossover operation with 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.

Since:
1.0
Version:
1.2
Author:
Luigi Troiano, Pierpaolo Lombardi, Giuseppe Pascale, Thierry Bodhuin
See Also:
Individual, Population

Nested Class Summary
 class Crossover.Statistics
          A statistics object holding the number of crossover performed and the time spent to execute them.
 
Field Summary
protected  double probability
          Crossover probability
 
Fields inherited from class jenes.stage.operator.Operator
random, statistics
 
Fields inherited from class jenes.stage.AbstractStage
biggerIsBetter, ga
 
Constructor Summary
Crossover(double probability)
          Constructs a new crossover instance with the specified crossover probability
 
Method Summary
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
protected abstract  int spread()
          Returns the number of individuals involved by this crossover operator
 
Methods inherited from class jenes.stage.operator.Operator
getStatistics, updateStatistics
 
Methods inherited from class jenes.stage.AbstractStage
dispose, isBiggerBetter, setBiggerIsBetter, setBiggerIsBetter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

probability

protected double probability
Crossover probability

Constructor Detail

Crossover

public Crossover(double probability)
Constructs a new crossover instance with the specified crossover probability

Parameters:
probability -
Method Detail

getProbability

public final double getProbability()
Returns the crossover probability

Returns:
the probability

setProbability

public final void setProbability(double probability)
Sets the crossover probability

Parameters:
probability - the new crossover probability

spread

protected abstract int spread()
Returns the number of individuals involved by this crossover operator

Returns:
the number of individuals required by crossover

init

public final void init(GeneticAlgorithm<T> ga)
                throws StageException
Description copied from class: AbstractStage
Initializes this stage according to the genetic algorithm that uses it

Overrides:
init in class AbstractStage<T extends Chromosome>
Parameters:
ga - the Genetic Algorithm in wchic this stage run
Throws:
StageException

process

public final void process(Population<T> in,
                          Population<T> out)
                   throws StageException
Description copied from class: AbstractStage
Processes the input population and tranforms it into the output population. Note: - Out population is made of recicled individuals. There is a need of new individuals to add only when there is a need to increase the population size. For pre-initalized individual just use setAs method. This is done for an efficient memory management. - A stage can modify the input population. So input passed to process method can be mutated when the process method ends.

Specified by:
process in class AbstractStage<T extends Chromosome>
Parameters:
in - the input population
out - the output population
Throws:
StageException

cross

protected abstract void cross(Individual<T>[] offsprings)
Executes the crossover. At the invocation time the specified array contains the individuals to be modify by cross; at the return time it contains the output crossover individuals.

Parameters:
offsprings - the individuals to be modified.