Package io.jenetics
Class Crossover<G extends Gene<?,G>,C extends Comparable<? super C>>
- java.lang.Object
-
- io.jenetics.AbstractAlterer<G,C>
-
- io.jenetics.Recombinator<G,C>
-
- io.jenetics.Crossover<G,C>
-
- Type Parameters:
G
- the gene type.
- All Implemented Interfaces:
Alterer<G,C>
- Direct Known Subclasses:
IntermediateCrossover
,LineCrossover
,MultiPointCrossover
,PartiallyMatchedCrossover
,UniformCrossover
public abstract class Crossover<G extends Gene<?,G>,C extends Comparable<? super C>> extends Recombinator<G,C>
Performs a Crossover of two
Chromosome
. This crossover implementation can handle genotypes with different length (different number of chromosomes). It is guaranteed that chromosomes with the the same (genotype) index are chosen for crossover.The order (
Recombinator.order()
) of this Recombination implementation is two.- Since:
- 1.0
- Version:
- 4.0
-
-
Field Summary
-
Fields inherited from class io.jenetics.AbstractAlterer
_probability
-
Fields inherited from interface io.jenetics.Alterer
DEFAULT_ALTER_PROBABILITY
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Crossover(double probability)
Constructs an alterer with a given recombination probability.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract int
crossover(MSeq<G> that, MSeq<G> other)
Template method which performs the crossover.protected int
recombine(MSeq<Phenotype<G,C>> population, int[] individuals, long generation)
Recombination template method.-
Methods inherited from class io.jenetics.Recombinator
alter, order
-
Methods inherited from class io.jenetics.AbstractAlterer
probability
-
-
-
-
Constructor Detail
-
Crossover
protected Crossover(double probability)
Constructs an alterer with a given recombination probability.- Parameters:
probability
- the recombination probability- Throws:
IllegalArgumentException
- if theprobability
is not in the valid range of[0, 1]
-
-
Method Detail
-
recombine
protected final int recombine(MSeq<Phenotype<G,C>> population, int[] individuals, long generation)
Description copied from class:Recombinator
Recombination template method. This method is called 0 to n times. It is guaranteed that this method is only called by one thread.- Specified by:
recombine
in classRecombinator<G extends Gene<?,G>,C extends Comparable<? super C>>
- Parameters:
population
- the population to recombineindividuals
- the array with the indexes of the individuals which are involved in the recombination step. The length of the array isRecombinator.order()
. The first individual is the primary individual.generation
- the current generation.- Returns:
- the number of genes that has been altered.
-
crossover
protected abstract int crossover(MSeq<G> that, MSeq<G> other)
Template method which performs the crossover. The arguments given are mutable non null arrays of the same length.- Parameters:
that
- the genes of the first chromosomeother
- the genes of the other chromosome- Returns:
- the number of altered genes
-
-