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

public Class OnePointCrossover<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, org.apache.commons.math3.exception.util.LocalizedFormats

One point crossover policy. A random crossover point is selected and the first part from each parent is copied to the corresponding child, and the second parts are copied crosswise. Example:
-C- denotes a crossover point
                  -C-                                 -C-
p1 = (1 0 1 0 0 1  | 0 1 1)    X    p2 = (0 1 1 0 1 0  | 1 1 1)
     \------------/ \-----/              \------------/ \-----/
           ||         (*)                       ||        (**)
           VV         (**)                      VV        (*)
     /------------\ /-----\              /------------\ /-----\
c1 = (1 0 1 0 0 1  | 1 1 1)    X    c2 = (0 1 1 0 1 0  | 0 1 1)
This policy works only on AbstractListChromosome, and therefore it is parameterized by T. Moreover, the chromosomes must have same lengths.
Since
2.0

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ChromosomePair

Returns:

pair of two children (c1,c2)
crossover
(final Chromosome
first parent (p1)
first
,
final Chromosome
second parent (p2)
second
)

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

Performs one point crossover.

private ChromosomePair

Returns:

the pair of new chromosomes that resulted from the crossover.
crossover
(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

Constructor Detail

OnePointCrossoverback to summary
public OnePointCrossover()

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.

Performs one point crossover. A random crossover point is selected and the first part from each parent is copied to the corresponding child, and the second parts are copied crosswise. Example:

-C- denotes a crossover point
                  -C-                                 -C-
p1 = (1 0 1 0 0 1  | 0 1 1)    X    p2 = (0 1 1 0 1 0  | 1 1 1)
     \------------/ \-----/              \------------/ \-----/
           ||         (*)                       ||        (**)
           VV         (**)                      VV        (*)
     /------------\ /-----\              /------------\ /-----\
c1 = (1 0 1 0 0 1  | 1 1 1)    X    c2 = (0 1 1 0 1 0  | 0 1 1)
Parameters
first:Chromosome

first parent (p1)

second:Chromosome

second parent (p2)

Returns:ChromosomePair

pair of two children (c1,c2)

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
crossoverback to summary
private ChromosomePair crossover(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