Package io.jenetics
Class PartialAlterer<G extends Gene<?,G>,C extends Comparable<? super C>>
- java.lang.Object
-
- io.jenetics.PartialAlterer<G,C>
-
- All Implemented Interfaces:
Alterer<G,C>
public final class PartialAlterer<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements Alterer<G,C>
This alterer wraps a given alterer which works on a given section of the genotype's chromosomes.If you are using chromosome indices which are greater or equal than the number of chromosomes defined in the genotype, a// The genotype prototype, consisting of 4 chromosomes final Genotype<DoubleGene> gtf = Genotype.of( DoubleChromosome.of(0, 1), DoubleChromosome.of(1, 2), DoubleChromosome.of(2, 3), DoubleChromosome.of(3, 4) ); // Define the GA engine. final Engine<DoubleGene, Double> engine = Engine .builder(gt -> gt.getGene().doubleValue(), gtf) .selector(new RouletteWheelSelector<>()) .alterers( // The `Mutator` is used on chromosome with index 0 and 2. PartialAlterer.of(new Mutator<DoubleGene, Double>(), 0, 2), // The `MeanAlterer` is used on chromosome 3. PartialAlterer.of(new MeanAlterer<DoubleGene, Double>(), 3), // The `GaussianMutator` is used on all chromosomes. new GaussianMutator<>() ) .build();
CompletionException
is thrown when the evolution stream is evaluated.- Since:
- 5.0
- Version:
- 5.0
- Author:
- Franz Wilhelmstötter
- Implementation Note:
- This alterer is slower than the performance of the wrapped alterer, because of the needed sectioning of the genotype.
-
-
Field Summary
-
Fields inherited from interface io.jenetics.Alterer
DEFAULT_ALTER_PROBABILITY
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AltererResult<G,C>
alter(Seq<Phenotype<G,C>> population, long generation)
Alters (recombine) a given population.static <G extends Gene<?,G>,C extends Comparable<? super C>>
Alterer<G,C>of(Alterer<G,C> alterer, int... indices)
Wraps the givenalterer
, so that it will only work on chromosomes with the given chromosome indices.static <G extends Gene<?,G>,C extends Comparable<? super C>>
Alterer<G,C>of(Alterer<G,C> alterer, IntRange section)
Wraps the givenalterer
, so that it will only work on chromosomes with the given chromosome indices.
-
-
-
Method Detail
-
alter
public AltererResult<G,C> alter(Seq<Phenotype<G,C>> population, long generation)
Description copied from interface:Alterer
Alters (recombine) a given population. If thepopulation
is empty, nothing is altered. The altered population is part of the returnedAlterResult
object.- Specified by:
alter
in interfaceAlterer<G extends Gene<?,G>,C extends Comparable<? super C>>
- Parameters:
population
- The Population to be altered. If thepopulation
isnull
or empty, nothing is altered.generation
- the date of birth (generation) of the altered phenotypes.- Returns:
- the alter-result object, which contains the altered population and the alteration count
-
of
public static <G extends Gene<?,G>,C extends Comparable<? super C>> Alterer<G,C> of(Alterer<G,C> alterer, int... indices)
Wraps the givenalterer
, so that it will only work on chromosomes with the given chromosome indices.- Type Parameters:
G
- the gene typeC
- the fitness value type- Parameters:
alterer
- the alterer to user for altering the chromosomes with the givenindices
indices
- the chromosomes indices (section)- Returns:
- a wrapped alterer which only works for the given chromosome section
- Throws:
NullPointerException
- if the givenindices
array isnull
IllegalArgumentException
- if the givenindices
array is emptyNegativeArraySizeException
- if one of the givenindices
is negative- See Also:
of(Alterer, IntRange)
-
of
public static <G extends Gene<?,G>,C extends Comparable<? super C>> Alterer<G,C> of(Alterer<G,C> alterer, IntRange section)
Wraps the givenalterer
, so that it will only work on chromosomes with the given chromosome indices.- Type Parameters:
G
- the gene typeC
- the fitness value type- Parameters:
alterer
- the alterer to user for altering the chromosomes with the givenindices
section
- the half-open chromosome index range[min, max)
- Returns:
- a wrapped alterer which only works for the given chromosome section
- Throws:
NullPointerException
- if the givenindices
array isnull
IllegalArgumentException
- if the givenindices
array is emptyNegativeArraySizeException
- if one of the givenindices
is negative- See Also:
of(Alterer, int...)
-
-