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 Phenotype
s. 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.Constructor and Description |
---|
Phenotype(Genotype<G> genotype,
Function<? super Genotype<G>,? extends C> fitnessFunction,
Function<? super C,? extends C> fitnessScaler,
int generation)
Create a new phenotype from the given arguments.
|
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) |
Phenotype<G,C> |
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<? 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.
|
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<? super Genotype<G>,? extends C> function,
Function<? super C,? extends 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<? super Genotype<G>,? extends C> function,
int generation)
Return a new phenotype with the the genotype of this and with new
fitness function and generation.
|
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
of(Genotype<G> genotype,
Function<? super Genotype<G>,? extends C> fitnessFunction,
Function<? super C,? extends C> fitnessScaler,
int generation)
Create a new phenotype from the given arguments.
|
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
of(Genotype<G> genotype,
Function<? super Genotype<G>,C> fitnessFunction,
int generation)
The
Genotype is copied to guarantee an immutable class. |
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<? super Genotype<G>,? extends C> fitnessFunction,
Function<? super C,? extends C> fitnessScaler,
int generation)
Deprecated.
|
static <G extends Gene<?,G>,C extends Comparable<? super C>> |
valueOf(Genotype<G> genotype,
Function<Genotype<G>,C> fitnessFunction,
int generation)
Deprecated.
|
public Phenotype(Genotype<G> genotype, Function<? super Genotype<G>,? extends C> fitnessFunction, Function<? super C,? extends C> fitnessScaler, int generation)
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.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 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 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> newInstance(Function<? super Genotype<G>,? extends C> function, Function<? super C,? extends 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<? super Genotype<G>,? extends 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
.@Deprecated 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)
of(Genotype, org.jenetics.util.Function, org.jenetics.util.Function, int)
instead.public static <G extends Gene<?,G>,C extends Comparable<? super C>> Phenotype<G,C> of(Genotype<G> genotype, Function<? super 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.@Deprecated public static <G extends Gene<?,G>,C extends Comparable<? super C>> Phenotype<G,C> valueOf(Genotype<G> genotype, Function<? super Genotype<G>,? extends C> fitnessFunction, Function<? super C,? extends C> fitnessScaler, int generation)
of(Genotype, org.jenetics.util.Function, org.jenetics.util.Function, int)
insteadpublic static <G extends Gene<?,G>,C extends Comparable<? super C>> Phenotype<G,C> of(Genotype<G> genotype, Function<? super Genotype<G>,? extends C> fitnessFunction, Function<? super C,? extends C> fitnessScaler, int generation)
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-2014 Franz Wilhelmstötter (2014-03-07 19:35)