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

    • Method Detail

      • setup

        public Engine.Builder<G,​Csetup​(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
      • offspringSelector

        public Engine.Builder<G,​CoffspringSelector​(Selector<G,​C> selector)
        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

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

        public Engine.Builder<G,​Cselector​(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,​Calterers​(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,​Cconstraint​(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,​Coptimize​(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

        public Engine.Builder<G,​Cmaximizing()
        Set to a fitness maximizing strategy.
        Returns:
        this builder, for command chaining
        Since:
        3.4
      • minimizing

        public Engine.Builder<G,​Cminimizing()
        Set to a fitness minimizing strategy.
        Returns:
        this builder, for command chaining
        Since:
        3.4
      • offspringFraction

        public Engine.Builder<G,​CoffspringFraction​(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(double)
      • survivorsFraction

        public Engine.Builder<G,​CsurvivorsFraction​(double fraction)
        The survivors 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 survivors fraction
        Returns:
        this builder, for command chaining
        Throws:
        IllegalArgumentException - if the fraction is not within the range [0, 1].
        Since:
        3.8
        See Also:
        offspringFraction(double)
      • offspringSize

        public Engine.Builder<G,​CoffspringSize​(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,​CsurvivorsSize​(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,​CpopulationSize​(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
      • executor

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

        public Engine.Builder<G,​Cclock​(Clock 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
      • build

        public Engine<G,​Cbuild()
        Builds an new Engine instance from the set properties.
        Returns:
        an new Engine instance from the set properties
      • clock

        public Clock clock()
        Return the Clock 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

        public Factory<Genotype<G>> 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,​Cconstraint()
        Return the constraint of the evolution problem.
        Returns:
        the constraint of the evolution problem
        Since:
        5.0
      • evolutionParams

        public EvolutionParams<G,​CevolutionParams()
        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.
      • 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
      • copy

        public Engine.Builder<G,​Ccopy()
        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