public 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
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> |
copy()
Create a new builder, with the current configuration.
|
Engine.Builder<G,C> |
executor(Executor executor)
The executor used by the engine.
|
Engine.Builder<G,C> |
fitnessFunction(Function<? super Genotype<G>,? extends C> function)
Set the fitness function of the evolution
Engine . |
Engine.Builder<G,C> |
fitnessScaler(Function<? super C,? extends C> scaler)
Set the fitness scaler of the evolution
Engine . |
Engine.Builder<G,C> |
genotypeFactory(Factory<Genotype<G>> genotypeFactory)
The genotype factory used for creating new individuals.
|
Engine.Builder<G,C> |
genotypeValidator(Predicate<? super Genotype<G>> validator)
The genotype validator used for detecting invalid individuals.
|
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. |
Executor |
getExecutor()
Return the
Executor the engine is using for executing the
evolution steps. |
Function<? super Genotype<G>,? extends C> |
getFitnessFunction()
Return the fitness function of the GA engine.
|
Function<? super C,? extends C> |
getFitnessScaler()
Return the fitness scaler of the GA engine.
|
Factory<Genotype<G>> |
getGenotypeFactory()
Return the used genotype
Factory of the GA. |
int |
getIndividualCreationRetries()
Return the maximal number of attempt before the
Engine gives
up creating a valid individual (Phenotype ). |
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> |
individualCreationRetries(int retries)
The maximal number of attempt before the
Engine gives up
creating a valid individual (Phenotype ). |
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> |
phenotypeValidator(Predicate<? super Phenotype<G,C>> validator)
The phenotype validator used for detecting invalid individuals.
|
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 Engine.Builder<G,C> fitnessFunction(Function<? super Genotype<G>,? extends C> function)
Engine
.function
- the fitness function to use in the GA Engine
this
builder, for command chainingpublic Engine.Builder<G,C> fitnessScaler(Function<? super C,? extends C> scaler)
Engine
. Default
value is set to the identity function.scaler
- the fitness scale to use in the GA Engine
this
builder, for command chainingpublic Engine.Builder<G,C> genotypeFactory(Factory<Genotype<G>> genotypeFactory)
genotypeFactory
- the genotype factory for creating new
individuals.this
builder, for command chainingpublic 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> phenotypeValidator(Predicate<? super Phenotype<G,C>> validator)
genotypeFactory(Factory)
, which will replace any
previously set phenotype validators.
Default value is set to Phenotype::isValid
.
validator
- the validator
used for validating the
individuals (phenotypes).this
builder, for command chainingNullPointerException
- if the validator
is
null
.genotypeValidator(Predicate)
public Engine.Builder<G,C> genotypeValidator(Predicate<? super Genotype<G>> validator)
phenotypeValidator(Predicate)
, which will replace any
previously set genotype validators.
Default value is set to Genotype::isValid
.
validator
- the validator
used for validating the
individuals (genotypes).this
builder, for command chainingNullPointerException
- if the validator
is
null
.phenotypeValidator(Predicate)
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> individualCreationRetries(int retries)
Engine
gives up
creating a valid individual (Phenotype
). Default values is
set to 10
.retries
- the maximal retry countthis
builder, for command chainingIllegalArgumentException
- if the given retry count
is
smaller than zero.public 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 Function<? super Genotype<G>,? extends C> getFitnessFunction()
public Function<? super C,? extends C> getFitnessScaler()
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 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 int getIndividualCreationRetries()
Engine
gives
up creating a valid individual (Phenotype
).Phenotype
creation attemptspublic 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-2018 Franz Wilhelmstötter (2018-02-14 08:27)