Top Description Fields Constructors Methods
org.apache.commons.math3.genetics

public Class UniformCrossover<T>

extends Object
implements CrossoverPolicy
Class Inheritance
All Implemented Interfaces
org.apache.commons.math3.genetics.CrossoverPolicy
Type Parameters
<T>
generic type of the AbstractListChromosomes for crossover
Imports
java.util.ArrayList, .List, org.apache.commons.math3.exception.DimensionMismatchException, .MathIllegalArgumentException, .OutOfRangeException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.random.RandomGenerator

Perform Uniform Crossover [UX] on the specified chromosomes. A fixed mixing ratio is used to combine genes from the first and second parents, e.g. using a ratio of 0.5 would result in approximately 50% of genes coming from each parent. This is typically a poor method of crossover, but empirical evidence suggests that it is more exploratory and results in a larger part of the problem space being searched.

This crossover policy evaluates each gene of the parent chromosomes by chosing a uniform random number p in the range [0, 1]. If p < ratio, the parent genes are swapped. This means with a ratio of 0.7, 30% of the genes from the first parent and 70% from the second parent will be selected for the first offspring (and vice versa for the second offspring).

This policy works only on AbstractListChromosome, and therefore it is parameterized by T. Moreover, the chromosomes must have same lengths.

Since
3.1
See Also
Crossover techniques (Wikipedia), Crossover (Obitko.com), Uniform crossover

Field Summary

Modifier and TypeField and Description
private final double
ratio

The mixing ratio.

Constructor Summary

AccessConstructor and Description
public
UniformCrossover(final double
the mixing ratio
ratio
)

Creates a new UniformCrossover policy using the given mixing ratio.

Method Summary

Modifier and TypeMethod and Description
public ChromosomePair
crossover(final Chromosome
the first chromosome.
first
,
final Chromosome
the second chromosome.
second
)

Implements org.apache.commons.math3.genetics.CrossoverPolicy.crossover.

Perform a crossover operation on the given chromosomes.

public double

Returns:

the mixing ratio
getRatio
()

Returns the mixing ratio used by this CrossoverPolicy.

private ChromosomePair

Returns:

the pair of new chromosomes that resulted from the crossover
mate
(final AbstractListChromosome<T>
the first chromosome
first
,
final AbstractListChromosome<T>
the second chromosome
second
)

Helper for crossover(Chromosome, Chromosome).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ratioback to summary
private final double ratio

The mixing ratio.

Constructor Detail

UniformCrossoverback to summary
public UniformCrossover(final double ratio) throws OutOfRangeException

Creates a new UniformCrossover policy using the given mixing ratio.

Parameters
ratio:double

the mixing ratio

Exceptions
OutOfRangeException:
if the mixing ratio is outside the [0, 1] range

Method Detail

crossoverback to summary
public ChromosomePair crossover(final Chromosome first, final Chromosome second) throws DimensionMismatchException, MathIllegalArgumentException

Implements org.apache.commons.math3.genetics.CrossoverPolicy.crossover.

Doc from org.apache.commons.math3.genetics.CrossoverPolicy.crossover.

Perform a crossover operation on the given chromosomes.

Parameters
first:Chromosome

the first chromosome.

second:Chromosome

the second chromosome.

Returns:ChromosomePair

the pair of new chromosomes that resulted from the crossover.

Annotations
@SuppressWarnings:unchecked
Exceptions
DimensionMismatchException:
if the length of the two chromosomes is different
MathIllegalArgumentException:
iff one of the chromosomes is not an instance of AbstractListChromosome
getRatioback to summary
public double getRatio()

Returns the mixing ratio used by this CrossoverPolicy.

Returns:double

the mixing ratio

mateback to summary
private ChromosomePair mate(final AbstractListChromosome<T> first, final AbstractListChromosome<T> second) throws DimensionMismatchException

Helper for crossover(Chromosome, Chromosome). Performs the actual crossover.

Parameters
first:AbstractListChromosome<T>

the first chromosome

second:AbstractListChromosome<T>

the second chromosome

Returns:ChromosomePair

the pair of new chromosomes that resulted from the crossover

Exceptions
DimensionMismatchException:
if the length of the two chromosomes is different