Module io.jenetics.base
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
- All Known Implementing Classes:
Regression
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
The example above shows the Ones-Counting problem definition.
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())
)
);
- Since:
- 3.4
- Version:
- 6.1
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncodec()
Return the codec, which translates the types of the problem domain into types, which can be understood by the evolutionEngine
.default Optional
<Constraint<G, C>> Return the constraint, associated withthis
problem, if available.default T
fitness()
Return the fitness function of the problem in the native problem domain.default C
Returns the fitness value for the given argument.default C
Returns the fitness value for the given argument.static <T,
G extends Gene<?, G>, C extends Comparable<? super C>>
Problem<T, G, C> 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 evolutionEngine
.- Returns:
- the engine codec
-
constraint
Return the constraint, associated withthis
problem, if available.- Returns:
- the constraint, associated with
this
problem - Since:
- 6.1
-
decode
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:
-
fitness
Returns the fitness value for the given argument.- Parameters:
arg
- the argument of the fitness function- Returns:
- the fitness value
- Since:
- 4.1
-
fitness
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<?, Problem<T,G>, C extends Comparable<? super C>> G, ofC> (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:
-
of
static <T,G extends Gene<?, Problem<T,G>, C extends Comparable<? super C>> G, ofC> (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
-