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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionalterer()Return the usedAltererof the GA.final Engine.Builder<G,C> The alterers used for alter the offspring population.build()Builds an newEngineinstance from the set properties.clock()Return theInstantSourcethe 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 theExecutorthe engine is using for executing the evolution steps.The executor used by the engine.Return the used genotypeFactoryof the GA.Return the evolution interceptor.interceptor(EvolutionInterceptor<G, C> interceptor) The evolution interceptor, which allows to change the evolution start and result.longReturn 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.doubleReturn the offspring fraction.offspringFraction(double fraction) The offspring fraction.Return the used offspringSelectorof 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.intReturn 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 givensetuprecipe tothisengine builder.survivorsFraction(double fraction) The survivors fraction.Return the used survivorSelectorof the GA.survivorsSelector(Selector<G, C> selector) The selector used for selecting the survivors population.survivorsSize(int size) The number of survivors.
-
Constructor Details
-
Builder
Create a new evolutionEngine.Builderwith 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:
-
-
Method Details
-
setup
Applies the givensetuprecipe tothisengine builder.- Parameters:
setup- the setup recipe applying tothisbuilder- Returns:
thisbuilder, for command chaining- Throws:
NullPointerException- if thesetupisnull.- Since:
- 6.0
-
evolutionParams
Set the evolution parameters used by the engine.- Parameters:
params- the evolution parameter- Returns:
thisbuilder, for command chaining- Throws:
NullPointerException- if theparamsisnull.- 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:
thisbuilder, for command chaining- Throws:
NullPointerException- if one of theselectorisnull.
-
survivorsSelector
The selector used for selecting the survivors population. Default values is set toTournamentSelector<>(3).- Parameters:
selector- used for selecting survivors population- Returns:
thisbuilder, for command chaining- Throws:
NullPointerException- if one of theselectorisnull.
-
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:
thisbuilder, for command chaining- Throws:
NullPointerException- if one of theselectorisnull.
-
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:
thisbuilder, 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::isValidfor validating the phenotype.- Parameters:
constraint- phenotype constraint which can override the default implementation thePhenotype.isValid()method and repairs invalid phenotypes when needed.- Returns:
thisbuilder, for command chaining- Throws:
NullPointerException- if one of theconstraintisnull.- 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:
thisbuilder, for command chaining- Throws:
NullPointerException- if one of theoptimizeisnull.
-
maximizing
Set to a fitness maximizing strategy.- Returns:
thisbuilder, for command chaining- Since:
- 3.4
-
minimizing
Set to a fitness minimizing strategy.- Returns:
thisbuilder, 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:
thisbuilder, for command chaining- Throws:
IllegalArgumentException- if the fraction is not within the range [0, 1].- See Also:
-
survivorsFraction
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:
thisbuilder, 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:
thisbuilder, 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:
thisbuilder, 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:
thisbuilder, 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:
thisbuilder, for command chaining- Throws:
IllegalArgumentException- ifage < 1
-
executor
The executor used by the engine.- Parameters:
executor- the executor used by the engine- Returns:
thisbuilder, for command chaining
-
clock
The clock used for calculating the execution durations.- Parameters:
clock- the clock used for calculating the execution durations- Returns:
thisbuilder, for command chaining
-
interceptor
The evolution interceptor, which allows to change the evolution start and result.- Parameters:
interceptor- the evolution interceptor- Returns:
thisbuilder, for command chaining- Throws:
NullPointerException- if the giveninterceptorisnull- Since:
- 6.0
- See Also:
-
build
Builds an newEngineinstance from the set properties.- Returns:
- an new
Engineinstance from the set properties
-
alterer
Return the usedAltererof the GA.- Returns:
- the used
Altererof the GA.
-
clock
Return theInstantSourcethe engine is using for measuring the execution time.- Returns:
- the clock used for measuring the execution time
- Since:
- 3.1
-
executor
Return theExecutorthe engine is using for executing the evolution steps.- Returns:
- the executor used for performing the evolution steps
- Since:
- 3.1
-
genotypeFactory
Return the used genotypeFactoryof 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
Factoryof 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 offspringSelectorof the GA.- Returns:
- the used offspring
Selectorof the GA. - Since:
- 3.1
-
survivorsSelector
Return the used survivorSelectorof the GA.- Returns:
- the used survivor
Selectorof 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.
-