public final class RetryConstraint<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements Constraint<G,C>
Constraint
implementation repairs an invalid
phenotype by creating new individuals until a valid one has been created.Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_RETRY_COUNT
The default retry-count for creating new, valid phenotypes.
|
Constructor and Description |
---|
RetryConstraint(Predicate<? super Phenotype<G,C>> validator,
Factory<Genotype<G>> genotypeFactory,
int retryLimit)
Create a new retry-constraint with the given parameters.
|
Modifier and Type | Method and Description |
---|---|
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
of(Factory<Genotype<G>> genotypeFactory)
Return a new constraint with the given genotype factory.
|
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
of(Predicate<? super Phenotype<G,C>> validator)
Return a new constraint with the given
validator and the
DEFAULT_RETRY_COUNT . |
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
of(Predicate<? super Phenotype<G,C>> validator,
int retryLimit)
Return a new constraint with the given
validator and
retryLimit . |
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 . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
of
public static final int DEFAULT_RETRY_COUNT
public RetryConstraint(Predicate<? super Phenotype<G,C>> validator, Factory<Genotype<G>> genotypeFactory, int retryLimit)
validator
- the phenotype validatorgenotypeFactory
- the genotype factory used for creating new
phenotypes. The genotype factory may be null
. In this case,
the phenotype to be repaired is used as template.retryLimit
- the limit of the phenotype creation retries. If more
re-creation tries are necessary, an invalid phenotype is returned.
This limit guarantees the termination of the
repair(Phenotype,long)
method.NullPointerException
- if the validator
is null
public boolean test(Phenotype<G,C> individual)
Constraint
individual
.test
in interface Constraint<G extends Gene<?,G>,C extends Comparable<? super C>>
individual
- the phenotype to checktrue
if the given individual
is valid,
false
otherwisepublic Phenotype<G,C> repair(Phenotype<G,C> individual, long generation)
Constraint
Engine
if the Constraint.test(Phenotype)
method returned
false
.repair
in interface Constraint<G extends Gene<?,G>,C extends Comparable<? super C>>
individual
- the phenotype to repairgeneration
- the actual generation used for the repaired phenotypeindividual
as a starting point for
the created phenotype.public static <G extends Gene<?,G>,C extends Comparable<? super C>> RetryConstraint<G,C> of(Factory<Genotype<G>> genotypeFactory)
Phenotype.isValid()
and the retry count to
DEFAULT_RETRY_COUNT
.G
- the gene typeC
- the fitness value typegenotypeFactory
- the genotype factory used for creating new
phenotypespublic static <G extends Gene<?,G>,C extends Comparable<? super C>> RetryConstraint<G,C> of(Predicate<? super Phenotype<G,C>> validator)
validator
and the
DEFAULT_RETRY_COUNT
.of
in interface Constraint<G extends Gene<?,G>,C extends Comparable<? super C>>
G
- the gene typeC
- the fitness value typevalidator
- the phenotype validatorpublic static <G extends Gene<?,G>,C extends Comparable<? super C>> RetryConstraint<G,C> of(Predicate<? super Phenotype<G,C>> validator, int retryLimit)
validator
and
retryLimit
.G
- the gene typeC
- the fitness value typevalidator
- the phenotype validatorretryLimit
- the limit of the phenotype creation retries. If more
re-creation tries are necessary, an invalid phenotype is returned.
This limit guarantees the termination of the
repair(Phenotype, long)
method.© 2007-2019 Franz Wilhelmstötter (2019-11-18 20:30)