Interface Problem<T,G extends Gene<?,G>,C extends Comparable<? super C>>

Type Parameters:
T - the (native) argument type of the problem fitness function
G - the gene type the evolution engine is working with
C - the result type of the fitness function

public interface Problem<T,G extends Gene<?,G>,C extends Comparable<? super C>>
This interface describes a problem which can be solved by the GA evolution Engine. It connects the actual fitness() function and the needed codec().
final Problem<ISeq<BitGene>, BitGene, Integer> counting = Problem.of( // Native fitness function genes -> (int)genes.stream() .filter(BitGene::bit) .count(), // Problem encoding Codec.of( Genotype.of(BitChromosome.of(100)), gt -> ISeq.of(gt.chromosome()) ) );
The example above shows the Ones-Counting problem definition.
Since:
3.4
Version:
6.1
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Return the codec, which translates the types of the problem domain into types, which can be understood by the evolution Engine.
    Return the constraint, associated with this problem, if available.
    default T
    decode(Genotype<G> genotype)
    Converts the given Genotype to the target type Problem.
    Return the fitness function of the problem in the native problem domain.
    default C
    fitness(Genotype<G> genotype)
    Returns the fitness value for the given argument.
    default C
    fitness(T arg)
    Returns the fitness value for the given argument.
    static <T, G extends Gene<?, G>, C extends Comparable<? super C>>
    Problem<T,G,C>
    of(Function<T,C> fitness, Codec<T,G> codec)
    Return a new optimization problem with the given parameters.
    static <T, G extends Gene<?, G>, C extends Comparable<? super C>>
    Problem<T,G,C>
    of(Function<T,C> fitness, Codec<T,G> codec, Constraint<G,C> constraint)
    Return a new optimization problem with the given parameters.
  • Method Details

    • fitness

      Return the fitness function of the problem in the native problem domain.
      Returns:
      the fitness function
    • codec

      Return the codec, which translates the types of the problem domain into types, which can be understood by the evolution Engine.
      Returns:
      the engine codec
    • constraint

      Return the constraint, associated with this problem, if available.
      Returns:
      the constraint, associated with this problem
      Since:
      6.1
    • decode

      default T decode(Genotype<G> genotype)
      Converts the given Genotype to the target type Problem. This is a shortcut for
      final Problem<SomeObject, DoubleGene, Double> problem = ... final Genotype<DoubleGene> gt = problem.codec().encoding().newInstance(); final SomeObject arg = problem.decode(gt);
      Parameters:
      genotype - the genotype to be converted
      Returns:
      the converted genotype
      Throws:
      NullPointerException - if the given genotype is null
      Since:
      4.2
      See Also:
    • fitness

      default C fitness(T arg)
      Returns the fitness value for the given argument.
      Parameters:
      arg - the argument of the fitness function
      Returns:
      the fitness value
      Since:
      4.1
    • fitness

      default C fitness(Genotype<G> genotype)
      Returns the fitness value for the given argument.
      Parameters:
      genotype - the argument of the fitness function
      Returns:
      the fitness value
      Since:
      4.1
    • of

      static <T, G extends Gene<?, G>, C extends Comparable<? super C>> Problem<T,G,C> of(Function<T,C> fitness, Codec<T,G> codec, Constraint<G,C> constraint)
      Return a new optimization problem with the given parameters. The given constraint is applied to the Engine, via Engine.Builder.constraint(Constraint), and the Codec, via Constraint.constrain(Codec).

      Note
      When creating a new Problem instance with this factory method, there is no need for additionally constraining the given codec with Constraint.constrain(Codec).

      Type Parameters:
      T - the (native) argument type of the problem fitness function
      G - the gene type the evolution engine is working with
      C - the result type of the fitness function
      Parameters:
      fitness - the problem fitness function
      codec - the evolution engine codec
      constraint - the problem constraint, may be null
      Returns:
      a new problem object from the given parameters
      Throws:
      NullPointerException - if the fitness or codec is null
      Since:
      6.1
      See Also:
    • of

      static <T, G extends Gene<?, G>, C extends Comparable<? super C>> Problem<T,G,C> of(Function<T,C> fitness, Codec<T,G> codec)
      Return a new optimization problem with the given parameters.
      Type Parameters:
      T - the (native) argument type of the problem fitness function
      G - the gene type the evolution engine is working with
      C - the result type of the fitness function
      Parameters:
      fitness - the problem fitness function
      codec - the evolution engine codec
      Returns:
      a new problem object from the given parameters
      Throws:
      NullPointerException - if one of the arguments is null