Class ImmutableEAConfiguration<T extends Comparable<T>>
EAConfiguration.
Use the builder to create immutable instances:
new EAConfiguration.Builder().
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classImmutableEAConfiguration.Builder<T extends Comparable<T>>Builds instances of typeEAConfiguration.private final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List<ChromosomeSpec> private final CombinationPolicyprivate final GenotypeCombinatorprivate ImmutableEAConfiguration<T>.InitShimprivate final List<MutationPolicy> private final doubleprivate final Optimizationprivate final SelectionPolicyprivate final PostEvaluationProcessor<T> private 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
ConstructorsModifierConstructorDescriptionprivateImmutableEAConfiguration(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, Fitness<T> fitness) private -
Method Summary
Modifier and TypeMethodDescriptionGenotype of the populationDefines the policy to generate new offsprings from two parentsstatic <T extends Comparable<T>>
EAConfiguration<T> copyOf(EAConfiguration<T> instance) Creates an immutable copy of aEAConfigurationvalue.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 ofImmutableEAConfigurationthat have equal attribute values.private booleanequalsByValue(ImmutableEAConfiguration<?> another) fitness()Defines how should individuals' fitness be assessedDefines 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,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 evaluatedDefines the replacement strategySeed the initial population with specific individualsDefines termination conditiontoString()Prints the immutable valueEAConfigurationwith attribute values.private static <T extends Comparable<T>>
ImmutableEAConfiguration<T> validate(ImmutableEAConfiguration<T> instance) final ImmutableEAConfiguration<T> withChromosomeSpecs(Iterable<? extends ChromosomeSpec> elements) Copy the current immutable object with elements that replace the content ofchromosomeSpecs.final ImmutableEAConfiguration<T> withChromosomeSpecs(ChromosomeSpec... elements) Copy the current immutable object with elements that replace the content ofchromosomeSpecs.final ImmutableEAConfiguration<T> Copy the current immutable object by setting a value for thecombinationPolicyattribute.final ImmutableEAConfiguration<T> withFitness(Fitness<T> value) Copy the current immutable object by setting a value for thefitnessattribute.final ImmutableEAConfiguration<T> Copy the current immutable object by setting a value for thegenotypeCombinatorattribute.final ImmutableEAConfiguration<T> withGenotypeGenerator(Supplier<Genotype> value) Copy the current immutable object by setting a present value for the optionalgenotypeGeneratorattribute.final ImmutableEAConfiguration<T> withGenotypeGenerator(Optional<? extends Supplier<Genotype>> optional) Copy the current immutable object by setting an optional value for thegenotypeGeneratorattribute.final ImmutableEAConfiguration<T> withMutationPolicies(Iterable<? extends MutationPolicy> elements) Copy the current immutable object with elements that replace the content ofmutationPolicies.final ImmutableEAConfiguration<T> withMutationPolicies(MutationPolicy... elements) Copy the current immutable object with elements that replace the content ofmutationPolicies.final ImmutableEAConfiguration<T> withOffspringGeneratedRatio(double value) Copy the current immutable object by setting a value for theoffspringGeneratedRatioattribute.final ImmutableEAConfiguration<T> withOptimization(Optimization value) Copy the current immutable object by setting a value for theoptimizationattribute.final ImmutableEAConfiguration<T> Copy the current immutable object by setting a value for theparentSelectionPolicyattribute.final ImmutableEAConfiguration<T> withPostEvaluationProcessor(Optional<? extends PostEvaluationProcessor<T>> optional) Copy the current immutable object by setting an optional value for thepostEvaluationProcessorattribute.final ImmutableEAConfiguration<T> Copy the current immutable object by setting a present value for the optionalpostEvaluationProcessorattribute.final ImmutableEAConfiguration<T> Copy the current immutable object by setting a value for thereplacementStrategyattribute.final ImmutableEAConfiguration<T> withSeedPopulation(Collection<Genotype> value) Copy the current immutable object by setting a value for theseedPopulationattribute.final ImmutableEAConfiguration<T> withTermination(Termination<T> value) Copy the current immutable object by setting a value for theterminationattribute.Methods 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
-
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
-
ImmutableEAConfiguration
-
ImmutableEAConfiguration
private ImmutableEAConfiguration(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, Fitness<T> fitness)
-
-
Method Details
-
chromosomeSpecs
Genotype of the population- Specified by:
chromosomeSpecsin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
-
parentSelectionPolicy
Defines 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:
-
combinationPolicy
Defines the policy to generate new offsprings from two parents- Specified by:
combinationPolicyin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
-
mutationPolicies
Defines what mutations to be performed on the offsprings- Specified by:
mutationPoliciesin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
-
replacementStrategy
Defines 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
invalid reference
Elitism#DEFAULT_OFFSPRING_RATIO- Overrides:
replacementStrategyin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
-
postEvaluationProcessor
Post-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:
- Population to be used by the remaining evolution process
-
termination
Defines termination condition- Specified by:
terminationin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
-
genotypeGenerator
Defines how to generate individualsIf not specified, the system will rely on the chromosome factories
- Specified by:
genotypeGeneratorin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
-
seedPopulation
Seed the initial population with specific individuals- Overrides:
seedPopulationin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
-
genotypeCombinator
Defines 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:
-
offspringGeneratedRatio
public double offspringGeneratedRatio()Defines 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:
-
optimization
Defines the optimization goal, whether we want to maximize the fitness or minimize it- Overrides:
optimizationin classAbstractEAConfiguration<T extends Comparable<T>>- Returns:
-
fitness
Defines how should individuals' fitness be assessed- Specified by:
fitnessin classEAConfiguration<T extends Comparable<T>>- Returns:
-
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 ImmutableEAConfiguration<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 ImmutableEAConfiguration<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 ImmutableEAConfiguration<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 ImmutableEAConfiguration<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 ImmutableEAConfiguration<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
-
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 ofImmutableEAConfigurationthat 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,fitness. -
toString
Prints the immutable valueEAConfigurationwith attribute values. -
validate
private static <T extends Comparable<T>> ImmutableEAConfiguration<T> validate(ImmutableEAConfiguration<T> instance) -
copyOf
Creates an immutable copy of aEAConfigurationvalue. 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 EAConfiguration instance
-
createSafeList
-
createUnmodifiableList
-