T
- The type of chromosome.public final class Individual<T extends Chromosome> extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable, java.lang.Comparable<Individual<T>>
Chromosome
representing its genoma, and a score representing its fitness.
To be valid, the score must be non-negative.
A key point is how to compare individuals.
There two ways in comparing individuals: by fitness and chromosome.
The compareTo(Individual)
method tests if scores are equal or which one is bigger
regardless at their genoma.
The equals(Individual)
methods compares the chromosome. In order to gain efficiency in
comparing individuals, the isSameChromosomeSameFitness()
property is used to shortcut
the procedure.
If this property is true, equals
returns true according to the score, thus avoiding to
perform an expensive chromosome comparison.
Indeed, by setting the sameChromosomeSameFitness
property to true, we assume that is not possible
to have two different chromosome with the same score. Appliability fo this property depends on the
problem and search landscape characteristics.
Obviously, we assume that individuals with the same chromosome must show the fitness value.
In complex search spaces, not every solution is feasible. The solution feasability is controlled
by the legal
property.
Population
,
Chromosome
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
Individual.Statistics<T extends Chromosome>
This class provides some basic statistics regarding an
Individual . |
Modifier and Type | Field and Description |
---|---|
static int |
UNRANKED
the default individual's rank
|
Constructor and Description |
---|
Individual()
Creates an
Individual with no genome. |
Individual(Individual<T> ind)
Constructs a new
Individual as a copy of another Individual . |
Individual(int n,
T chromosome)
Creates an
Individual with a specific chromosome and a number of scores. |
Individual(T chromosome,
double... score)
Creates an
Individual with the specified genome and a given score array(fitness value). |
Modifier and Type | Method and Description |
---|---|
Individual<T> |
clone()
Returns a cloned instance of this class
|
int |
compareTo(Individual<T> ind)
Compares this individual with the specified individual.
|
boolean |
equals(Individual<T> ind)
Indicates whether the other individual is "equal to" this one.
|
double[] |
getAllScores()
Returns all scores
|
T |
getChromosome()
Returns the
Individual 's genome
|
int |
getChromosomeLength()
Returns the chromosome's length
|
int |
getNumOfObjectives()
Returns the number of objectivies for which this
Individual is evaluated
|
Population<T> |
getPopulation()
Return the
Population that contains this Individual
|
int |
getRank()
Returns the individual's rank
|
double |
getScore()
Returns the
Individual 's fitness value
This score is meaningful only if isEvaluated() returns true. |
double |
getScore(int i)
Return the score at a specific position
|
int |
getSpeciem()
Returns the subpopulation the individual belongs to
|
Individual.Statistics<T> |
getStatistics()
Returns the
Individual.Statistics of this Individual |
boolean |
isEvaluated()
Tests if the
Individual is evaluated |
boolean |
isLegal()
Tests if this Individual is a legal individual
i.e is a feasible solution.
|
static boolean |
isSameChromosomeSameFitness()
Returns true if individual with the same chromosome must have also the same fitness (if evaluated),
false otherwise
|
void |
randomize()
Randomizes the genome (chromosome) of this
Individual |
void |
resetScores(int m)
Reset the array of scores by setting each value to
Double.NaN . |
void |
setAs(Individual<T> individual)
Sets this
Individual as the specified one. |
void |
setAs(Individual<T> individual,
boolean full)
Sets this
Individual 's genome equal
to the specified Individual 's one |
void |
setChromosome(T chromosome)
Sets the
Individual 's genome
|
void |
setLegal(boolean legal)
Sets the legal state of this individual
|
void |
setNotEvaluated()
Sets this individual as not evaluated.
|
static void |
setSameChromosomeSameFitness(boolean sameChromosomeSameFitness)
Set to true if individual with the same chromosome must have also the same fitness (if evaluated),
false otherwise
|
void |
setScore(double... score)
Sets the
Individual 's fitness value. |
void |
setScore(double score,
int i)
Set the score at specific position and check if this
Individual is evaluated |
void |
setSpeciem(int speciem)
Sets the subpopulation the individual belongs to
|
java.lang.String |
toCompleteString()
Returns a full textual representation of this Individual
|
java.lang.String |
toString() |
public static final int UNRANKED
public Individual()
Individual
with no genome.public Individual(int n, T chromosome)
Individual
with a specific chromosome and a number of scores.n
- number of scoreschromosome
- individual's chromosomepublic Individual(T chromosome, double... score)
Individual
with the specified genome and a given score array(fitness value).chromosome
- individual's genomescore
- individual's score arraypublic Individual(Individual<T> ind)
Individual
as a copy of another Individual
.
ind
- the source Individual
.public final Population<T> getPopulation()
Population
that contains this Individual
public final T getChromosome()
Individual
's genome
public final void setChromosome(T chromosome)
Individual
's genome
chromosome
- the Individual
's genomepublic final int getNumOfObjectives()
Individual
is evaluated
public final double getScore()
Individual
's fitness value
This score is meaningful only if isEvaluated()
returns true.
Otherwise the score is equal to Double.NaN
.
Individual
's fitness valuepublic final double getScore(int i)
i
- index of array's scorepublic final double[] getAllScores()
public final void resetScores(int m)
Double.NaN
.
If the value given as argument is different from the actual length
of scores' array, a new array is created.m
- lenght of scores' arraypublic final void setScore(double... score)
Individual
's fitness value.score
- the Individual
's fitness valuepublic final void setScore(double score, int i)
Individual
is evaluatedscore
- value of scorei
- array's indexpublic final void setNotEvaluated()
public int getRank()
public int getSpeciem()
public void setSpeciem(int speciem)
speciem
- - the subpopulation idpublic final Individual<T> clone()
clone
in class java.lang.Object
public final void randomize()
Individual
public final void setAs(Individual<T> individual)
Individual
as the specified one.
individual
- the model individualpublic final void setAs(Individual<T> individual, boolean full)
Individual
's genome equal
to the specified Individual
's oneindividual
- the instance to copy aspublic final boolean isEvaluated()
Individual
is evaluatedtrue
if the Individual
is evaluated; false
otherwisepublic final java.lang.String toCompleteString()
public final java.lang.String toString()
toString
in class java.lang.Object
public final boolean isLegal()
true
if this individual is a legal solution; flase
otherwise.public final void setLegal(boolean legal)
legal
- true
if legal; false
otherwise.public final int compareTo(Individual<T> ind)
compareTo
in interface java.lang.Comparable<Individual<T extends Chromosome>>
ind
- the individual to be compared.public final boolean equals(Individual<T> ind)
ind
- the reference individual with which to compare.true
if the individual has the same chromosome and score as the other; false
otherwise.public final int getChromosomeLength()
public static final boolean isSameChromosomeSameFitness()
public static final void setSameChromosomeSameFitness(boolean sameChromosomeSameFitness)
sameChromosomeSameFitness
- the sameChromosomeSameFitness valuepublic Individual.Statistics<T> getStatistics()
Individual.Statistics
of this Individual
Individual.Statistics
object