org.apache.commons.math.genetics
Class OnePointCrossover<T>

java.lang.Object
  extended by org.apache.commons.math.genetics.OnePointCrossover<T>
Type Parameters:
T - generic type of the AbstractListChromosomes for crossover
All Implemented Interfaces:
CrossoverPolicy

public class OnePointCrossover<T>
extends java.lang.Object
implements CrossoverPolicy

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    p2 = (0 1 1 0 1 0  | 0 1 1)
 
This policy works only on AbstractListChromosome, and therefore it is parametrized by T. Moreover, the chromosomes must have same lengths.

Since:
2.0
Version:
$Revision: 799857 $ $Date: 2009-08-01 09:07:12 -0400 (Sat, 01 Aug 2009) $

Constructor Summary
OnePointCrossover()
           
 
Method Summary
private  ChromosomePair crossover(AbstractListChromosome<T> first, AbstractListChromosome<T> second)
          Helper for crossover(Chromosome, Chromosome).
 ChromosomePair crossover(Chromosome first, Chromosome second)
          Performs one point crossover.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OnePointCrossover

public OnePointCrossover()
Method Detail

crossover

public ChromosomePair crossover(Chromosome first,
                                Chromosome second)
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 p2 = (0 1 1 0 1 0 | 0 1 1)

Specified by:
crossover in interface CrossoverPolicy
Parameters:
first - first parent (p1)
second - second parent (p2)
Returns:
pair of two children (c1,c2)

crossover

private ChromosomePair crossover(AbstractListChromosome<T> first,
                                 AbstractListChromosome<T> second)
Helper for crossover(Chromosome, Chromosome). Performs the actual crossover.

Parameters:
first - the first chromosome.
second - the second chromosome.
Returns:
the pair of new chromosomes that resulted from the crossover.


Copyright (c) 2003-2009 Apache Software Foundation