Class ImmutableNeatSelection.Builder<T extends Comparable<T>>

java.lang.Object
net.bmahe.genetics4j.neat.spec.selection.ImmutableNeatSelection.Builder<T>
Direct Known Subclasses:
NeatSelection.Builder
Enclosing class:
ImmutableNeatSelection<T extends Comparable<T>>

public static class ImmutableNeatSelection.Builder<T extends Comparable<T>> extends Object
Builds instances of type ImmutableNeatSelection. 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

    • INIT_BIT_SPECIES_PREDICATE

      private static final long INIT_BIT_SPECIES_PREDICATE
      See Also:
    • INIT_BIT_SPECIES_SELECTION

      private static final long INIT_BIT_SPECIES_SELECTION
      See Also:
    • OPT_BIT_PER_SPECIES_KEEP_RATIO

      private static final long OPT_BIT_PER_SPECIES_KEEP_RATIO
      See Also:
    • OPT_BIT_MIN_SPECIES_SIZE

      private static final long OPT_BIT_MIN_SPECIES_SIZE
      See Also:
    • initBits

      private long initBits
    • optBits

      private long optBits
    • perSpeciesKeepRatio

      private float perSpeciesKeepRatio
    • minSpeciesSize

      private int minSpeciesSize
    • speciesPredicate

      private BiPredicate<Individual<T extends Comparable<T>>,Individual<T extends Comparable<T>>> speciesPredicate
    • speciesSelection

      private SelectionPolicy speciesSelection
  • Constructor Details

    • Builder

      public Builder()
      Creates a builder for ImmutableNeatSelection instances.
       new NeatSelection.Builder&lt;T&gt;()
          .perSpeciesKeepRatio(float) // optional perSpeciesKeepRatio
          .minSpeciesSize(int) // optional minSpeciesSize
          .speciesPredicate(function.BiPredicate&lt;net.bmahe.genetics4j.core.Individual&lt;T&gt;, net.bmahe.genetics4j.core.Individual&lt;T&gt;&gt;) // required speciesPredicate
          .speciesSelection(net.bmahe.genetics4j.core.spec.selection.SelectionPolicy) // required speciesSelection
          .build();
       
  • Method Details

    • from

      public final NeatSelection.Builder<T> from(NeatSelection<T> instance)
      Fill a builder with attribute values from the provided NeatSelection instance. Regular attribute values will be replaced with those from the given instance. Absent optional values will not replace present values.
      Parameters:
      instance - The instance from which to copy values
      Returns:
      this builder for use in a chained invocation
    • perSpeciesKeepRatio

      public final NeatSelection.Builder<T> perSpeciesKeepRatio(float perSpeciesKeepRatio)
      Initializes the value for the perSpeciesKeepRatio attribute.

      If not set, this attribute will have a default value as returned by the initializer of perSpeciesKeepRatio.

      Parameters:
      perSpeciesKeepRatio - The value for perSpeciesKeepRatio
      Returns:
      this builder for use in a chained invocation
    • minSpeciesSize

      public final NeatSelection.Builder<T> minSpeciesSize(int minSpeciesSize)
      Initializes the value for the minSpeciesSize attribute.

      If not set, this attribute will have a default value as returned by the initializer of minSpeciesSize.

      Parameters:
      minSpeciesSize - The value for minSpeciesSize
      Returns:
      this builder for use in a chained invocation
    • speciesPredicate

      public final NeatSelection.Builder<T> speciesPredicate(BiPredicate<Individual<T>,Individual<T>> speciesPredicate)
      Initializes the value for the speciesPredicate attribute.
      Parameters:
      speciesPredicate - The value for speciesPredicate
      Returns:
      this builder for use in a chained invocation
    • speciesSelection

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

      public ImmutableNeatSelection<T> build()
      Returns:
      An immutable instance of NeatSelection
      Throws:
      IllegalStateException - if any required attributes are missing
    • perSpeciesKeepRatioIsSet

      private boolean perSpeciesKeepRatioIsSet()
    • minSpeciesSizeIsSet

      private boolean minSpeciesSizeIsSet()
    • formatRequiredAttributesMessage

      private String formatRequiredAttributesMessage()