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>>

public static class ImmutableEAConfiguration.Builder<T extends Comparable<T>> extends Object
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 Details

  • Constructor Details

    • Builder

      public Builder()
      Creates a builder for ImmutableEAConfiguration instances.
       new EAConfiguration.Builder&lt;T&gt;()
          .addChromosomeSpecs|addAllChromosomeSpecs(net.bmahe.genetics4j.core.spec.chromosome.ChromosomeSpec) // chromosomeSpecs elements
          .parentSelectionPolicy(net.bmahe.genetics4j.core.spec.selection.SelectionPolicy) // required parentSelectionPolicy
          .combinationPolicy(net.bmahe.genetics4j.core.spec.combination.CombinationPolicy) // required combinationPolicy
          .addMutationPolicies|addAllMutationPolicies(net.bmahe.genetics4j.core.spec.mutation.MutationPolicy) // mutationPolicies elements
          .replacementStrategy(net.bmahe.genetics4j.core.spec.replacement.ReplacementStrategy) // optional replacementStrategy
          .postEvaluationProcessor(function.Function&lt;net.bmahe.genetics4j.core.Population&lt;T&gt;, net.bmahe.genetics4j.core.Population&lt;T&gt;&gt;) // optional postEvaluationProcessor
          .termination(net.bmahe.genetics4j.core.termination.Termination&lt;T&gt;) // required termination
          .genotypeGenerator(function.Supplier&lt;net.bmahe.genetics4j.core.Genotype&gt;) // optional genotypeGenerator
          .seedPopulation(Collection&lt;net.bmahe.genetics4j.core.Genotype&gt;) // optional seedPopulation
          .genotypeCombinator(net.bmahe.genetics4j.core.combination.GenotypeCombinator) // optional genotypeCombinator
          .offspringGeneratedRatio(double) // optional offspringGeneratedRatio
          .optimization(net.bmahe.genetics4j.core.spec.Optimization) // optional optimization
          .fitness(net.bmahe.genetics4j.core.Fitness&lt;T&gt;) // required fitness
          .build();
       
  • Method Details

    • from

      public final EAConfiguration.Builder<T> from(EAConfiguration<T> instance)
      Fill a builder with attribute values from the provided EAConfiguration 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

      public final EAConfiguration.Builder<T> addChromosomeSpecs(ChromosomeSpec element)
      Adds one element to chromosomeSpecs list.
      Parameters:
      element - A chromosomeSpecs element
      Returns:
      this builder for use in a chained invocation
    • addChromosomeSpecs

      public final EAConfiguration.Builder<T> addChromosomeSpecs(ChromosomeSpec... elements)
      Adds elements to chromosomeSpecs 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 for chromosomeSpecs 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 to chromosomeSpecs 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 the parentSelectionPolicy attribute.
      Parameters:
      parentSelectionPolicy - The value for parentSelectionPolicy
      Returns:
      this builder for use in a chained invocation
    • combinationPolicy

      public final EAConfiguration.Builder<T> combinationPolicy(CombinationPolicy combinationPolicy)
      Initializes the value for the combinationPolicy attribute.
      Parameters:
      combinationPolicy - The value for combinationPolicy
      Returns:
      this builder for use in a chained invocation
    • addMutationPolicies

      public final EAConfiguration.Builder<T> addMutationPolicies(MutationPolicy element)
      Adds one element to mutationPolicies list.
      Parameters:
      element - A mutationPolicies element
      Returns:
      this builder for use in a chained invocation
    • addMutationPolicies

      public final EAConfiguration.Builder<T> addMutationPolicies(MutationPolicy... elements)
      Adds elements to mutationPolicies 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 for mutationPolicies 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 to mutationPolicies 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 the replacementStrategy 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 value postEvaluationProcessor 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 value postEvaluationProcessor to postEvaluationProcessor.
      Parameters:
      postEvaluationProcessor - The value for postEvaluationProcessor
      Returns:
      this builder for use in a chained invocation
    • termination

      public final EAConfiguration.Builder<T> termination(Termination<T> termination)
      Initializes the value for the termination attribute.
      Parameters:
      termination - The value for termination
      Returns:
      this builder for use in a chained invocation
    • genotypeGenerator

      public final EAConfiguration.Builder<T> genotypeGenerator(Supplier<Genotype> genotypeGenerator)
      Initializes the optional value genotypeGenerator 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 value genotypeGenerator to genotypeGenerator.
      Parameters:
      genotypeGenerator - The value for genotypeGenerator
      Returns:
      this builder for use in a chained invocation
    • seedPopulation

      public final EAConfiguration.Builder<T> seedPopulation(Collection<Genotype> seedPopulation)
      Initializes the value for the seedPopulation 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 EAConfiguration.Builder<T> genotypeCombinator(GenotypeCombinator genotypeCombinator)
      Initializes the value for the genotypeCombinator 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

      public final EAConfiguration.Builder<T> offspringGeneratedRatio(double offspringGeneratedRatio)
      Initializes the value for the offspringGeneratedRatio 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

      public final EAConfiguration.Builder<T> optimization(Optimization optimization)
      Initializes the value for the optimization 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

      public final EAConfiguration.Builder<T> fitness(Fitness<T> fitness)
      Initializes the value for the fitness attribute.
      Parameters:
      fitness - The value for fitness
      Returns:
      this builder for use in a chained invocation
    • build

      public ImmutableEAConfiguration<T> build()
      Returns:
      An immutable instance of EAConfiguration
      Throws:
      IllegalStateException - if any required attributes are missing
    • offspringGeneratedRatioIsSet

      private boolean offspringGeneratedRatioIsSet()
    • formatRequiredAttributesMessage

      private String formatRequiredAttributesMessage()