G
- the gene typeC
- the fitness function result typepublic static final class Engine.Builder<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements Copyable<Engine.Builder<G,C>>
Engine
instances.Engine
Constructor and Description |
---|
Builder(Evaluator<G,C> evaluator,
Factory<Genotype<G>> genotypeFactory)
Create a new evolution
Engine.Builder with the given fitness
evaluator and genotype factory. |
Modifier and Type | Method and Description |
---|---|
Engine.Builder<G,C> |
alterers(Alterer<G,C> first,
Alterer<G,C>... rest)
The alterers used for alter the offspring population.
|
Engine<G,C> |
build()
Builds an new
Engine instance from the set properties. |
Engine.Builder<G,C> |
clock(Clock clock)
The clock used for calculating the execution durations.
|
Engine.Builder<G,C> |
constraint(Constraint<G,C> constraint)
The phenotype constraint is used for detecting invalid individuals
and repairing them.
|
Engine.Builder<G,C> |
copy()
Create a new builder, with the current configuration.
|
Engine.Builder<G,C> |
executor(Executor executor)
The executor used by the engine.
|
Alterer<G,C> |
getAlterers()
Return the used
Alterer of the GA. |
Clock |
getClock()
Return the
Clock the engine is using for measuring the execution
time. |
Constraint<G,C> |
getConstraint()
Return the constraint of the evolution problem.
|
Executor |
getExecutor()
Return the
Executor the engine is using for executing the
evolution steps. |
Factory<Genotype<G>> |
getGenotypeFactory()
Return the used genotype
Factory of the GA. |
UnaryOperator<EvolutionResult<G,C>> |
getMapper()
Return the evolution result mapper.
|
long |
getMaximalPhenotypeAge()
Return the maximal allowed phenotype age.
|
double |
getOffspringFraction()
Return the offspring fraction.
|
Selector<G,C> |
getOffspringSelector()
Return the used offspring
Selector of the GA. |
Optimize |
getOptimize()
Return the optimization strategy.
|
int |
getPopulationSize()
Return the number of individuals of a population.
|
Selector<G,C> |
getSurvivorsSelector()
Return the used survivor
Selector of the GA. |
Engine.Builder<G,C> |
mapping(Function<? super EvolutionResult<G,C>,EvolutionResult<G,C>> mapper)
The result mapper, which allows to change the evolution result after
each generation.
|
Engine.Builder<G,C> |
maximalPhenotypeAge(long age)
The maximal allowed age of a phenotype.
|
Engine.Builder<G,C> |
maximizing()
Set to a fitness maximizing strategy.
|
Engine.Builder<G,C> |
minimizing()
Set to a fitness minimizing strategy.
|
Engine.Builder<G,C> |
offspringFraction(double fraction)
The offspring fraction.
|
Engine.Builder<G,C> |
offspringSelector(Selector<G,C> selector)
The selector used for selecting the offspring population.
|
Engine.Builder<G,C> |
offspringSize(int size)
The number of offspring individuals.
|
Engine.Builder<G,C> |
optimize(Optimize optimize)
The optimization strategy used by the engine.
|
Engine.Builder<G,C> |
populationSize(int size)
The number of individuals which form the population.
|
Engine.Builder<G,C> |
selector(Selector<G,C> selector)
The selector used for selecting the survivors and offspring
population.
|
Engine.Builder<G,C> |
survivorsFraction(double fraction)
The survivors fraction.
|
Engine.Builder<G,C> |
survivorsSelector(Selector<G,C> selector)
The selector used for selecting the survivors population.
|
Engine.Builder<G,C> |
survivorsSize(int size)
The number of survivors.
|
public Builder(Evaluator<G,C> evaluator, Factory<Genotype<G>> genotypeFactory)
Engine.Builder
with the given fitness
evaluator and genotype factory. This is the most general way for
creating an engine builder.evaluator
- the fitness evaluatorgenotypeFactory
- the genotype factoryNullPointerException
- if one of the arguments is null
.Engine.builder(Function, Codec)
,
Engine.builder(Function, Factory)
,
Engine.builder(Problem)
,
Engine.builder(Function, Chromosome, Chromosome[])
public Engine.Builder<G,C> offspringSelector(Selector<G,C> selector)
TournamentSelector<>(3)
.selector
- used for selecting the offspring populationthis
builder, for command chainingpublic Engine.Builder<G,C> survivorsSelector(Selector<G,C> selector)
TournamentSelector<>(3)
.selector
- used for selecting survivors populationthis
builder, for command chainingpublic Engine.Builder<G,C> selector(Selector<G,C> selector)
TournamentSelector<>(3)
.selector
- used for selecting survivors and offspring populationthis
builder, for command chaining@SafeVarargs public final Engine.Builder<G,C> alterers(Alterer<G,C> first, Alterer<G,C>... rest)
new SinglePointCrossover<>(0.2)
followed by
new Mutator<>(0.15)
.first
- the first alterer used for alter the offspring
populationrest
- the rest of the alterers used for alter the offspring
populationthis
builder, for command chainingNullPointerException
- if one of the alterers is
null
.public Engine.Builder<G,C> constraint(Constraint<G,C> constraint)
Default implementation uses Phenotype::isValid
for
validating the phenotype.
constraint
- phenotype constraint which can override the default
implementation the Phenotype.isValid()
method and repairs
invalid phenotypes when needed.this
builder, for command chainingNullPointerException
- if the validator
is
null
.public Engine.Builder<G,C> optimize(Optimize optimize)
Optimize.MAXIMUM
.optimize
- the optimization strategy used by the enginethis
builder, for command chainingpublic Engine.Builder<G,C> maximizing()
this
builder, for command chainingpublic Engine.Builder<G,C> minimizing()
this
builder, for command chainingpublic Engine.Builder<G,C> offspringFraction(double fraction)
0.6
.
This method call is equivalent to
survivorsFraction(1 - offspringFraction)
and will override
any previously set survivors-fraction.fraction
- the offspring fractionthis
builder, for command chainingIllegalArgumentException
- if the fraction is not
within the range [0, 1].survivorsFraction(double)
public Engine.Builder<G,C> survivorsFraction(double fraction)
0.4
.
This method call is equivalent to
offspringFraction(1 - survivorsFraction)
and will override
any previously set offspring-fraction.fraction
- the survivors fractionthis
builder, for command chainingIllegalArgumentException
- if the fraction is not
within the range [0, 1].offspringFraction(double)
public Engine.Builder<G,C> offspringSize(int size)
size
- the number of offspring individuals.this
builder, for command chainingIllegalArgumentException
- if the size is not
within the range [0, population-size].public Engine.Builder<G,C> survivorsSize(int size)
size
- the number of survivors.this
builder, for command chainingIllegalArgumentException
- if the size is not
within the range [0, population-size].public Engine.Builder<G,C> populationSize(int size)
50
.size
- the number of individuals of a populationthis
builder, for command chainingIllegalArgumentException
- if size < 1
public Engine.Builder<G,C> maximalPhenotypeAge(long age)
70
.age
- the maximal phenotype agethis
builder, for command chainingIllegalArgumentException
- if age < 1
public Engine.Builder<G,C> executor(Executor executor)
executor
- the executor used by the enginethis
builder, for command chainingpublic Engine.Builder<G,C> clock(Clock clock)
clock
- the clock used for calculating the execution durationsthis
builder, for command chainingpublic Engine.Builder<G,C> mapping(Function<? super EvolutionResult<G,C>,EvolutionResult<G,C>> mapper)
mapper
- the evolution result mapperthis
builder, for command chainingNullPointerException
- if the given resultMapper
is
null
EvolutionResult.toUniquePopulation()
public Engine<G,C> build()
Engine
instance from the set properties.Engine
instance from the set propertiespublic Alterer<G,C> getAlterers()
Alterer
of the GA.Alterer
of the GA.public Clock getClock()
Clock
the engine is using for measuring the execution
time.public Executor getExecutor()
Executor
the engine is using for executing the
evolution steps.public Factory<Genotype<G>> getGenotypeFactory()
Factory
of the GA. The genotype factory
is used for creating the initial population and new, random individuals
when needed (as replacement for invalid and/or died genotypes).Factory
of the GA.public Constraint<G,C> getConstraint()
public long getMaximalPhenotypeAge()
public double getOffspringFraction()
public Selector<G,C> getOffspringSelector()
Selector
of the GA.Selector
of the GA.public Selector<G,C> getSurvivorsSelector()
Selector
of the GA.Selector
of the GA.public Optimize getOptimize()
public int getPopulationSize()
public UnaryOperator<EvolutionResult<G,C>> getMapper()
public Engine.Builder<G,C> copy()
copy
in interface Copyable<Engine.Builder<G extends Gene<?,G>,C extends Comparable<? super C>>>
© 2007-2019 Franz Wilhelmstötter (2019-06-23 15:39)