Class Engine.Builder<G extends Gene<?,G>,C extends Comparable<? super C>>

java.lang.Object
io.jenetics.engine.Engine.Builder<G,C>
Type Parameters:
G - the gene type
C - the fitness function result type
All Implemented Interfaces:
Copyable<Engine.Builder<G,C>>
Enclosing class:
Engine<G extends Gene<?,G>,C extends Comparable<? super C>>

public static final class Engine.Builder<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements Copyable<Engine.Builder<G,C>>
Builder class for building GA Engine instances.
Since:
3.0
Version:
6.0
See Also:
  • Constructor Details

  • Method Details

    • setup

      public Engine.Builder<G,C> setup(Engine.Setup<G,C> setup)
      Applies the given setup recipe to this engine builder.
      Parameters:
      setup - the setup recipe applying to this builder
      Returns:
      this builder, for command chaining
      Throws:
      NullPointerException - if the setup is null.
      Since:
      6.0
    • evolutionParams

      Set the evolution parameters used by the engine.
      Parameters:
      params - the evolution parameter
      Returns:
      this builder, for command chaining
      Throws:
      NullPointerException - if the params is null.
      Since:
      5.2
    • offspringSelector

      The selector used for selecting the offspring population. Default values is set to TournamentSelector<>(3).
      Parameters:
      selector - used for selecting the offspring population
      Returns:
      this builder, for command chaining
      Throws:
      NullPointerException - if one of the selector is null.
    • survivorsSelector

      The selector used for selecting the survivor population. Default values is set to TournamentSelector<>(3).
      Parameters:
      selector - used for selecting survivor population
      Returns:
      this builder, for command chaining
      Throws:
      NullPointerException - if one of the selector is null.
    • selector

      public Engine.Builder<G,C> selector(Selector<G,C> selector)
      The selector used for selecting the survivors and offspring population. Default values is set to TournamentSelector<>(3).
      Parameters:
      selector - used for selecting survivors and offspring population
      Returns:
      this builder, for command chaining
      Throws:
      NullPointerException - if one of the selector is null.
    • alterers

      @SafeVarargs public final Engine.Builder<G,C> alterers(Alterer<G,C> first, Alterer<G,C>... rest)
      The alterers used for alter the offspring population. Default values is set to new SinglePointCrossover<>(0.2) followed by new Mutator<>(0.15).
      Parameters:
      first - the first alterer used for alter the offspring population
      rest - the rest of the alterers used for alter the offspring population
      Returns:
      this builder, for command chaining
      Throws:
      NullPointerException - if one of the alterers is null.
    • constraint

      public Engine.Builder<G,C> constraint(Constraint<G,C> constraint)
      The phenotype constraint is used for detecting invalid individuals and repairing them.

      Default implementation uses Phenotype::isValid for validating the phenotype.

      Parameters:
      constraint - phenotype constraint which can override the default implementation the Phenotype.isValid() method and repairs invalid phenotypes when needed.
      Returns:
      this builder, for command chaining
      Throws:
      NullPointerException - if one of the constraint is null.
      Since:
      5.0
    • optimize

      public Engine.Builder<G,C> optimize(Optimize optimize)
      The optimization strategy used by the engine. Default values is set to Optimize.MAXIMUM.
      Parameters:
      optimize - the optimization strategy used by the engine
      Returns:
      this builder, for command chaining
      Throws:
      NullPointerException - if one of the optimize is null.
    • maximizing

      Set to a fitness-maximizing strategy.
      Returns:
      this builder, for command chaining
      Since:
      3.4
    • minimizing

      Set to a fitness minimizing strategy.
      Returns:
      this builder, for command chaining
      Since:
      3.4
    • offspringFraction

      public Engine.Builder<G,C> offspringFraction(double fraction)
      The offspring fraction. Default values is set to 0.6. This method call is equivalent to survivorsFraction(1 - offspringFraction) and will override any previously set survivors-fraction.
      Parameters:
      fraction - the offspring fraction
      Returns:
      this builder, for command chaining
      Throws:
      IllegalArgumentException - if the fraction is not within the range [0, 1].
      See Also:
    • survivorsFraction

      public Engine.Builder<G,C> survivorsFraction(double fraction)
      The survivor fraction. Default values is set to 0.4. This method call is equivalent to offspringFraction(1 - survivorsFraction) and will override any previously set offspring-fraction.
      Parameters:
      fraction - the survivor fraction
      Returns:
      this builder, for command chaining
      Throws:
      IllegalArgumentException - if the fraction is not within the range [0, 1].
      Since:
      3.8
      See Also:
    • offspringSize

      public Engine.Builder<G,C> offspringSize(int size)
      The number of offspring individuals.
      Parameters:
      size - the number of offspring individuals.
      Returns:
      this builder, for command chaining
      Throws:
      IllegalArgumentException - if the size is not within the range [0, population-size].
      Since:
      3.8
    • survivorsSize

      public Engine.Builder<G,C> survivorsSize(int size)
      The number of survivors.
      Parameters:
      size - the number of survivors.
      Returns:
      this builder, for command chaining
      Throws:
      IllegalArgumentException - if the size is not within the range [0, population-size].
      Since:
      3.8
    • populationSize

      public Engine.Builder<G,C> populationSize(int size)
      The number of individuals which form the population. Default values is set to 50.
      Parameters:
      size - the number of individuals of a population
      Returns:
      this builder, for command chaining
      Throws:
      IllegalArgumentException - if size < 1
    • maximalPhenotypeAge

      public Engine.Builder<G,C> maximalPhenotypeAge(long age)
      The maximal allowed age of a phenotype. Default values is set to 70.
      Parameters:
      age - the maximal phenotype age
      Returns:
      this builder, for command chaining
      Throws:
      IllegalArgumentException - if age < 1
    • executor

      public Engine.Builder<G,C> executor(Executor executor)
      The executor used by the engine.
      Parameters:
      executor - the executor used by the engine
      Returns:
      this builder, for command chaining
    • clock

      The clock used for calculating the execution durations.
      Parameters:
      clock - the clock used for calculating the execution durations
      Returns:
      this builder, for command chaining
    • interceptor

      The evolution interceptor, which allows to change the evolution start and result.
      Parameters:
      interceptor - the evolution interceptor
      Returns:
      this builder, for command chaining
      Throws:
      NullPointerException - if the given interceptor is null
      Since:
      6.0
      See Also:
    • build

      public Engine<G,C> build()
      Builds a new Engine instance from the set properties.
      Returns:
      a new Engine instance from the set properties
    • alterer

      public Alterer<G,C> alterer()
      Return the used Alterer of the GA.
      Returns:
      the used Alterer of the GA.
    • clock

      public InstantSource clock()
      Return the InstantSource the engine is using for measuring the execution time.
      Returns:
      the clock used for measuring the execution time
      Since:
      3.1
    • executor

      public Executor executor()
      Return the Executor the engine is using for executing the evolution steps.
      Returns:
      the executor used for performing the evolution steps
      Since:
      3.1
    • genotypeFactory

      Return the used genotype Factory of the GA. The genotype factory is used for creating the initial population and new, random individuals when needed (as replacement for invalid and/or died genotypes).
      Returns:
      the used genotype Factory of the GA.
      Since:
      3.1
    • constraint

      public Constraint<G,C> constraint()
      Return the constraint of the evolution problem.
      Returns:
      the constraint of the evolution problem
      Since:
      5.0
    • evolutionParams

      Return the currently set evolution parameters.
      Returns:
      the currently set evolution parameters
      Since:
      5.2
    • maximalPhenotypeAge

      public long maximalPhenotypeAge()
      Return the maximal allowed phenotype age.
      Returns:
      the maximal allowed phenotype age
      Since:
      3.1
    • offspringFraction

      public double offspringFraction()
      Return the offspring fraction.
      Returns:
      the offspring fraction.
    • offspringSelector

      Return the used offspring Selector of the GA.
      Returns:
      the used offspring Selector of the GA.
      Since:
      3.1
    • survivorsSelector

      Return the used survivor Selector of the GA.
      Returns:
      the used survivor Selector of the GA.
      Since:
      3.1
    • optimize

      public Optimize optimize()
      Return the optimization strategy.
      Returns:
      the optimization strategy
      Since:
      3.1
    • populationSize

      public int populationSize()
      Return the number of individuals of a population.
      Returns:
      the number of individuals of a population
      Since:
      3.1
    • interceptor

      Return the evolution interceptor.
      Returns:
      the evolution interceptor
      Since:
      6.0
    • copy

      public Engine.Builder<G,C> copy()
      Create a new builder, with the current configuration.
      Specified by:
      copy in interface Copyable<G extends Gene<?,G>>
      Returns:
      a new builder, with the current configuration
      Since:
      3.1