Module io.jenetics.base
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 GA
Engine
instances.- Since:
- 3.0
- Version:
- 6.0
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionalterer()
Return the usedAlterer
of the GA.final Engine.Builder
<G, C> The alterers used for alter the offspring population.build()
Builds a newEngine
instance from the set properties.clock()
Return theInstantSource
the engine is using for measuring the execution time.clock
(InstantSource clock) The clock used for calculating the execution durations.Constraint
<G, C> Return the constraint of the evolution problem.constraint
(Constraint<G, C> constraint) The phenotype constraint is used for detecting invalid individuals and repairing them.copy()
Create a new builder, with the current configuration.Return the currently set evolution parameters.evolutionParams
(EvolutionParams<G, C> params) Set the evolution parameters used by the engine.executor()
Return theExecutor
the engine is using for executing the evolution steps.The executor used by the engine.Return the batch executor, used for evaluating the fitness functions.fitnessExecutor
(BatchExecutor executor) This executor is used for evaluating the fitness functions.Return the used genotypeFactory
of the GA.Return the evolution interceptor.interceptor
(EvolutionInterceptor<G, C> interceptor) The evolution interceptor, which allows changing the evolution start and result.long
Return the maximal allowed phenotype age.maximalPhenotypeAge
(long age) The maximal allowed age of a phenotype.Set to a fitness-maximizing strategy.Set to a fitness minimizing strategy.double
Return the offspring fraction.offspringFraction
(double fraction) The offspring fraction.Return the used offspringSelector
of the GA.offspringSelector
(Selector<G, C> selector) The selector used for selecting the offspring population.offspringSize
(int size) The number of offspring individuals.optimize()
Return the optimization strategy.The optimization strategy used by the engine.int
Return the number of individuals of a population.populationSize
(int size) The number of individuals which form the population.The selector used for selecting the survivors and offspring population.setup
(Engine.Setup<G, C> setup) Applies the givensetup
recipe tothis
engine builder.survivorsFraction
(double fraction) The survivor fraction.Return the used survivorSelector
of the GA.survivorsSelector
(Selector<G, C> selector) The selector used for selecting the survivor population.survivorsSize
(int size) The number of survivors.
-
Constructor Details
-
Builder
Create a new evolutionEngine.Builder
with the given fitness evaluator and genotype factory. This is the most general way of creating an engine builder.- Parameters:
evaluator
- the fitness evaluatorgtf
- the genotype factory- Throws:
NullPointerException
- if one of the arguments isnull
.- Since:
- 5.0
- See Also:
-
-
Method Details
-
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
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
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
The selector used for selecting the survivor population. Default values is set toTournamentSelector<>(3)
.- Parameters:
selector
- used for selecting survivor population- Returns:
this
builder, for command chaining- Throws:
NullPointerException
- if one of theselector
isnull
.
-
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
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
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
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
Set to a fitness-maximizing strategy.- Returns:
this
builder, for command chaining- Since:
- 3.4
-
minimizing
Set to a fitness minimizing strategy.- Returns:
this
builder, for command chaining- Since:
- 3.4
-
offspringFraction
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
The survivor 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 survivor fraction- Returns:
this
builder, for command chaining- Throws:
IllegalArgumentException
- if the fraction is not within the range [0, 1].- Since:
- 3.8
- See Also:
-
offspringSize
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
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
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
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
The executor used by the engine.- Parameters:
executor
- the executor used by the engine- Returns:
this
builder, for command chaining- API Note:
- If no dedicated
Evaluator
is defined, this is also the executor, used for evaluating the fitness functions.
-
fitnessExecutor
This executor is used for evaluating the fitness functions.- Parameters:
executor
- the executor used for evaluating the fitness functions- Returns:
this
builder, for command chaining- Since:
- 8.0
- API Note:
- If a dedicated
Evaluator
is defined, this executor is not used.
-
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
The evolution interceptor, which allows changing 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:
-
build
Builds a newEngine
instance from the set properties.- Returns:
- a new
Engine
instance from the set properties
-
alterer
Return the usedAlterer
of the GA.- Returns:
- the used
Alterer
of the GA.
-
clock
Return theInstantSource
the engine is using for measuring the execution time.- Returns:
- the clock used for measuring the execution time
- Since:
- 3.1
-
executor
Return theExecutor
the engine is using for executing the evolution steps.- Returns:
- the executor used for performing the evolution steps
- Since:
- 3.1
-
fitnessExecutor
Return the batch executor, used for evaluating the fitness functions.- Returns:
- the batch executor, used for evaluating the fitness functions
- Since:
- 8.0
-
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
Return the constraint of the evolution problem.- Returns:
- the constraint of the evolution problem
- Since:
- 5.0
-
evolutionParams
Return the currently set evolution parameters.- Returns:
- the currently set evolution parameters
- Since:
- 5.2
-
maximalPhenotypeAge
Return the maximal allowed phenotype age.- Returns:
- the maximal allowed phenotype age
- Since:
- 3.1
-
offspringFraction
Return the offspring fraction.- Returns:
- the offspring fraction.
-
offspringSelector
Return the used offspringSelector
of the GA.- Returns:
- the used offspring
Selector
of the GA. - Since:
- 3.1
-
survivorsSelector
Return the used survivorSelector
of the GA.- Returns:
- the used survivor
Selector
of the GA. - Since:
- 3.1
-
optimize
Return the optimization strategy.- Returns:
- the optimization strategy
- Since:
- 3.1
-
populationSize
Return the number of individuals of a population.- Returns:
- the number of individuals of a population
- Since:
- 3.1
-
interceptor
Return the evolution interceptor.- Returns:
- the evolution interceptor
- Since:
- 6.0
-
copy
Create a new builder, with the current configuration.
-