Package io.jenetics.engine
Interface Problem<T,G extends Gene<?,G>,C extends Comparable<? super C>>
-
- Type Parameters:
T
- the (native) argument type of the problem fitness functionG
- the gene type the evolution engine is working withC
- 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 evolutionEngine
. It connects the actualfitness()
function and the neededcodec()
.The example above shows the Ones-Counting problem definition.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()) ) );
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Codec<T,G>
codec()
Return the codec, which translates the types of the problem domain into types, which can be understand by the evolutionEngine
.default Optional<Constraint<G,C>>
constraint()
Return the constraint, associated withthis
problem, if available.default T
decode(Genotype<G> genotype)
Function<T,C>
fitness()
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 Detail
-
fitness
Function<T,C> fitness()
Return the fitness function of the problem in the native problem domain.- Returns:
- the fitness function
-
codec
Codec<T,G> codec()
Return the codec, which translates the types of the problem domain into types, which can be understand by the evolutionEngine
.- Returns:
- the engine codec
-
constraint
default Optional<Constraint<G,C>> constraint()
Return the constraint, associated withthis
problem, if available.- Returns:
- the constraint, associated with
this
problem - Since:
- 6.1
-
decode
default T decode(Genotype<G> genotype)
Converts the givenGenotype
to the target typeProblem
. This is a shortcut forfinal 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 givengenotype
isnull
- 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, Constraint<G,C> constraint)
Return a new optimization problem with the given parameters. The givenconstraint
is applied to theEngine
, viaEngine.Builder.constraint(Constraint)
, and theCodec
, viaConstraint.constrain(Codec)
.Note
When creating a newProblem
instance with this factory method, there is no need for additionally constraining the givencodec
withConstraint.constrain(Codec)
.- Type Parameters:
T
- the (native) argument type of the problem fitness functionG
- the gene type the evolution engine is working withC
- the result type of the fitness function- Parameters:
fitness
- the problem fitness functioncodec
- the evolution engine codecconstraint
- the problem constraint, may benull
- Returns:
- a new problem object from the given parameters
- Throws:
NullPointerException
- if thefitness
orcodec
isnull
- Since:
- 6.1
- See Also:
Engine.Builder.constraint(Constraint)
,Constraint.constrain(Codec)
-
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 functionG
- the gene type the evolution engine is working withC
- the result type of the fitness function- Parameters:
fitness
- the problem fitness functioncodec
- the evolution engine codec- Returns:
- a new problem object from the given parameters
- Throws:
NullPointerException
- if one of the arguments isnull
-
-