es.udc.gii.common.eaf.algorithm.population
Class Individual

java.lang.Object
  extended by es.udc.gii.common.eaf.algorithm.population.Individual
All Implemented Interfaces:
Configurable, java.io.Externalizable, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
JADEIndividual, MaIndividual, NSGA2Individual

public class Individual
extends java.lang.Object
implements java.lang.Cloneable, Configurable, java.io.Externalizable

This class represents a basic individual of the population.

Since:
1.0
Author:
Grupo Integrado de IngenierĂ­a (www.gii.udc.es)
See Also:
Serialized Form

Field Summary
private  org.apache.commons.math.util.DoubleArray[] chromosomes
          Array of chromosomes of the individual.
private  FitnessComparator<Individual> comparator
          Fitness comparator of the individual.
private  java.util.List<java.lang.Double> constraints
          List of the constraint values.
private  double fitness
          Fitness value of the individual.
private  java.util.List<java.lang.Double> objectives
          List of the objective values.
private  boolean serializeEvalResults
           
private  boolean serializeGenotype
           
private  int violatedConstraints
          Number of violated constraints.
 
Constructor Summary
Individual()
          Creates a new instance of Individual
Individual(org.apache.commons.math.util.DoubleArray[] chromosomes)
          Creates a new instance of Individual with a DoubleArray of chromosomes.
 
Method Summary
private  boolean checkChromosomes(org.apache.commons.math.util.DoubleArray[] c_1, org.apache.commons.math.util.DoubleArray[] c_2)
           
 java.lang.Object clone()
          Clones the current individual.
 void configure(org.apache.commons.configuration.Configuration conf)
          Configures the current individual.
 void copyEvalResults(Individual other)
          Copies the evaluation results of this individual to the passed individual.
 void copyGenotype(Individual other)
          Copies the genotype of this individual to the passed individual.
 boolean equals(java.lang.Object obj)
          Tests if two individuals are or are not equals.
 void generate()
          Generates the chromosomes of the Individual with values in [-1.0,1.0]
 double[] getChromosomeAt(int index)
          Returns the chromosome at index of the individual.
 org.apache.commons.math.util.DoubleArray[] getChromosomes()
          Returns the chromosomes of the individual.
 FitnessComparator<Individual> getComparator()
          Returns the fitness comparator of this individual.
 java.util.List<java.lang.Double> getConstraints()
          Returns the values of the contraint functions evaluate with the chromosomes of this Individual.
 int getDimension()
          Returns the dimension of this individual as the sum of the dimensions of all its chromosomes.
 double getFitness()
          Returns the fitness value of the Individual.
 java.util.List<java.lang.Double> getObjectives()
          Restuns the value of the objective functions evaluate with the chromosomes of this Individual.
 int getViolatedConstraints()
          Returns the number of violated constraints.
 int hashCode()
          Resturns the hashCode of an Individual.
 boolean isSerializeEvalResults()
          Before and while serialization this method returns true if the evaluation results should be serialized and false otherwise.
 boolean isSerializeGenotype()
          Before and while serialization this method returns true if the genotype information should be serialized and false otherwise.
 void readExternal(java.io.ObjectInput in)
          This method is called whenever an instance of this class has to be de-serialized.
 void setChromosomeAt(int index, double[] chromosome)
          Sets a double array chromosome to the current individual at position index.
 void setChromosomes(org.apache.commons.math.util.DoubleArray[] chromosomes)
          Sets an array of chromosomes to the current Individual.
 void setComparator(FitnessComparator<Individual> comparator)
          Sets the fitness comparator of this individual.
 void setConstraints(java.util.List<java.lang.Double> constraints)
          Sets the values of the constraint functions evaluate by this individual.
 void setDimension(int[] dimensions)
          Sets the dimension of each chromosome of the individual.
 void setFitness(double fitness)
          Sets the fitness value of the Individual.
 void setObjectives(java.util.List<java.lang.Double> objectives)
          Sets the values of the objectives functions evaluate by this individual.
 void setSerializeEvalResults(boolean serializePhenotype)
          This method controls the behaviour of the serialization of an instance of this class.
 void setSerializeGenotype(boolean serializeGenotype)
          This method controls the behaviour of the serialization of an instance of this class.
 void setViolatedConstraints(int violatedConstraints)
          Sets the number of violated constraints of the Individual.
 java.lang.String toString()
          Resturns a String representation of the Individual.
 void writeExternal(java.io.ObjectOutput out)
          This method is called whenever an instance of this class has to be serialized.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

