Class ImmutableGPUEAConfiguration<T extends Comparable<T>>
GPUEAConfiguration.
Use the builder to create immutable instances:
new GPUEAConfiguration.Builder().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classImmutableGPUEAConfiguration.Builder<T extends Comparable<T>>Builds instances of typeGPUEAConfiguration.private final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<ChromosomeSpec> private final CombinationPolicyprivate final OpenCLFitness<T> private final GenotypeCombinatorprivate ImmutableGPUEAConfiguration<T>.InitShimprivate final List<MutationPolicy> private final doubleprivate final Optimizationprivate final SelectionPolicyprivate final PostEvaluationProcessor<T> private final Programprivate final ReplacementStrategyprivate final Collection<Genotype> private static final byteprivate static final byteprivate static final byteprivate final Termination<T> Fields inherited from class net.bmahe.genetics4j.core.spec.AbstractEAConfiguration
DEFAULT_OFFSPRING_RATIO, DEFAULT_OPTIMIZATION -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateImmutableGPUEAConfiguration(List<ChromosomeSpec> chromosomeSpecs, SelectionPolicy parentSelectionPolicy, CombinationPolicy combinationPolicy, List<MutationPolicy> mutationPolicies, ReplacementStrategy replacementStrategy, PostEvaluationProcessor<T> postEvaluationProcessor, Termination<T> termination, Supplier<Genotype> genotypeGenerator, Collection<Genotype> seedPopulation, GenotypeCombinator genotypeCombinator, double offspringGeneratedRatio, Optimization optimization, Program program, OpenCLFitness<T> fitness) private -
Method Summary
Modifier and TypeMethodDescriptionGenotype of the populationDefines the policy to generate new offsprings from two parentsstatic <T extends Comparable<T>>
GPUEAConfiguration<T> copyOf(GPUEAConfiguration<T> instance) Creates an immutable copy of aGPUEAConfigurationvalue.private static <T> List<T> createSafeList(Iterable<? extends T> iterable, boolean checkNulls, boolean skipNulls) private static <T> List<T> createUnmodifiableList(boolean clone, List<? extends T> list) booleanThis instance is equal to all instances ofImmutableGPUEAConfigurationthat have equal attribute values.private booleanequalsByValue(ImmutableGPUEAConfiguration<?> another) fitness()Returns the GPU-specific fitness function that implements evaluation using OpenCL.Defines how to combine the offspring chromosomes generatedDefines how to generate individualsinthashCode()Computes a hash code from attributes:chromosomeSpecs,parentSelectionPolicy,combinationPolicy,mutationPolicies,replacementStrategy,postEvaluationProcessor,termination,genotypeGenerator,seedPopulation,genotypeCombinator,offspringGeneratedRatio,optimization,program,fitness.Defines what mutations to be performed on the offspringsdoubleDefines how many children will be generated at each iteration.Defines the optimization goal, whether we want to maximize the fitness or minimize itDefines the policy to select the parents.Post-processing of a population after it got evaluatedprogram()Returns the OpenCL program specification containing kernel source code and build options.Defines the replacement strategySeed the initial population with specific individualsDefines termination conditiontoString()Prints the immutable valueGPUEAConfigurationwith attribute values.private static <T extends Comparable<T>>
ImmutableGPUEAConfiguration<T> validate(ImmutableGPUEAConfiguration<T> instance) final ImmutableGPUEAConfiguration<T> withChromosomeSpecs(Iterable<? extends ChromosomeSpec> elements) Copy the current immutable object with elements that replace the content ofchromosomeSpecs.final ImmutableGPUEAConfiguration<T> withChromosomeSpecs(ChromosomeSpec... elements) Copy the current immutable object with elements that replace the content ofchromosomeSpecs.final ImmutableGPUEAConfiguration<T> Copy the current immutable object by setting a value for thecombinationPolicyattribute.final ImmutableGPUEAConfiguration<T> withFitness(OpenCLFitness<T> value) Copy the current immutable object by setting a value for thefitnessattribute.final ImmutableGPUEAConfiguration<T> Copy the current immutable object by setting a value for thegenotypeCombinatorattribute.final ImmutableGPUEAConfiguration<T> withGenotypeGenerator(Supplier<Genotype> value) Copy the current immutable object by setting a present value for the optionalgenotypeGeneratorattribute.final ImmutableGPUEAConfiguration<T> withGenotypeGenerator(Optional<? extends Supplier<Genotype>> optional) Copy the current immutable object by setting an optional value for thegenotypeGeneratorattribute.final ImmutableGPUEAConfiguration<T> withMutationPolicies(Iterable<? extends MutationPolicy> elements) Copy the current immutable object with elements that replace the content ofmutationPolicies.final ImmutableGPUEAConfiguration<T> withMutationPolicies(MutationPolicy... elements) Copy the current immutable object with elements that replace the content ofmutationPolicies.final ImmutableGPUEAConfiguration<T> withOffspringGeneratedRatio(double value) Copy the current immutable object by setting a value for theoffspringGeneratedRatioattribute.final ImmutableGPUEAConfiguration<T> withOptimization(Optimization value) Copy the current immutable object by setting a value for theoptimizationattribute.final ImmutableGPUEAConfiguration<T> Copy the current immutable object by setting a value for theparentSelectionPolicyattribute.final ImmutableGPUEAConfiguration<T> withPostEvaluationProcessor(Optional<? extends PostEvaluationProcessor<T>> optional) Copy the current immutable object by setting an optional value for thepostEvaluationProcessorattribute.final ImmutableGPUEAConfiguration<T> Copy the current immutable object by setting a present value for the optionalpostEvaluationProcessorattribute.final ImmutableGPUEAConfiguration<T> withProgram(Program value) Copy the current immutable object by setting a value for theprogramattribute.final ImmutableGPUEAConfiguration<T> Copy the current immutable object by setting a value for thereplacementStrategyattribute.final ImmutableGPUEAConfiguration<T> withSeedPopulation(Collection<Genotype> value) Copy the current immutable object by setting a value for theseedPopulationattribute.final ImmutableGPUEAConfiguration<T> withTermination(Termination<T> value) Copy the current immutable object by setting a value for theterminationattribute.Methods inherited from class net.bmahe.genetics4j.gpu.spec.GPUEAConfiguration
builderMethods inherited from class net.bmahe.genetics4j.core.spec.AbstractEAConfiguration
check, fitnessComparator, getChromosomeSpec, numChromosomes
-
Field Details
-
chromosomeSpecs
-
parentSelectionPolicy
-
combinationPolicy
-
mutationPolicies
-
replacementStrategy
-
postEvaluationProcessor
-
termination
-
genotypeGenerator
-
seedPopulation
-
genotypeCombinator
-
offspringGeneratedRatio
private final double offspringGeneratedRatio -
optimization
-
program
-
fitness
-
STAGE_INITIALIZING
private static final byte STAGE_INITIALIZING- See Also:
-
STAGE_UNINITIALIZED
private static final byte STAGE_UNINITIALIZED- See Also:
-
STAGE_INITIALIZED
private static final byte STAGE_INITIALIZED- See Also:
-
initShim
-
-
Constructor Details
-
ImmutableGPUEAConfiguration
-
ImmutableGPUEAConfiguration
private ImmutableGPUEAConfiguration(List<ChromosomeSpec> chromosomeSpecs, SelectionPolicy parentSelectionPolicy, CombinationPolicy combinationPolicy, List<MutationPolicy> mutationPolicies, ReplacementStrategy replacementStrategy, PostEvaluationProcessor<T> postEvaluationProcessor, Termination<T> termination, Supplier<Genotype> genotypeGenerator, Collection<Genotype> seedPopulation, GenotypeCombinator genotypeCombinator, double offspringGeneratedRatio, Optimization optimization, Program program, OpenCLFitness<T> fitness)
-
-
Method Details
-
chromosomeSpecs
Description copied from class:AbstractEAConfigurationGenotype of the population- Specified by:
chromosomeSpecsin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
- The value of the
chromosomeSpecsattribute
-
parentSelectionPolicy
Description copied from class:AbstractEAConfigurationDefines the policy to select the parents. The selected parents will be used for generating the new offsprings- Specified by:
parentSelectionPolicyin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
- The value of the
parentSelectionPolicyattribute
-
combinationPolicy
Description copied from class:AbstractEAConfigurationDefines the policy to generate new offsprings from two parents- Specified by:
combinationPolicyin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
- The value of the
combinationPolicyattribute
-
mutationPolicies
Description copied from class:AbstractEAConfigurationDefines what mutations to be performed on the offsprings- Specified by:
mutationPoliciesin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
- The value of the
mutationPoliciesattribute
-
replacementStrategy
Description copied from class:AbstractEAConfigurationDefines the replacement strategyThe replacement strategy is what will determine the next population based on the generated and mutated offsprings along with the current population
If not specified, the default replacement strategy will be to use Elitism with tournament selection of 3 individuals for both offsprings and survivors. The default offspring ratio is
Elitism.DEFAULT_OFFSPRING_RATIO- Overrides:
replacementStrategyin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
- The value of the
replacementStrategyattribute
-
postEvaluationProcessor
Description copied from class:AbstractEAConfigurationPost-processing of a population after it got evaluatedThis gives the opportunity to filter out, repair or rescore individuals
- Specified by:
postEvaluationProcessorin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
- The value of the
postEvaluationProcessorattribute
-
termination
Description copied from class:AbstractEAConfigurationDefines termination condition- Specified by:
terminationin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
- The value of the
terminationattribute
-
genotypeGenerator
Description copied from class:AbstractEAConfigurationDefines how to generate individualsIf not specified, the system will rely on the chromosome factories
- Specified by:
genotypeGeneratorin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
- The value of the
genotypeGeneratorattribute
-
seedPopulation
Description copied from class:AbstractEAConfigurationSeed the initial population with specific individuals- Overrides:
seedPopulationin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
- The value of the
seedPopulationattribute
-
genotypeCombinator
Description copied from class:AbstractEAConfigurationDefines how to combine the offspring chromosomes generatedCombination of individuals is done on a per chromosome basis. This means some parents may generate a different number of children for each chromosome. This method will therefore define how to take all these generated chromosomes and combine them into offspring individuals
The current default implementation is to generate as many individual as there are combinations of generated chromosomes
- Overrides:
genotypeCombinatorin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
- The value of the
genotypeCombinatorattribute
-
offspringGeneratedRatio
public double offspringGeneratedRatio()Description copied from class:AbstractEAConfigurationDefines how many children will be generated at each iteration. Value must be between 0 and 1 (inclusive) and represents a fraction of the population size- Overrides:
offspringGeneratedRatioin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
- The value of the
offspringGeneratedRatioattribute
-
optimization
Description copied from class:AbstractEAConfigurationDefines the optimization goal, whether we want to maximize the fitness or minimize it- Overrides:
optimizationin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
- The value of the
optimizationattribute
-
program
Returns the OpenCL program specification containing kernel source code and build options.The program defines the OpenCL kernels that will be compiled and executed on GPU devices for fitness evaluation. This includes source code, build flags, and kernel definitions required for the evolutionary algorithm execution.
- Specified by:
programin classGPUEAConfiguration<T extends Comparable<T>>- Returns:
- the OpenCL program specification for kernel compilation
-
fitness
Returns the GPU-specific fitness function that implements evaluation using OpenCL.The fitness function encapsulates the logic for evaluating individual solutions using GPU acceleration. It coordinates data transfer, kernel execution, and result extraction for efficient parallel fitness computation.
- Specified by:
fitnessin classGPUEAConfiguration<T extends Comparable<T>>- Returns:
- the OpenCL fitness function for GPU-accelerated evaluation
-
withChromosomeSpecs
Copy the current immutable object with elements that replace the content ofchromosomeSpecs.- Parameters:
elements- The elements to set- Returns:
- A modified copy of
thisobject
-
withChromosomeSpecs
public final ImmutableGPUEAConfiguration<T> withChromosomeSpecs(Iterable<? extends ChromosomeSpec> elements) Copy the current immutable object with elements that replace the content ofchromosomeSpecs. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
elements- An iterable of chromosomeSpecs elements to set- Returns:
- A modified copy or
thisif not changed
-
withParentSelectionPolicy
Copy the current immutable object by setting a value for theparentSelectionPolicyattribute. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for parentSelectionPolicy- Returns:
- A modified copy or the
thisobject
-
withCombinationPolicy
Copy the current immutable object by setting a value for thecombinationPolicyattribute. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for combinationPolicy- Returns:
- A modified copy or the
thisobject
-
withMutationPolicies
Copy the current immutable object with elements that replace the content ofmutationPolicies.- Parameters:
elements- The elements to set- Returns:
- A modified copy of
thisobject
-
withMutationPolicies
public final ImmutableGPUEAConfiguration<T> withMutationPolicies(Iterable<? extends MutationPolicy> elements) Copy the current immutable object with elements that replace the content ofmutationPolicies. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
elements- An iterable of mutationPolicies elements to set- Returns:
- A modified copy or
thisif not changed
-
withReplacementStrategy
Copy the current immutable object by setting a value for thereplacementStrategyattribute. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for replacementStrategy- Returns:
- A modified copy or the
thisobject
-
withPostEvaluationProcessor
public final ImmutableGPUEAConfiguration<T> withPostEvaluationProcessor(PostEvaluationProcessor<T> value) Copy the current immutable object by setting a present value for the optionalpostEvaluationProcessorattribute.- Parameters:
value- The value for postEvaluationProcessor- Returns:
- A modified copy or
thisif not changed
-
withPostEvaluationProcessor
public final ImmutableGPUEAConfiguration<T> withPostEvaluationProcessor(Optional<? extends PostEvaluationProcessor<T>> optional) Copy the current immutable object by setting an optional value for thepostEvaluationProcessorattribute. A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returningthis.- Parameters:
optional- An optional value for postEvaluationProcessor- Returns:
- A modified copy or
thisif not changed
-
withTermination
Copy the current immutable object by setting a value for theterminationattribute. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for termination- Returns:
- A modified copy or the
thisobject
-
withGenotypeGenerator
Copy the current immutable object by setting a present value for the optionalgenotypeGeneratorattribute.- Parameters:
value- The value for genotypeGenerator- Returns:
- A modified copy or
thisif not changed
-
withGenotypeGenerator
public final ImmutableGPUEAConfiguration<T> withGenotypeGenerator(Optional<? extends Supplier<Genotype>> optional) Copy the current immutable object by setting an optional value for thegenotypeGeneratorattribute. A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returningthis.- Parameters:
optional- An optional value for genotypeGenerator- Returns:
- A modified copy or
thisif not changed
-
withSeedPopulation
Copy the current immutable object by setting a value for theseedPopulationattribute. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for seedPopulation- Returns:
- A modified copy or the
thisobject
-
withGenotypeCombinator
Copy the current immutable object by setting a value for thegenotypeCombinatorattribute. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for genotypeCombinator- Returns:
- A modified copy or the
thisobject
-
withOffspringGeneratedRatio
Copy the current immutable object by setting a value for theoffspringGeneratedRatioattribute. A value strict bits equality used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for offspringGeneratedRatio- Returns:
- A modified copy or the
thisobject
-
withOptimization
Copy the current immutable object by setting a value for theoptimizationattribute. A value equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for optimization- Returns:
- A modified copy or the
thisobject
-
withProgram
Copy the current immutable object by setting a value for theprogramattribute. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for program- Returns:
- A modified copy or the
thisobject
-
withFitness
Copy the current immutable object by setting a value for thefitnessattribute. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Parameters:
value- A new value for fitness- Returns:
- A modified copy or the
thisobject
-
equals
This instance is equal to all instances ofImmutableGPUEAConfigurationthat have equal attribute values. -
equalsByValue
-
hashCode
public int hashCode()Computes a hash code from attributes:chromosomeSpecs,parentSelectionPolicy,combinationPolicy,mutationPolicies,replacementStrategy,postEvaluationProcessor,termination,genotypeGenerator,seedPopulation,genotypeCombinator,offspringGeneratedRatio,optimization,program,fitness. -
toString
Prints the immutable valueGPUEAConfigurationwith attribute values. -
validate
private static <T extends Comparable<T>> ImmutableGPUEAConfiguration<T> validate(ImmutableGPUEAConfiguration<T> instance) -
copyOf
public static <T extends Comparable<T>> GPUEAConfiguration<T> copyOf(GPUEAConfiguration<T> instance) Creates an immutable copy of aGPUEAConfigurationvalue. Uses accessors to get values to initialize the new immutable instance. If an instance is already immutable, it is returned as is.- Type Parameters:
T- generic parameter T- Parameters:
instance- The instance to copy- Returns:
- A copied immutable GPUEAConfiguration instance
-
createSafeList
-
createUnmodifiableList
-