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:
    Codec, Engine
    • Method Detail

      • fitness

        Function<T,​Cfitness()
        Return the fitness function of the problem in the native problem domain.
        Returns:
        the fitness function
      • codec

        Codec<T,​Gcodec()
        Return the codec, which translates the types of the problem domain into types, which can be understand by the evolution Engine.
        Returns:
        the engine codec
      • constraint

        default Optional<Constraint<G,​C>> 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:
        Codec.decode(Genotype)
      • 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)
        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