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

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

  • Constructor Details

    • Builder

      public Builder()
      Creates a builder for ImmutableGPUEAConfiguration instances.
       new GPUEAConfiguration.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
          .program(net.bmahe.genetics4j.gpu.spec.Program) // required program
          .fitness(net.bmahe.genetics4j.gpu.spec.fitness.OpenCLFitness&lt;T&gt;) // required fitness
          .build();
       
  • Method Details

    • from

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

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

      public final GPUEAConfiguration.Builder<T> fitness(OpenCLFitness<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 ImmutableGPUEAConfiguration<T> build()
      Returns:
      An immutable instance of GPUEAConfiguration
      Throws:
      IllegalStateException - if any required attributes are missing
    • offspringGeneratedRatioIsSet

      private boolean offspringGeneratedRatioIsSet()
    • formatRequiredAttributesMessage

      private String formatRequiredAttributesMessage()