Package io.jenetics.engine
Class Engine.Builder<G extends Gene<?,G>,C extends Comparable<? super C>>
- java.lang.Object
-
- io.jenetics.engine.Engine.Builder<G,C>
-
- Type Parameters:
G
- the gene typeC
- the fitness function result type
- All Implemented Interfaces:
Copyable<Engine.Builder<G,C>>
public static final class Engine.Builder<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements Copyable<Engine.Builder<G,C>>
Builder class for building GAEngine
instances.- Since:
- 3.0
- Version:
- 6.0
- See Also:
Engine
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Alterer<G,C>
alterer()
Return the usedAlterer
of the GA.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 newEngine
instance from the set properties.Clock
clock()
Return theClock
the engine is using for measuring the execution time.Engine.Builder<G,C>
clock(Clock clock)
The clock used for calculating the execution durations.Constraint<G,C>
constraint()
Return the constraint of the evolution problem.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.EvolutionParams<G,C>
evolutionParams()
Return the currently set evolution parameters.Engine.Builder<G,C>
evolutionParams(EvolutionParams<G,C> params)
Set the evolution parameters used by the engine.Executor
executor()
Return theExecutor
the engine is using for executing the evolution steps.Engine.Builder<G,C>
executor(Executor executor)
The executor used by the engine.Factory<Genotype<G>>
genotypeFactory()
Return the used genotypeFactory
of the GA.EvolutionInterceptor<G,C>
interceptor()
Return the evolution interceptor.Engine.Builder<G,C>
interceptor(EvolutionInterceptor<G,C> interceptor)
The evolution interceptor, which allows to change the evolution start and result.long
maximalPhenotypeAge()
Return the maximal allowed phenotype age.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.double
offspringFraction()
Return the offspring fraction.Engine.Builder<G,C>
offspringFraction(double fraction)
The offspring fraction.Selector<G,C>
offspringSelector()
Return the used offspringSelector
of the GA.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.Optimize
optimize()
Return the optimization strategy.Engine.Builder<G,C>
optimize(Optimize optimize)
The optimization strategy used by the engine.int
populationSize()
Return the number of individuals of a population.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>
setup(Engine.Setup<G,C> setup)
Applies the givensetup
recipe tothis
engine builder.Engine.Builder<G,C>
survivorsFraction(double fraction)
The survivors fraction.Selector<G,C>
survivorsSelector()
Return the used survivorSelector
of the GA.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.
-
-
-
Constructor Detail
-
Builder
public Builder(Evaluator<G,C> evaluator, Factory<Genotype<G>> genotypeFactory)
Create a new evolutionEngine.Builder
with the given fitness evaluator and genotype factory. This is the most general way for creating an engine builder.- Parameters:
evaluator
- the fitness evaluatorgenotypeFactory
- the genotype factory- Throws:
NullPointerException
- if one of the arguments isnull
.- Since:
- 5.0
- See Also:
Engine.builder(Function, Codec)
,Engine.builder(Function, Factory)
,Engine.builder(Problem)
,Engine.builder(Function, Chromosome, Chromosome[])
-
-
Method Detail
-
setup
public Engine.Builder<G,C> setup(Engine.Setup<G,C> setup)
Applies the givensetup
recipe tothis
engine builder.- Parameters:
setup
- the setup recipe applying tothis
builder- Returns:
this
builder, for command chaining- Throws:
NullPointerException
- if thesetup
isnull
.- Since:
- 6.0
-
evolutionParams
public Engine.Builder<G,C> evolutionParams(EvolutionParams<G,C> params)
Set the evolution parameters used by the engine.- Parameters:
params
- the evolution parameter- Returns:
this
builder, for command chaining- Throws:
NullPointerException
- if theparams
isnull
.- Since:
- 5.2
-
offspringSelector
public Engine.Builder<G,C> offspringSelector(Selector<G,C> selector)
The selector used for selecting the offspring population. Default values is set toTournamentSelector<>(3)
.- Parameters:
selector
- used for selecting the offspring population- Returns:
this
builder, for command chaining- Throws:
NullPointerException
- if one of theselector
isnull
.
-
survivorsSelector
public Engine.Builder<G,C> survivorsSelector(Selector<G,C> selector)
The selector used for selecting the survivors population. Default values is set toTournamentSelector<>(3)
.- Parameters:
selector
- used for selecting survivors population- Returns:
this
builder, for command chaining- Throws:
NullPointerException
- if one of theselector
isnull
.
-
selector
public Engine.Builder<G,C> selector(Selector<G,C> selector)
The selector used for selecting the survivors and offspring population. Default values is set toTournamentSelector<>(3)
.- Parameters:
selector
- used for selecting survivors and offspring population- Returns:
this
builder, for command chaining- Throws:
NullPointerException
- if one of theselector
isnull
.
-
alterers
@SafeVarargs public final Engine.Builder<G,C> alterers(Alterer<G,C> first, Alterer<G,C>... rest)
The alterers used for alter the offspring population. Default values is set tonew SinglePointCrossover<>(0.2)
followed bynew Mutator<>(0.15)
.- Parameters:
first
- the first alterer used for alter the offspring populationrest
- the rest of the alterers used for alter the offspring population- Returns:
this
builder, for command chaining- Throws:
NullPointerException
- if one of the alterers isnull
.
-
constraint
public Engine.Builder<G,C> constraint(Constraint<G,C> constraint)
The phenotype constraint is used for detecting invalid individuals and repairing them.Default implementation uses
Phenotype::isValid
for validating the phenotype.- Parameters:
constraint
- phenotype constraint which can override the default implementation thePhenotype.isValid()
method and repairs invalid phenotypes when needed.- Returns:
this
builder, for command chaining- Throws:
NullPointerException
- if one of theconstraint
isnull
.- Since:
- 5.0
-
optimize
public Engine.Builder<G,C> optimize(Optimize optimize)
The optimization strategy used by the engine. Default values is set toOptimize.MAXIMUM
.- Parameters:
optimize
- the optimization strategy used by the engine- Returns:
this
builder, for command chaining- Throws:
NullPointerException
- if one of theoptimize
isnull
.
-
maximizing
public Engine.Builder<G,C> maximizing()
Set to a fitness maximizing strategy.- Returns:
this
builder, for command chaining- Since:
- 3.4
-
minimizing
public Engine.Builder<G,C> minimizing()
Set to a fitness minimizing strategy.- Returns:
this
builder, for command chaining- Since:
- 3.4
-
offspringFraction
public Engine.Builder<G,C> offspringFraction(double fraction)
The offspring fraction. Default values is set to0.6
. This method call is equivalent tosurvivorsFraction(1 - offspringFraction)
and will override any previously set survivors-fraction.- Parameters:
fraction
- the offspring fraction- Returns:
this
builder, for command chaining- Throws:
IllegalArgumentException
- if the fraction is not within the range [0, 1].- See Also:
survivorsFraction(double)
-
survivorsFraction
public Engine.Builder<G,C> survivorsFraction(double fraction)
The survivors fraction. Default values is set to0.4
. This method call is equivalent tooffspringFraction(1 - survivorsFraction)
and will override any previously set offspring-fraction.- Parameters:
fraction
- the survivors fraction- Returns:
this
builder, for command chaining- Throws:
IllegalArgumentException
- if the fraction is not within the range [0, 1].- Since:
- 3.8
- See Also:
offspringFraction(double)
-
offspringSize
public Engine.Builder<G,C> offspringSize(int size)
The number of offspring individuals.- Parameters:
size
- the number of offspring individuals.- Returns:
this
builder, for command chaining- Throws:
IllegalArgumentException
- if the size is not within the range [0, population-size].- Since:
- 3.8
-
survivorsSize
public Engine.Builder<G,C> survivorsSize(int size)
The number of survivors.- Parameters:
size
- the number of survivors.- Returns:
this
builder, for command chaining- Throws:
IllegalArgumentException
- if the size is not within the range [0, population-size].- Since:
- 3.8
-
populationSize
public Engine.Builder<G,C> populationSize(int size)
The number of individuals which form the population. Default values is set to50
.- Parameters:
size
- the number of individuals of a population- Returns:
this
builder, for command chaining- Throws:
IllegalArgumentException
- ifsize < 1
-
maximalPhenotypeAge
public Engine.Builder<G,C> maximalPhenotypeAge(long age)
The maximal allowed age of a phenotype. Default values is set to70
.- Parameters:
age
- the maximal phenotype age- Returns:
this
builder, for command chaining- Throws:
IllegalArgumentException
- ifage < 1
-
executor
public Engine.Builder<G,C> executor(Executor executor)
The executor used by the engine.- Parameters:
executor
- the executor used by the engine- Returns:
this
builder, for command chaining
-
clock
public Engine.Builder<G,C> clock(Clock clock)
The clock used for calculating the execution durations.- Parameters:
clock
- the clock used for calculating the execution durations- Returns:
this
builder, for command chaining
-
interceptor
public Engine.Builder<G,C> interceptor(EvolutionInterceptor<G,C> interceptor)
The evolution interceptor, which allows to change the evolution start and result.- Parameters:
interceptor
- the evolution interceptor- Returns:
this
builder, for command chaining- Throws:
NullPointerException
- if the giveninterceptor
isnull
- Since:
- 6.0
- See Also:
EvolutionResult.toUniquePopulation()
-
build
public Engine<G,C> build()
Builds an newEngine
instance from the set properties.- Returns:
- an new
Engine
instance from the set properties
-
alterer
public Alterer<G,C> alterer()
Return the usedAlterer
of the GA.- Returns:
- the used
Alterer
of the GA.
-
clock
public Clock clock()
Return theClock
the engine is using for measuring the execution time.- Returns:
- the clock used for measuring the execution time
- Since:
- 3.1
-
executor
public Executor executor()
Return theExecutor
the engine is using for executing the evolution steps.- Returns:
- the executor used for performing the evolution steps
- Since:
- 3.1
-
genotypeFactory
public Factory<Genotype<G>> genotypeFactory()
Return the used genotypeFactory
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).- Returns:
- the used genotype
Factory
of the GA. - Since:
- 3.1
-
constraint
public Constraint<G,C> constraint()
Return the constraint of the evolution problem.- Returns:
- the constraint of the evolution problem
- Since:
- 5.0
-
evolutionParams
public EvolutionParams<G,C> evolutionParams()
Return the currently set evolution parameters.- Returns:
- the currently set evolution parameters
- Since:
- 5.2
-
maximalPhenotypeAge
public long maximalPhenotypeAge()
Return the maximal allowed phenotype age.- Returns:
- the maximal allowed phenotype age
- Since:
- 3.1
-
offspringFraction
public double offspringFraction()
Return the offspring fraction.- Returns:
- the offspring fraction.
-
offspringSelector
public Selector<G,C> offspringSelector()
Return the used offspringSelector
of the GA.- Returns:
- the used offspring
Selector
of the GA. - Since:
- 3.1
-
survivorsSelector
public Selector<G,C> survivorsSelector()
Return the used survivorSelector
of the GA.- Returns:
- the used survivor
Selector
of the GA. - Since:
- 3.1
-
optimize
public Optimize optimize()
Return the optimization strategy.- Returns:
- the optimization strategy
- Since:
- 3.1
-
populationSize
public int populationSize()
Return the number of individuals of a population.- Returns:
- the number of individuals of a population
- Since:
- 3.1
-
interceptor
public EvolutionInterceptor<G,C> interceptor()
Return the evolution interceptor.- Returns:
- the evolution interceptor
- Since:
- 6.0
-
-