fitness

private double fitness
Fitness value of the individual.


objectives

private java.util.List<java.lang.Double> objectives
List of the objective values.


constraints

private java.util.List<java.lang.Double> constraints
List of the constraint values.


violatedConstraints

private int violatedConstraints
Number of violated constraints.


chromosomes

private org.apache.commons.math.util.DoubleArray[] chromosomes
Array of chromosomes of the individual.


serializeEvalResults

private boolean serializeEvalResults

serializeGenotype

private boolean serializeGenotype

comparator

private FitnessComparator<Individual> comparator
Fitness comparator of the individual.

Constructor Detail

Individual

public Individual()
Creates a new instance of Individual


Individual

public Individual(org.apache.commons.math.util.DoubleArray[] chromosomes)
Creates a new instance of Individual with a DoubleArray of chromosomes.

Parameters:
chromosomes - DoubleArray of the individual's chromosomes.
Method Detail

configure

public void configure(org.apache.commons.configuration.Configuration conf)
Configures the current individual.

Specified by:
configure in interface Configurable
Parameters:
conf - configuration's parameters to configure the current individual.
See Also:
Configuration

getComparator

public FitnessComparator<Individual> getComparator()
Returns the fitness comparator of this individual.

Returns:
the fitness comparator of this individual.

setComparator

public void setComparator(FitnessComparator<Individual> comparator)
Sets the fitness comparator of this individual.

Parameters:
comparator - the fitness comparator of this individual.

getFitness

public double getFitness()
Returns the fitness value of the Individual.

Returns:
fitness the fitness value of the Individual.

setFitness

public void setFitness(double fitness)
Sets the fitness value of the Individual.

Parameters:
fitness - the new fitness value of the Individual.

getChromosomes

public org.apache.commons.math.util.DoubleArray[] getChromosomes()
Returns the chromosomes of the individual.

Returns:
chromosomes an array of chromososmes of the individual.

getChromosomeAt

public double[] getChromosomeAt(int index)
Returns the chromosome at index of the individual.

Parameters:
index - index of the chromosome to return.
Returns:
the double array of the chromosome at index.

setChromosomes

public void setChromosomes(org.apache.commons.math.util.DoubleArray[] chromosomes)
Sets an array of chromosomes to the current Individual.

Parameters:
chromosomes - a new array of chromosomes.

setChromosomeAt

public void setChromosomeAt(int index,
                            double[] chromosome)
Sets a double array chromosome to the current individual at position index.

Parameters:
index - position to set the new chromosome.
chromosome - a chromosme to be set at position index.

getViolatedConstraints

public int getViolatedConstraints()
Returns the number of violated constraints.

Returns:
violated_contraint the number of violated constraints.

setViolatedConstraints

public void setViolatedConstraints(int violatedConstraints)
Sets the number of violated constraints of the Individual.

Parameters:
violatedConstraints - number of violated constraints.

getObjectives

public java.util.List<java.lang.Double> getObjectives()
Restuns the value of the objective functions evaluate with the chromosomes of this Individual.

Returns:
objectives a list with the values of the objective functions evaluate with this Individual.

setObjectives

public void setObjectives(java.util.List<java.lang.Double> objectives)
Sets the values of the objectives functions evaluate by this individual.

Parameters:
objectives - list of values of the objective functions.

getConstraints

public java.util.List<java.lang.Double> getConstraints()
Returns the values of the contraint functions evaluate with the chromosomes of this Individual.

Returns:
contraints list of values of the contraint functions.

setConstraints

public void setConstraints(java.util.List<java.lang.Double> constraints)
Sets the values of the constraint functions evaluate by this individual.

Parameters:
constraints - list of values of the objective functions.

setSerializeGenotype

