public final class Phenotype<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements Comparable<Phenotype<G,C>>, Verifiable, Serializable, Runnable
Phenotype consists of a Genotype plus a fitness
Function, where the fitness Function represents the
environment where the Genotype lives.
This class implements the Comparable interface, to define a natural
order between two Phenotypes. The natural order of the
Phenotypes is defined by its fitness value (given by the
fitness Function. The Phenotype is immutable and therefore
can't be changed after creation.| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Phenotype<G,C> pt) |
boolean |
equals(Object obj) |
Phenotype<G,C> |
evaluate()
Evaluates the (raw) fitness values and caches it so the fitness calculation
is performed only once.
|
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. |
Function<? super Genotype<G>,? extends C> |
getFitnessFunction()
Return the fitness function used by this phenotype to calculate the
(raw) fitness value.
|
Function<? super C,? extends C> |
getFitnessScaler()
Return the fitness scaler used by this phenotype to scale the raw
fitness.
|
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. |
C |
getRawFitness()
Return the raw fitness (before scaling) of the phenotype.
|
int |
hashCode() |
boolean |
isValid()
Test whether this phenotype is valid.
|
Phenotype<G,C> |
newInstance(long generation,
Function<? super Genotype<G>,? extends C> function)
Return a new phenotype with the the genotype of this and with new
fitness function and generation.
|
Phenotype<G,C> |
newInstance(long generation,
Function<? super Genotype<G>,? extends C> function,
Function<? super C,? extends C> scaler)
Return a new phenotype with the the genotype of this and with new
fitness function, fitness scaler and generation.
|
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
of(Genotype<G> genotype,
long generation,
Function<? super Genotype<G>,? extends C> function,
Function<? super C,? extends C> scaler)
Create a new phenotype from the given arguments.
|
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
of(Genotype<G> genotype,
long generation,
Function<? super Genotype<G>,C> function)
The
Genotype is copied to guarantee an immutable class. |
void |
run()
This method simply calls the
evaluate() method. |
String |
toString() |
public Genotype<G> getGenotype()
Genotype, to guarantee a
immutable class.Genotype of this Phenotype.NullPointerException - if one of the arguments is null.public Phenotype<G,C> evaluate()
public void run()
evaluate() method. The purpose of
this method is to have a simple way for concurrent fitness calculation
for expensive fitness values.public Function<? super Genotype<G>,? extends C> getFitnessFunction()
public Function<? super C,? extends C> getFitnessScaler()
public C getFitness()
Phenotype.Phenotype.public C getRawFitness()
public long getGeneration()
Phenotype was created.Phenotype was created.public long getAge(long currentGeneration)
currentGeneration - the current generation evaluated by the GA.currentGeneration - this.getGeneration().public boolean isValid()
Genotype is valid.isValid in interface Verifiablepublic int compareTo(Phenotype<G,C> pt)
compareTo in interface Comparable<Phenotype<G extends Gene<?,G>,C extends Comparable<? super C>>>public Phenotype<G,C> newInstance(long generation, Function<? super Genotype<G>,? extends C> function, Function<? super C,? extends C> scaler)
generation - the generation of the new phenotype.function - the (new) fitness scaler of the created phenotype.scaler - the (new) fitness scaler of the created phenotypeNullPointerException - if one of the values is null.IllegalArgumentException - if the given generation is
< 0.public Phenotype<G,C> newInstance(long generation, Function<? super Genotype<G>,? extends C> function)
generation - the generation of the new phenotype.function - the (new) fitness scaler of the created phenotype.NullPointerException - if one of the values 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, Function<? super Genotype<G>,C> function)
Genotype is copied to guarantee an immutable class. Only
the age of the Phenotype can be incremented.G - the gene type of the chromosomeC - the fitness value typegenotype - the genotype of this phenotype.generation - the current generation of the generated phenotype.function - the fitness function of this 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, Function<? super Genotype<G>,? extends C> function, Function<? super C,? extends C> scaler)
G - the gene type of the chromosomeC - the fitness value typegenotype - the genotype of this phenotype.generation - the current generation of the generated phenotype.function - the fitness function of this phenotype.scaler - the fitness scaler.NullPointerException - if one of the arguments is null.IllegalArgumentException - if the given generation is
< 0.© 2007-2014 Franz Wilhelmstötter (2014-12-28 10:45)