Module io.jenetics.ext
Package io.jenetics.ext
Class TreeCrossover<G extends TreeGene<?,G>,C extends Comparable<? super C>>
java.lang.Object
io.jenetics.AbstractAlterer<G,C>
io.jenetics.Recombinator<G,C>
io.jenetics.ext.TreeCrossover<G,C>
- All Implemented Interfaces:
Alterer<G,
C>
- Direct Known Subclasses:
SingleNodeCrossover
public abstract class TreeCrossover<G extends TreeGene<?,G>,C extends Comparable<? super C>>
extends Recombinator<G,C>
Abstract implementation of tree base crossover recombinator. This class
simplifies the implementation of tree base crossover implementation, by doing
the transformation of the flattened tree genes to actual trees and vice versa.
Only the
crossover(TreeNode, TreeNode)
method must be implemented.- Since:
- 3.9
- Version:
- 3.9
-
Field Summary
Fields inherited from class io.jenetics.AbstractAlterer
_probability
Fields inherited from interface io.jenetics.Alterer
DEFAULT_ALTER_PROBABILITY
-
Constructor Summary
ModifierConstructorDescriptionprotected
TreeCrossover
(double probability) Constructs a tree crossover with a given recombination probability. -
Method Summary
Methods inherited from class io.jenetics.Recombinator
alter, order
Methods inherited from class io.jenetics.AbstractAlterer
probability
-
Constructor Details
-
TreeCrossover
Constructs a tree crossover with a given recombination probability.- Parameters:
probability
- the recombination probability- Throws:
IllegalArgumentException
- if theprobability
is not in the valid range of[0, 1]
-
-
Method Details
-
recombine
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 TreeGene<?,
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
Template method which performs the crossover. The arguments given are mutable non-null trees.- Type Parameters:
A
- the existential allele type- Parameters:
that
- the first (chromosome) treeother
- he second (chromosome) tree- Returns:
- the number of altered genes
-