public final class PartialAlterer<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements Alterer<G,C>
// 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.DEFAULT_ALTER_PROBABILITY
Modifier and Type | Method and 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>> |
of(Alterer<G,C> alterer,
int... indices)
Wraps the given
alterer , so that it will only work on chromosomes
with the given chromosome indices. |
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
of(Alterer<G,C> alterer,
IntRange section)
Wraps the given
alterer , so that it will only work on chromosomes
with the given chromosome indices. |
public AltererResult<G,C> alter(Seq<Phenotype<G,C>> population, long generation)
Alterer
population
is empty,
nothing is altered. The altered population is part of the returned
AlterResult
object.alter
in interface Alterer<G extends Gene<?,G>,C extends Comparable<? super C>>
population
- The Population to be altered. If the population
is null
or empty, nothing is altered.generation
- the date of birth (generation) of the altered phenotypes.public static <G extends Gene<?,G>,C extends Comparable<? super C>> Alterer<G,C> of(Alterer<G,C> alterer, int... indices)
alterer
, so that it will only work on chromosomes
with the given chromosome indices.G
- the gene typeC
- the fitness value typealterer
- the alterer to user for altering the chromosomes with the
given indices
indices
- the chromosomes indices (section)NullPointerException
- if the given indices
array is
null
IllegalArgumentException
- if the given indices
array is
emptyNegativeArraySizeException
- if one of the given indices
is
negativeof(Alterer, IntRange)
public static <G extends Gene<?,G>,C extends Comparable<? super C>> Alterer<G,C> of(Alterer<G,C> alterer, IntRange section)
alterer
, so that it will only work on chromosomes
with the given chromosome indices.G
- the gene typeC
- the fitness value typealterer
- the alterer to user for altering the chromosomes with the
given indices
section
- the half-open chromosome index range [min, max)
NullPointerException
- if the given indices
array is
null
IllegalArgumentException
- if the given indices
array is
emptyNegativeArraySizeException
- if one of the given indices
is
negativeof(Alterer, int...)
© 2007-2019 Franz Wilhelmstötter (2019-06-23 15:39)