T
- generic type of the AbstractListChromosome
s for crossoverpublic class UniformCrossover<T> extends java.lang.Object implements CrossoverPolicy
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.
Modifier and Type | Field and Description |
---|---|
private double |
ratio
The mixing ratio.
|
Constructor and Description |
---|
UniformCrossover(double ratio)
Creates a new
UniformCrossover policy using the given mixing ratio. |
Modifier and Type | Method and Description |
---|---|
ChromosomePair |
crossover(Chromosome first,
Chromosome second)
Perform a crossover operation on the given chromosomes.
|
double |
getRatio()
Returns the mixing ratio used by this
CrossoverPolicy . |
private ChromosomePair |
mate(AbstractListChromosome<T> first,
AbstractListChromosome<T> second)
Helper for
crossover(Chromosome, Chromosome) . |
public UniformCrossover(double ratio) throws OutOfRangeException
UniformCrossover
policy using the given mixing ratio.ratio
- the mixing ratioOutOfRangeException
- if the mixing ratio is outside the [0, 1] rangepublic double getRatio()
CrossoverPolicy
.public ChromosomePair crossover(Chromosome first, Chromosome second) throws DimensionMismatchException, MathIllegalArgumentException
crossover
in interface CrossoverPolicy
first
- the first chromosome.second
- the second chromosome.MathIllegalArgumentException
- iff one of the chromosomes is
not an instance of AbstractListChromosome
DimensionMismatchException
- if the length of the two chromosomes is differentprivate ChromosomePair mate(AbstractListChromosome<T> first, AbstractListChromosome<T> second) throws DimensionMismatchException
crossover(Chromosome, Chromosome)
. Performs the actual crossover.first
- the first chromosomesecond
- the second chromosomeDimensionMismatchException
- if the length of the two chromosomes is differentCopyright (c) 2003-2016 Apache Software Foundation