jenes.population
Class Individual<T extends Chromosome>

java.lang.Object
  extended by jenes.population.Individual<T>
Type Parameters:
T - The type of chromosome.
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Individual<T>>

public final class Individual<T extends Chromosome>
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable, java.lang.Comparable<Individual<T>>

Individual represents a solution processed by a genetic algorithm. It is made of a 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.

Since:
1.0
Version:
1.2
Author:
Luigi Troiano, Pierpaolo Lombardi, Giuseppe Pascale, Thierry Bodhuin
See Also:
Population, Chromosome, Serialized Form

Constructor Summary
Individual(Individual<T> ind)
          Constructs a new Individual as a copy of another Individual.
Individual(T chromosome)
          Creates an Individual with the specified genome.
Individual(T chromosome, double score)
          Creates an Individual with the specified genome and a given score (fitness value).
 
Method Summary
 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.
 T getChromosome()
          Returns the Individual's genome
 int getChromosomeLength()
          Returns the chromosome's length
 double getScore()
          Returns the Individual's fitness value This score is meaningful only if isEvaluated() returns true.
 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()
          Return 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 setAs(Individual<T> individual)
          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.
 java.lang.String toCompleteString()
          Returns a full textual representation of this Individual
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Individual

public Individual(T chromosome)
Creates an Individual with the specified genome. It results not evaluated.

Parameters:
chromosome - individual's genome

Individual

public Individual(T chromosome,
                  double score)
Creates an Individual with the specified genome and a given score (fitness value).

Parameters:
chromosome - individual's genome
score - individual's score

Individual

public Individual(Individual<T> ind)
Constructs a new Individual as a copy of another Individual.

Parameters:
ind - the source Individual.
Method Detail

getChromosome

public final T getChromosome()
Returns the Individual's genome

Returns:
the individual's genome

setChromosome

public final void setChromosome(T chromosome)
Sets the Individual's genome

Parameters:
chromosome - the Individual's genome

getScore

public final double getScore()
Returns the Individual's fitness value This score is meaningful only if isEvaluated() returns true. Otherwise the score is equal to Double.NaN.

Returns:
the Individual's fitness value

setScore

public final void setScore(double score)
Sets the Individual's fitness value.

Parameters:
score - the Individual's fitness value

setNotEvaluated

public final void setNotEvaluated()
Sets this individual as not evaluated.


clone

public final Individual<T> clone()
Returns a cloned instance of this class

Overrides:
clone in class java.lang.Object
Returns:
a clone of this Individual

randomize

public final void randomize()
Randomizes the genome (chromosome) of this individual


setAs

public final void setAs(Individual<T> individual)
Sets this Individual's genome equal to the specified Individual's one

Parameters:
individual - the instance to copy as

isEvaluated

public final boolean isEvaluated()
Tests if the Individual is evaluated

Returns:
true if the Individual is evaluated; false otherwise

toCompleteString

public final java.lang.String toCompleteString()
Returns a full textual representation of this Individual

Returns:
representation

toString

public final java.lang.String toString()
Overrides:
toString in class java.lang.Object

isLegal

public final boolean isLegal()
Tests if this Individual is a legal individual i.e is a feasible solution.

Returns:
true if this individual is a legal solution; flase otherwise.

setLegal

public final void setLegal(boolean legal)
Sets the legal state of this individual

Parameters:
legal - true if legal; false otherwise.

compareTo

public final int compareTo(Individual<T> ind)
Compares this individual with the specified individual. Returns a negative, zero or positive value as the individual is lesser than, equal to, or greater than the specified individual. The comparison is based on the chromosome score. Note: this class has a natural ordering that is inconsistent with equals.

Specified by:
compareTo in interface java.lang.Comparable<Individual<T extends Chromosome>>
Parameters:
ind - the individual to be compared.

equals

public final boolean equals(Individual<T> ind)
Indicates whether the other individual is "equal to" this one. i.e if they have the same fitness and the same chromosome

Parameters:
ind - the reference individual with which to compare.
Returns:
true if this individual is the same as the ind argument; false otherwise.

getChromosomeLength

public final int getChromosomeLength()
Returns the chromosome's length

Returns:
the chromosome's length

isSameChromosomeSameFitness

public static final boolean isSameChromosomeSameFitness()
Return true if individual with the same chromosome must have also the same fitness (if evaluated), false otherwise

Returns:
the sameChromosomeSameFitness field value

setSameChromosomeSameFitness

public static final void setSameChromosomeSameFitness(boolean sameChromosomeSameFitness)
Set to true if individual with the same chromosome must have also the same fitness (if evaluated), false otherwise

Parameters:
sameChromosomeSameFitness - the sameChromosomeSameFitness value