public final class Phenotype<G extends Gene<?,G>,C extends Comparable<? super C>> extends Object implements Comparable<Phenotype<G,C>>, Immutable, Verifiable, XMLSerializable, Realtime, 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 |
|---|---|
static Function<Phenotype<?,?>,Integer> |
Age(int currentGeneration)
Create a
Function which return the phenotype age when calling
converter.convert(phenotype). |
int |
compareTo(Phenotype<G,C> pt) |
boolean |
equals(Object obj) |
void |
evaluate()
Evaluates the (raw) fitness values and caches it so the fitness calculation
is performed only once.
|
static <C extends Comparable<? super C>> |
Fitness()
Create a
Function which return the phenotype fitness when
calling converter.convert(phenotype). |
static Function<Phenotype<?,?>,Integer> |
Generation()
Create a
Function which return the phenotype generation when
calling converter.convert(phenotype). |
static <G extends Gene<?,G>> |
Genotype()
Create a
Function which return the phenotype genotype when
calling converter.convert(phenotype). |
int |
getAge(int currentGeneration)
Return the age of this phenotype depending on the given current generation.
|
C |
getFitness()
Return the fitness value of this
Phenotype. |
Function<Genotype<G>,C> |
getFitnessFunction()
Return the fitness function used by this phenotype to calculate the
(raw) fitness value.
|
Function<C,C> |
getFitnessScaler()
Return the fitness scaler used by this phenotype to scale the raw
fitness.
|
int |
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(Function<Genotype<G>,C> function,
Function<C,C> scaler,
int generation)
Return a new phenotype with the the genotype of this and with new
fitness function, fitness scaler and generation.
|
Phenotype<G,C> |
newInstance(Function<Genotype<G>,C> function,
int generation)
Return a new phenotype with the the genotype of this and with new
fitness function and generation.
|
static <C extends Comparable<? super C>> |
RawFitnees()
Deprecated.
Fixing typo, use
RawFitness() instead. |
static <C extends Comparable<? super C>> |
RawFitness()
Create a
Function which return the phenotype raw fitness when
calling converter.convert(phenotype). |
void |
run()
This method simply calls the
evaluate() method. |
String |
toString() |
Text |
toText() |
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
valueOf(Genotype<G> genotype,
Function<Genotype<G>,C> fitnessFunction,
Function<C,C> fitnessScaler,
int generation)
The
Genotype is copied to guarantee an immutable class. |
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
valueOf(Genotype<G> genotype,
Function<Genotype<G>,C> fitnessFunction,
int generation)
The
Genotype is copied to guarantee an immutable class. |
public Genotype<G> getGenotype()
Genotype, to guarantee a
immutable class.Genotype of this Phenotype.NullPointerException - if one of the arguments is null.public void 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<Genotype<G>,C> getFitnessFunction()
public Function<C,C> getFitnessScaler()
public C getFitness()
Phenotype.Phenotype.public C getRawFitness()
public int getGeneration()
Phenotype was created.Phenotype was created.public int getAge(int 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(Function<Genotype<G>,C> function, Function<C,C> scaler, int generation)
function - the (new) fitness scaler of the created phenotype.scaler - the (new) fitness scaler of the created phenotypegeneration - the generation of the new phenotype.NullPointerException - if one of the values is null.IllegalArgumentException - if the given generation is < 0.public Phenotype<G,C> newInstance(Function<Genotype<G>,C> function, int generation)
function - the (new) fitness scaler of the created phenotype.generation - the generation of the new phenotype.NullPointerException - if one of the values is null.IllegalArgumentException - if the given generation is < 0.public static Function<Phenotype<?,?>,Integer> Age(int currentGeneration)
Function which return the phenotype age when calling
converter.convert(phenotype).currentGeneration - the current generation.Function.public static Function<Phenotype<?,?>,Integer> Generation()
Function which return the phenotype generation when
calling converter.convert(phenotype).Function.public static <C extends Comparable<? super C>> Function<Phenotype<?,C>,C> Fitness()
Function which return the phenotype fitness when
calling converter.convert(phenotype).C - the fitness value type.Function.@Deprecated public static <C extends Comparable<? super C>> Function<Phenotype<?,C>,C> RawFitnees()
RawFitness() instead.Function which return the phenotype raw fitness when
calling converter.convert(phenotype).C - the fitness value type.Function.public static <C extends Comparable<? super C>> Function<Phenotype<?,C>,C> RawFitness()
Function which return the phenotype raw fitness when
calling converter.convert(phenotype).C - the fitness value type.Function.public static <G extends Gene<?,G>> Function<Phenotype<G,?>,Genotype<G>> Genotype()
Function which return the phenotype genotype when
calling converter.convert(phenotype).G - the gene type.Function.public static <G extends Gene<?,G>,C extends Comparable<? super C>> Phenotype<G,C> valueOf(Genotype<G> genotype, Function<Genotype<G>,C> fitnessFunction, int generation)
Genotype is copied to guarantee an immutable class. Only
the age of the Phenotype can be incremented.genotype - the genotype of this phenotype.fitnessFunction - the fitness function 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> valueOf(Genotype<G> genotype, Function<Genotype<G>,C> fitnessFunction, Function<C,C> fitnessScaler, int generation)
Genotype is copied to guarantee an immutable class. Only
the age of the Phenotype can be incremented.genotype - the genotype of this phenotype.fitnessFunction - the fitness function of this phenotype.fitnessScaler - the fitness scaler.generation - the current generation of the generated phenotype.NullPointerException - if one of the arguments is null.IllegalArgumentException - if the given generation is < 0.© 2007-2013 Franz Wilhelmstötter (2013-12-18 20:17)