public interface Constraint<G extends Gene<?,G>,C extends Comparable<? super C>>
Phenotype.isValid()
method, which checks
the validity of the underlying genotypes and/or chromosomes. Additionally it
is possible to repair invalid individuals. The evolution
Engine
is using the constraint in the following way: check the validity
and repair invalid individuals.
for (int i = 0; i < population.size(); ++i) {
final Phenotype<G, C> individual = population.get(i);
if (!constraint.test(individual)) {
population.set(i, constraint.repair(individual, generation));
}
}
Engine.Builder.constraint(Constraint)
Modifier and Type | Method and Description |
---|---|
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
of(Predicate<? super Phenotype<G,C>> validator)
Return a new constraint object with the given
validator . |
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
of(Predicate<? super Phenotype<G,C>> validator,
BiFunction<? super Phenotype<G,C>,Long,Phenotype<G,C>> repairer)
Return a new constraint object with the given
validator and
repairer . |
Phenotype<G,C> |
repair(Phenotype<G,C> individual,
long generation)
Tries to repair the given phenotype.
|
boolean |
test(Phenotype<G,C> individual)
Checks the validity of the given
individual . |
boolean test(Phenotype<G,C> individual)
individual
.individual
- the phenotype to checktrue
if the given individual
is valid,
false
otherwiseNullPointerException
- if the given individual
is
null
Phenotype<G,C> repair(Phenotype<G,C> individual, long generation)
Engine
if the test(Phenotype)
method returned
false
.individual
- the phenotype to repairgeneration
- the actual generation used for the repaired phenotypeindividual
as a starting point for
the created phenotype.NullPointerException
- if the given individual
is
null
static <G extends Gene<?,G>,C extends Comparable<? super C>> Constraint<G,C> of(Predicate<? super Phenotype<G,C>> validator, BiFunction<? super Phenotype<G,C>,Long,Phenotype<G,C>> repairer)
validator
and
repairer
.G
- the gene typeC
- the fitness value typevalidator
- the phenotype validator used by the constraintrepairer
- the phenotype repairer used by the constraintNullPointerException
- if one of the arguments is null
static <G extends Gene<?,G>,C extends Comparable<? super C>> Constraint<G,C> of(Predicate<? super Phenotype<G,C>> validator)
validator
. The used
repairer just creates a new phenotype by using the phenotype to be
repaired as template. The repaired phenotype might still be
invalid.G
- the gene typeC
- the fitness value typevalidator
- the phenotype validator used by the constraintNullPointerException
- if one of the arguments is null
© 2007-2019 Franz Wilhelmstötter (2019-11-18 20:30)