Package net.bmahe.genetics4j.gpu.spec
Class ImmutableGPUEAConfiguration.Builder<T extends Comparable<T>>
java.lang.Object
net.bmahe.genetics4j.gpu.spec.ImmutableGPUEAConfiguration.Builder<T>
- Direct Known Subclasses:
GPUEAConfiguration.Builder
- Enclosing class:
ImmutableGPUEAConfiguration<T extends Comparable<T>>
Builds instances of type
ImmutableGPUEAConfiguration
.
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 OpenCLFitness
<T> private GenotypeCombinator
private static final long
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 Program
private ReplacementStrategy
private Collection
<Genotype> private Termination
<T> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal GPUEAConfiguration.Builder
<T> addAllChromosomeSpecs
(Iterable<? extends ChromosomeSpec> elements) Adds elements tochromosomeSpecs
list.final GPUEAConfiguration.Builder
<T> addAllMutationPolicies
(Iterable<? extends MutationPolicy> elements) Adds elements tomutationPolicies
list.final GPUEAConfiguration.Builder
<T> addChromosomeSpecs
(ChromosomeSpec element) Adds one element tochromosomeSpecs
list.final GPUEAConfiguration.Builder
<T> addChromosomeSpecs
(ChromosomeSpec... elements) Adds elements tochromosomeSpecs
list.final GPUEAConfiguration.Builder
<T> addMutationPolicies
(MutationPolicy element) Adds one element tomutationPolicies
list.final GPUEAConfiguration.Builder
<T> addMutationPolicies
(MutationPolicy... elements) Adds elements tomutationPolicies
list.build()
Builds a newImmutableGPUEAConfiguration
.final GPUEAConfiguration.Builder
<T> chromosomeSpecs
(Iterable<? extends ChromosomeSpec> elements) Sets or replaces all elements forchromosomeSpecs
list.final GPUEAConfiguration.Builder
<T> combinationPolicy
(CombinationPolicy combinationPolicy) Initializes the value for thecombinationPolicy
attribute.final GPUEAConfiguration.Builder
<T> fitness
(OpenCLFitness<T> fitness) Initializes the value for thefitness
attribute.private String
final GPUEAConfiguration.Builder
<T> from
(GPUEAConfiguration<T> instance) Fill a builder with attribute values from the providedGPUEAConfiguration
instance.final GPUEAConfiguration.Builder
<T> genotypeCombinator
(GenotypeCombinator genotypeCombinator) Initializes the value for thegenotypeCombinator
attribute.final GPUEAConfiguration.Builder
<T> genotypeGenerator
(Supplier<Genotype> genotypeGenerator) Initializes the optional valuegenotypeGenerator
to genotypeGenerator.final GPUEAConfiguration.Builder
<T> genotypeGenerator
(Optional<? extends Supplier<Genotype>> genotypeGenerator) Initializes the optional valuegenotypeGenerator
to genotypeGenerator.final GPUEAConfiguration.Builder
<T> mutationPolicies
(Iterable<? extends MutationPolicy> elements) Sets or replaces all elements formutationPolicies
list.final GPUEAConfiguration.Builder
<T> offspringGeneratedRatio
(double offspringGeneratedRatio) Initializes the value for theoffspringGeneratedRatio
attribute.private boolean
final GPUEAConfiguration.Builder
<T> optimization
(Optimization optimization) Initializes the value for theoptimization
attribute.final GPUEAConfiguration.Builder
<T> parentSelectionPolicy
(SelectionPolicy parentSelectionPolicy) Initializes the value for theparentSelectionPolicy
attribute.final GPUEAConfiguration.Builder
<T> postEvaluationProcessor
(Function<Population<T>, Population<T>> postEvaluationProcessor) Initializes the optional valuepostEvaluationProcessor
to postEvaluationProcessor.final GPUEAConfiguration.Builder
<T> postEvaluationProcessor
(Optional<? extends Function<Population<T>, Population<T>>> postEvaluationProcessor) Initializes the optional valuepostEvaluationProcessor
to postEvaluationProcessor.final GPUEAConfiguration.Builder
<T> Initializes the value for theprogram
attribute.final GPUEAConfiguration.Builder
<T> replacementStrategy
(ReplacementStrategy replacementStrategy) Initializes the value for thereplacementStrategy
attribute.final GPUEAConfiguration.Builder
<T> seedPopulation
(Collection<Genotype> seedPopulation) Initializes the value for theseedPopulation
attribute.final GPUEAConfiguration.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_PROGRAM
private static final long INIT_BIT_PROGRAM- 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
-
program
-
fitness
-
-
Constructor Details
-
Builder
public Builder()Creates a builder forImmutableGPUEAConfiguration
instances.new GPUEAConfiguration.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
.program(net.bmahe.genetics4j.gpu.spec.Program) // requiredprogram
.fitness(net.bmahe.genetics4j.gpu.spec.fitness.OpenCLFitness<T>) // requiredfitness
.build();
-
-
Method Details
-
from
Fill a builder with attribute values from the providedGPUEAConfiguration
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 GPUEAConfiguration.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 GPUEAConfiguration.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 GPUEAConfiguration.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 GPUEAConfiguration.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 GPUEAConfiguration.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 GPUEAConfiguration.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 GPUEAConfiguration.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 GPUEAConfiguration.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 GPUEAConfiguration.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
public final GPUEAConfiguration.Builder<T> genotypeCombinator(GenotypeCombinator 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
-
program
Initializes the value for theprogram
attribute.- Parameters:
program
- The value for program- 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 newImmutableGPUEAConfiguration
.- Returns:
- An immutable instance of GPUEAConfiguration
- Throws:
IllegalStateException
- if any required attributes are missing
-
offspringGeneratedRatioIsSet
private boolean offspringGeneratedRatioIsSet() -
formatRequiredAttributesMessage
-