public void setSerializeGenotype(boolean serializeGenotype)
This method controls the behaviour of the serialization of an instance of this class. Setting true means that the genotype information will be serialized (and hence will be transmitted, for example, via sockets). Setting false means that the genotype information won't be serialized.

Parameters:
serializeGenotype -

setSerializeEvalResults

public void setSerializeEvalResults(boolean serializePhenotype)
This method controls the behaviour of the serialization of an instance of this class. Setting true means that the evaluation results (objectives, contraint values, ...) will be serialized (and hence will be transmitted, for example, via sockets). Setting false means that this information won't be serialized.

Parameters:
serializePhenotype - true or false.

isSerializeGenotype

public boolean isSerializeGenotype()
Before and while serialization this method returns true if the genotype information should be serialized and false otherwise.

While de-serialization this method returns true if the genotype information should be de-serialized. After de-serialization it returns true if genotype information has been de-serialized. It returns false otherwise.


isSerializeEvalResults

public boolean isSerializeEvalResults()
Before and while serialization this method returns true if the evaluation results should be serialized and false otherwise.

While de-serialization this method returns true if the evaluation results should be de-serialized. After de-serialization it returns true if the evaluation results heve been de-serialized. It returns false otherwise.


generate

public void generate()
Generates the chromosomes of the Individual with values in [-1.0,1.0]


getDimension

public int getDimension()
Returns the dimension of this individual as the sum of the dimensions of all its chromosomes.

Returns:
the dimension of this individual.

setDimension

public void setDimension(int[] dimensions)
Sets the dimension of each chromosome of the individual.

Parameters:
dimensions - array of dimensions.

toString

public java.lang.String toString()
Resturns a String representation of the Individual.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the Individual.

clone

public java.lang.Object clone()
Clones the current individual.

Overrides:
clone in class java.lang.Object
Returns:
a new individual which is a copy of the current one.

equals

public boolean equals(java.lang.Object obj)
Tests if two individuals are or are not equals.

Overrides:
equals in class java.lang.Object
Parameters:
obj - another Individual to compare.
Returns:
true if they are equal, false in other case.

checkChromosomes

private boolean checkChromosomes(org.apache.commons.math.util.DoubleArray[] c_1,
                                 org.apache.commons.math.util.DoubleArray[] c_2)

hashCode

public int hashCode()
Resturns the hashCode of an Individual.

Overrides:
hashCode in class java.lang.Object
Returns:
the hashCode of an Individual.

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
This method is called whenever an instance of this class has to be serialized.

It might write to the output out the evaluation results or the genotype information or both, deppending on the value of Individual#getSerializeEvalResults and Individual#getSerializeGenotype, which are always writen at the beginning of the output to know later what type of information is contained in the data.

Subclasses should override this method if they introduce new attibutes. Remember to call super.writeExternal() in order to be sure that the state of the parent class is serialized.

Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
out - - DataOutput to write the serialized bytes to.
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
This method is called whenever an instance of this class has to be de-serialized.

It sets the values of Individual#getSerializeEvalResults and Individual#getSerializeGenotype accordingly to the information received so that subclasses can rely on them to know what kind of information is to be read.

Subclasses should override this method if they introduce new attibutes. Remember to call super.readExternal() in order to be sure that the state of the parent class is de-serialized and the values of Individual#getSerializeEvalResults and Individual#getSerializeGenotype contain the right information.

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in - - DataInput from which the bytes are read.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

copyEvalResults

public void copyEvalResults(Individual other)
Copies the evaluation results of this individual to the passed individual. No deep copy is made, so this object and the passed individual share this information.

Subclasses of Individual have to override this method and call super.copyEvalResults() in order to handle the copy of the possible extra attibutes introduced in the subclass.

Parameters:
other - - The individual into which the phenotype of this object will be copied.

copyGenotype

public void copyGenotype(Individual other)
Copies the genotype of this individual to the passed individual. No deep copy is made, so this object and the passed individual share the genotype information.

Subclasses of Individual have to override this method and call super.copyGenotype() in order to handle the copy of the extra genotype information introduced in the subclass.

Parameters:
other - - The individual into which the genotype of this object will be copied.