Package net.bmahe.genetics4j.core.spec
Class ImmutableEAConfiguration.Builder<T extends Comparable<T>>
java.lang.Object
net.bmahe.genetics4j.core.spec.ImmutableEAConfiguration.Builder<T>
- Direct Known Subclasses:
EAConfiguration.Builder
- Enclosing class:
ImmutableEAConfiguration<T extends Comparable<T>>
Builds instances of type
ImmutableEAConfiguration
.
Initialize attributes and then invoke the build()
method to create an
immutable instance.
Builder
is not thread-safe and generally should not be stored in a field or collection,
but instead used immediately to create instances.
-
Field Summary
Modifier and TypeFieldDescriptionprivate List
<ChromosomeSpec> private CombinationPolicy
private GenotypeCombinator
private static final long
private static final long
private static final long
private static final long
private long
private List
<MutationPolicy> private double
private static final long
private long
private Optimization
private SelectionPolicy
private Function
<Population<T>, Population<T>> private ReplacementStrategy
private Collection
<Genotype> private Termination
<T> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal EAConfiguration.Builder
<T> addAllChromosomeSpecs
(Iterable<? extends ChromosomeSpec> elements) Adds elements tochromosomeSpecs
list.final EAConfiguration.Builder
<T> addAllMutationPolicies
(Iterable<? extends MutationPolicy> elements) Adds elements tomutationPolicies
list.final EAConfiguration.Builder
<T> addChromosomeSpecs
(ChromosomeSpec element) Adds one element tochromosomeSpecs
list.final EAConfiguration.Builder
<T> addChromosomeSpecs
(ChromosomeSpec... elements) Adds elements tochromosomeSpecs
list.final EAConfiguration.Builder
<T> addMutationPolicies
(MutationPolicy element) Adds one element tomutationPolicies
list.final EAConfiguration.Builder
<T> addMutationPolicies
(MutationPolicy... elements) Adds elements tomutationPolicies
list.build()
Builds a newImmutableEAConfiguration
.final EAConfiguration.Builder
<T> chromosomeSpecs
(Iterable<? extends ChromosomeSpec> elements) Sets or replaces all elements forchromosomeSpecs
list.final EAConfiguration.Builder
<T> combinationPolicy
(CombinationPolicy combinationPolicy) Initializes the value for thecombinationPolicy
attribute.final EAConfiguration.Builder
<T> Initializes the value for thefitness
attribute.private String
final EAConfiguration.Builder
<T> from
(EAConfiguration<T> instance) Fill a builder with attribute values from the providedEAConfiguration
instance.final EAConfiguration.Builder
<T> genotypeCombinator
(GenotypeCombinator genotypeCombinator) Initializes the value for thegenotypeCombinator
attribute.final EAConfiguration.Builder
<T> genotypeGenerator
(Supplier<Genotype> genotypeGenerator) Initializes the optional valuegenotypeGenerator
to genotypeGenerator.final EAConfiguration.Builder
<T> genotypeGenerator
(Optional<? extends Supplier<Genotype>> genotypeGenerator) Initializes the optional valuegenotypeGenerator
to genotypeGenerator.final EAConfiguration.Builder
<T> mutationPolicies
(Iterable<? extends MutationPolicy> elements) Sets or replaces all elements formutationPolicies
list.final EAConfiguration.Builder
<T> offspringGeneratedRatio
(double offspringGeneratedRatio) Initializes the value for theoffspringGeneratedRatio
attribute.private boolean
final EAConfiguration.Builder
<T> optimization
(Optimization optimization) Initializes the value for theoptimization
attribute.final EAConfiguration.Builder
<T> parentSelectionPolicy
(SelectionPolicy parentSelectionPolicy) Initializes the value for theparentSelectionPolicy
attribute.final EAConfiguration.Builder
<T> postEvaluationProcessor
(Function<Population<T>, Population<T>> postEvaluationProcessor) Initializes the optional valuepostEvaluationProcessor
to postEvaluationProcessor.final EAConfiguration.Builder
<T> postEvaluationProcessor
(Optional<? extends Function<Population<T>, Population<T>>> postEvaluationProcessor) Initializes the optional valuepostEvaluationProcessor
to postEvaluationProcessor.final EAConfiguration.Builder
<T> replacementStrategy
(ReplacementStrategy replacementStrategy) Initializes the value for thereplacementStrategy
attribute.final EAConfiguration.Builder
<T> seedPopulation
(Collection<Genotype> seedPopulation) Initializes the value for theseedPopulation
attribute.final EAConfiguration.Builder
<T> termination
(Termination<T> termination) Initializes the value for thetermination
attribute.
-
Field Details
-
INIT_BIT_PARENT_SELECTION_POLICY
private static final long INIT_BIT_PARENT_SELECTION_POLICY- See Also:
-
INIT_BIT_COMBINATION_POLICY
private static final long INIT_BIT_COMBINATION_POLICY- See Also:
-
INIT_BIT_TERMINATION
private static final long INIT_BIT_TERMINATION- See Also:
-
INIT_BIT_FITNESS
private static final long INIT_BIT_FITNESS- See Also:
-
OPT_BIT_OFFSPRING_GENERATED_RATIO
private static final long OPT_BIT_OFFSPRING_GENERATED_RATIO- See Also:
-
initBits
private long initBits -
optBits
private long optBits -
chromosomeSpecs
-
parentSelectionPolicy
-
combinationPolicy
-
mutationPolicies
-
replacementStrategy
-
postEvaluationProcessor
private Function<Population<T extends Comparable<T>>,Population<T extends Comparable<T>>> postEvaluationProcessor -
termination
-
genotypeGenerator
-
seedPopulation
-
genotypeCombinator
-
offspringGeneratedRatio
private double offspringGeneratedRatio -
optimization
-
fitness
-
-
Constructor Details
-
Builder
public Builder()Creates a builder forImmutableEAConfiguration
instances.new EAConfiguration.Builder<T>() .addChromosomeSpecs|addAllChromosomeSpecs(net.bmahe.genetics4j.core.spec.chromosome.ChromosomeSpec) //
chromosomeSpecs
elements .parentSelectionPolicy(net.bmahe.genetics4j.core.spec.selection.SelectionPolicy) // requiredparentSelectionPolicy
.combinationPolicy(net.bmahe.genetics4j.core.spec.combination.CombinationPolicy) // requiredcombinationPolicy
.addMutationPolicies|addAllMutationPolicies(net.bmahe.genetics4j.core.spec.mutation.MutationPolicy) //mutationPolicies
elements .replacementStrategy(net.bmahe.genetics4j.core.spec.replacement.ReplacementStrategy) // optionalreplacementStrategy
.postEvaluationProcessor(function.Function<net.bmahe.genetics4j.core.Population<T>, net.bmahe.genetics4j.core.Population<T>>) // optionalpostEvaluationProcessor
.termination(net.bmahe.genetics4j.core.termination.Termination<T>) // requiredtermination
.genotypeGenerator(function.Supplier<net.bmahe.genetics4j.core.Genotype>) // optionalgenotypeGenerator
.seedPopulation(Collection<net.bmahe.genetics4j.core.Genotype>) // optionalseedPopulation
.genotypeCombinator(net.bmahe.genetics4j.core.combination.GenotypeCombinator) // optionalgenotypeCombinator
.offspringGeneratedRatio(double) // optionaloffspringGeneratedRatio
.optimization(net.bmahe.genetics4j.core.spec.Optimization) // optionaloptimization
.fitness(net.bmahe.genetics4j.core.Fitness<T>) // requiredfitness
.build();
-
-
Method Details
-
from
Fill a builder with attribute values from the providedEAConfiguration
instance. Regular attribute values will be replaced with those from the given instance. Absent optional values will not replace present values. Collection elements and entries will be added, not replaced.- Parameters:
instance
- The instance from which to copy values- Returns:
this
builder for use in a chained invocation
-
addChromosomeSpecs
Adds one element tochromosomeSpecs
list.- Parameters:
element
- A chromosomeSpecs element- Returns:
this
builder for use in a chained invocation
-
addChromosomeSpecs
Adds elements tochromosomeSpecs
list.- Parameters:
elements
- An array of chromosomeSpecs elements- Returns:
this
builder for use in a chained invocation
-
chromosomeSpecs
public final EAConfiguration.Builder<T> chromosomeSpecs(Iterable<? extends ChromosomeSpec> elements) Sets or replaces all elements forchromosomeSpecs
list.- Parameters:
elements
- An iterable of chromosomeSpecs elements- Returns:
this
builder for use in a chained invocation
-
addAllChromosomeSpecs
public final EAConfiguration.Builder<T> addAllChromosomeSpecs(Iterable<? extends ChromosomeSpec> elements) Adds elements tochromosomeSpecs
list.- Parameters:
elements
- An iterable of chromosomeSpecs elements- Returns:
this
builder for use in a chained invocation
-
parentSelectionPolicy
public final EAConfiguration.Builder<T> parentSelectionPolicy(SelectionPolicy parentSelectionPolicy) Initializes the value for theparentSelectionPolicy
attribute.- Parameters:
parentSelectionPolicy
- The value for parentSelectionPolicy- Returns:
this
builder for use in a chained invocation
-
combinationPolicy
Initializes the value for thecombinationPolicy
attribute.- Parameters:
combinationPolicy
- The value for combinationPolicy- Returns:
this
builder for use in a chained invocation
-
addMutationPolicies
Adds one element tomutationPolicies
list.- Parameters:
element
- A mutationPolicies element- Returns:
this
builder for use in a chained invocation
-
addMutationPolicies
Adds elements tomutationPolicies
list.- Parameters:
elements
- An array of mutationPolicies elements- Returns:
this
builder for use in a chained invocation
-
mutationPolicies
public final EAConfiguration.Builder<T> mutationPolicies(Iterable<? extends MutationPolicy> elements) Sets or replaces all elements formutationPolicies
list.- Parameters:
elements
- An iterable of mutationPolicies elements- Returns:
this
builder for use in a chained invocation
-
addAllMutationPolicies
public final EAConfiguration.Builder<T> addAllMutationPolicies(Iterable<? extends MutationPolicy> elements) Adds elements tomutationPolicies
list.- Parameters:
elements
- An iterable of mutationPolicies elements- Returns:
this
builder for use in a chained invocation
-
replacementStrategy
public final EAConfiguration.Builder<T> replacementStrategy(ReplacementStrategy replacementStrategy) Initializes the value for thereplacementStrategy
attribute.If not set, this attribute will have a default value as returned by the initializer of
replacementStrategy
.- Parameters:
replacementStrategy
- The value for replacementStrategy- Returns:
this
builder for use in a chained invocation
-
postEvaluationProcessor
public final EAConfiguration.Builder<T> postEvaluationProcessor(Function<Population<T>, Population<T>> postEvaluationProcessor) Initializes the optional valuepostEvaluationProcessor
to postEvaluationProcessor.- Parameters:
postEvaluationProcessor
- The value for postEvaluationProcessor- Returns:
this
builder for chained invocation
-
postEvaluationProcessor
public final EAConfiguration.Builder<T> postEvaluationProcessor(Optional<? extends Function<Population<T>, Population<T>>> postEvaluationProcessor) Initializes the optional valuepostEvaluationProcessor
to postEvaluationProcessor.- Parameters:
postEvaluationProcessor
- The value for postEvaluationProcessor- Returns:
this
builder for use in a chained invocation
-
termination
Initializes the value for thetermination
attribute.- Parameters:
termination
- The value for termination- Returns:
this
builder for use in a chained invocation
-
genotypeGenerator
Initializes the optional valuegenotypeGenerator
to genotypeGenerator.- Parameters:
genotypeGenerator
- The value for genotypeGenerator- Returns:
this
builder for chained invocation
-
genotypeGenerator
public final EAConfiguration.Builder<T> genotypeGenerator(Optional<? extends Supplier<Genotype>> genotypeGenerator) Initializes the optional valuegenotypeGenerator
to genotypeGenerator.- Parameters:
genotypeGenerator
- The value for genotypeGenerator- Returns:
this
builder for use in a chained invocation
-
seedPopulation
Initializes the value for theseedPopulation
attribute.If not set, this attribute will have a default value as returned by the initializer of
seedPopulation
.- Parameters:
seedPopulation
- The value for seedPopulation- Returns:
this
builder for use in a chained invocation
-
genotypeCombinator
Initializes the value for thegenotypeCombinator
attribute.If not set, this attribute will have a default value as returned by the initializer of
genotypeCombinator
.- Parameters:
genotypeCombinator
- The value for genotypeCombinator- Returns:
this
builder for use in a chained invocation
-
offspringGeneratedRatio
Initializes the value for theoffspringGeneratedRatio
attribute.If not set, this attribute will have a default value as returned by the initializer of
offspringGeneratedRatio
.- Parameters:
offspringGeneratedRatio
- The value for offspringGeneratedRatio- Returns:
this
builder for use in a chained invocation
-
optimization
Initializes the value for theoptimization
attribute.If not set, this attribute will have a default value as returned by the initializer of
optimization
.- Parameters:
optimization
- The value for optimization- Returns:
this
builder for use in a chained invocation
-
fitness
Initializes the value for thefitness
attribute.- Parameters:
fitness
- The value for fitness- Returns:
this
builder for use in a chained invocation
-
build
Builds a newImmutableEAConfiguration
.- Returns:
- An immutable instance of EAConfiguration
- Throws:
IllegalStateException
- if any required attributes are missing
-
offspringGeneratedRatioIsSet
private boolean offspringGeneratedRatioIsSet() -
formatRequiredAttributesMessage
-