public final class Phenotype<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements Comparable<Phenotype<G,C>>, Verifiable, Serializable
Phenotype
consists of a Genotype
, the current generation
and an optional fitness value. Once the fitness has been evaluated, a new
Phenotype
instance, with the calculated fitness, can be created with
the withFitness(Comparable)
.Genotype
,
Serialized FormModifier and Type | Method and Description |
---|---|
int |
compareTo(Phenotype<G,C> pt) |
boolean |
equals(Object obj) |
Phenotype<G,C> |
eval(Function<? super Genotype<G>,? extends C> ff)
Applies the given fitness function to the underlying genotype and return
a new phenotype with the (newly) evaluated fitness function, if not
already evaluated.
|
Optional<C> |
fitnessOptional()
Return the fitness value of
this phenotype, or
Optional.empty() if not evaluated yet. |
long |
getAge(long currentGeneration)
Return the age of this phenotype depending on the given current generation.
|
C |
getFitness()
Return the fitness value of this
Phenotype . |
long |
getGeneration()
Return the generation this
Phenotype was created. |
Genotype<G> |
getGenotype()
This method returns a copy of the
Genotype , to guarantee a
immutable class. |
int |
hashCode() |
boolean |
isEvaluated()
A phenotype instance can be created with or without fitness value.
|
boolean |
isValid()
Test whether this phenotype is valid.
|
boolean |
nonEvaluated()
A phenotype instance can be created with or without fitness value.
|
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
of(Genotype<G> genotype,
long generation)
Create a new phenotype from the given arguments.
|
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
of(Genotype<G> genotype,
long generation,
C fitness)
Create a new phenotype from the given arguments.
|
String |
toString() |
Phenotype<G,C> |
withFitness(C fitness)
Return a new
Phenotype object with the given raw fitness
value. |
Phenotype<G,C> |
withGeneration(long generation)
Return a new
Phenotype object with the given generation. |
public Phenotype<G,C> eval(Function<? super Genotype<G>,? extends C> ff)
this
phenotype is returned.ff
- the fitness functionthis
if the fitness value is
already setNullPointerException
- if the given fitness function is null
public Genotype<G> getGenotype()
Genotype
, to guarantee a
immutable class.Genotype
of this Phenotype
.NullPointerException
- if one of the arguments is null
.public boolean isEvaluated()
true
is this phenotype has an fitness value assigned,
false
otherwisenonEvaluated()
public boolean nonEvaluated()
false
is this phenotype has an fitness value assigned,
true
otherwiseisEvaluated()
public C getFitness()
Phenotype
.Phenotype
.NoSuchElementException
- if isEvaluated()
returns
false
fitnessOptional()
public Optional<C> fitnessOptional()
this
phenotype, or
Optional.empty()
if not evaluated yet.getFitness()
public long getGeneration()
Phenotype
was created.Phenotype
was created.getAge(long)
public long getAge(long currentGeneration)
currentGeneration
- the current generation evaluated by the GA.currentGeneration - this.getGeneration()
.getGeneration()
public boolean isValid()
Genotype
is valid.isValid
in interface Verifiable
public int compareTo(Phenotype<G,C> pt)
compareTo
in interface Comparable<Phenotype<G extends Gene<?,G>,C extends Comparable<? super C>>>
public Phenotype<G,C> withFitness(C fitness)
Phenotype
object with the given raw fitness
value. The returned phenotype is automatically evaluated:
isEvaluated() == true
fitness
- the phenotypes fitness valueNullPointerException
- if the given fitness
value is
null
public Phenotype<G,C> withGeneration(long generation)
Phenotype
object with the given generation.generation
- the generation of the newly created phenotypepublic static <G extends Gene<?,G>,C extends Comparable<? super C>> Phenotype<G,C> of(Genotype<G> genotype, long generation)
isEvaluated()
will return false
.G
- the gene type of the chromosomeC
- the fitness value typegenotype
- the genotype of this phenotype.generation
- the current generation of the generated phenotype.NullPointerException
- if one of the arguments is null
.IllegalArgumentException
- if the given generation
is
< 0
.public static <G extends Gene<?,G>,C extends Comparable<? super C>> Phenotype<G,C> of(Genotype<G> genotype, long generation, C fitness)
G
- the gene type of the chromosomeC
- the fitness value typegenotype
- the genotype of this phenotype.generation
- the current generation of the generated phenotype.fitness
- the known fitness of the phenotype.NullPointerException
- if one of the arguments is null
.IllegalArgumentException
- if the given generation
is
< 0
.© 2007-2019 Franz Wilhelmstötter (2019-06-23 15:39)