JGAP

org.jgap.impl
Class AveragingCrossoverOperator

java.lang.Object
  extended by org.jgap.BaseGeneticOperator
      extended by org.jgap.impl.AveragingCrossoverOperator
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable, GeneticOperator

public class AveragingCrossoverOperator
extends BaseGeneticOperator

The averaging crossover operator randomly selects two Chromosomes from the population and "mates" them by randomly picking a gene and then swapping that gene and all subsequent genes between the two Chromosomes. The two modified Chromosomes are then added to the list of candidate Chromosomes. This operation is performed half as many times as there are Chromosomes in the population. Additionally, the loci of crossing over are cached for each index, i.e., after randomizing the loci for each index once, they don't change again. If you work with CompositeGene's, this operator expects them to contain genes of the same type (e.g. IntegerGene). If you have mixed types, please provide your own crossover operator.

Since:
2.0
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.jgap.BaseGeneticOperator
m_monitor, m_monitorActive
 
Constructor Summary
AveragingCrossoverOperator()
          Using the same random generator for randomizing the loci for crossing over as for selecting the genes to be crossed over.
AveragingCrossoverOperator(Configuration a_configuration)
          Using the same random generator for randomizing the loci for crossing over as for selecting the genes to be crossed over.
AveragingCrossoverOperator(Configuration a_configuration, IUniversalRateCalculator a_crossoverRateCalculator)
          Constructs a new instance of this CrossoverOperator with a specified crossover rate calculator, which results in dynamic crossover being turned on.
AveragingCrossoverOperator(Configuration a_configuration, RandomGenerator a_generatorForAveraging)
          Using a different random generator for randomizing the loci for crossing over than for selecting the genes to be crossed over
 
Method Summary
 int compareTo(java.lang.Object a_other)
          Compares the given object to this one.
 boolean equals(java.lang.Object a_other)
          Compares this GeneticOperator against the specified object.
protected  int getLocus(RandomGenerator a_generator, int a_index, int a_max)
          Returns the crossover location for a given index.
 void operate(Population a_population, java.util.List a_candidateChromosomes)
          Crossover that acts as a perturbed mean of two individuals.
 void setCrossoverRate(int a_rate)
           
 
Methods inherited from class org.jgap.BaseGeneticOperator
getConfiguration
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AveragingCrossoverOperator

public AveragingCrossoverOperator()
                           throws InvalidConfigurationException
Using the same random generator for randomizing the loci for crossing over as for selecting the genes to be crossed over.

Attention: The configuration used is the one set with the static method Genotype.setConfiguration.

Throws:
InvalidConfigurationException
Since:
2.0

AveragingCrossoverOperator

public AveragingCrossoverOperator(Configuration a_configuration)
                           throws InvalidConfigurationException
Using the same random generator for randomizing the loci for crossing over as for selecting the genes to be crossed over.

Parameters:
a_configuration - the configuration to use
Throws:
InvalidConfigurationException
Since:
3.0

AveragingCrossoverOperator

public AveragingCrossoverOperator(Configuration a_configuration,
                                  RandomGenerator a_generatorForAveraging)
                           throws InvalidConfigurationException
Using a different random generator for randomizing the loci for crossing over than for selecting the genes to be crossed over

Parameters:
a_configuration - the configuration to use
a_generatorForAveraging - RandomGenerator to use
Throws:
InvalidConfigurationException
Since:
3.0 (since 2.0 without a_configuration)

AveragingCrossoverOperator

public AveragingCrossoverOperator(Configuration a_configuration,
                                  IUniversalRateCalculator a_crossoverRateCalculator)
                           throws InvalidConfigurationException
Constructs a new instance of this CrossoverOperator with a specified crossover rate calculator, which results in dynamic crossover being turned on.

Parameters:
a_configuration - the configuration to use
a_crossoverRateCalculator - calculator for dynamic crossover rate computation
Throws:
InvalidConfigurationException
Since:
3.0 (since 2.0 without a_configuration)
Method Detail

operate

public void operate(Population a_population,
                    java.util.List a_candidateChromosomes)
Crossover that acts as a perturbed mean of two individuals. x_i = p*x1_i + (1-p)*x2_i p - uniform random value over [0,1]. Averaging over line means p is same for every i, averaging over space if different p is chosen for each i. See CrossoverOperator for general description, also see feature request 708774

Parameters:
a_population - Chromosome[]
a_candidateChromosomes - List
Since:
2.0

getLocus

protected int getLocus(RandomGenerator a_generator,
                       int a_index,
                       int a_max)
Returns the crossover location for a given index. For each index the crossover locatio is the same, therefor it is cached!

Parameters:
a_generator - to generate random values the first time
a_index - the index of the crossover operation
a_max - upper boundary for random generator
Returns:
crossover location for a given index
Since:
2.0

equals

public boolean equals(java.lang.Object a_other)
Compares this GeneticOperator against the specified object. The result is true if and the argument is an instance of this class and is equal wrt the data.

Overrides:
equals in class BaseGeneticOperator
Parameters:
a_other - the object to compare against
Returns:
true: if the objects are the same, false otherwise
Since:
2.6

compareTo

public int compareTo(java.lang.Object a_other)
Compares the given object to this one.

Parameters:
a_other - the instance against which to compare this instance
Returns:
a negative number if this instance is "less than" the given instance, zero if they are equal to each other, and a positive number if this is "greater than" the given instance
Since:
2.6

setCrossoverRate

public void setCrossoverRate(int a_rate)
Parameters:
a_rate - crossover rate to use by this crossover operator
Since:
2.6

JGAP