jenes.chromosome
Class DoubleChromosome

java.lang.Object
  extended by jenes.chromosome.DoubleChromosome
All Implemented Interfaces:
java.lang.Cloneable, Chromosome<DoubleChromosome>

public final class DoubleChromosome
extends java.lang.Object
implements Chromosome<DoubleChromosome>

A DoubleChromosome is made of an array of double values. Each value is in the range [lowerBound,upperBound[. The lower bound is include included, the upper bound not. Both the bounds are specified ad the instantiation time. DoubleChromosome is a fixed length chromosome class, thus number of genes is specified at instantiation time and cannot be modified after.

Since:
1.0
Version:
1.2
Author:
Luigi Troiano, Pierpaolo Lombardi, Giuseppe Pascale, Thierry Bodhuin

Constructor Summary
DoubleChromosome(DoubleChromosome chromosome)
          Creates a new DoubleChromosome as a copy of the specified chromosome
DoubleChromosome(int length, double lowerBound, double upperBound)
          Creates a DoubleChromosome with each allele in the range [lowerBound, upperBound[
 
Method Summary
 DoubleChromosome clone()
          Performs a chromosome deep-cloning.
 void cross(DoubleChromosome chromosome, int from)
          Exchanges the genes chromosome starting from a given position
 void cross(DoubleChromosome chromosome, int from, int to)
          Exchanges the genes chromosome within the range [from,to]
 boolean equals(DoubleChromosome chromosome)
          Compares the chromosome with another.
 double getDefaultValue()
          Returns the default value of this chromosome
 double getLowerBound()
          Returns the lower bound value for a gene of this chromosome
 double getUpperBound()
          Returns the upper bound value for a gene of this chromosome
 double getValue(int pos)
          Returns the double value at the specified position
 double[] getValues()
          Returns the double values
 double[] getValues(double[] values)
          Provides the gene values by the array passed as parameter and returning it on return.
 void leftShift(int from, int to)
          Makes a left-shift of the genes between two positions.
 int length()
          Returns the number of genes contained in the chromosome.
 void randomize()
          Fills the chromosome with random value.
 void randomize(int pos)
          Sets a random value in the specified position
 void rightShift(int from, int to)
          Makes a right-shift of the genes between two positions.
 void setAs(DoubleChromosome chromosome)
          Makes the chromosome a copy of another chromosome.
 void setDefaultValue(double defaultValue)
          Sets the default value of this chromosome
 void setDefaultValueAt(int pos)
          Sets the default value at a given position
 void setValue(int pos, double value)
          Sets the specified value at the specified position
 void swap(int pos1, int pos2)
          Exchanges two genes at the specified positions
 java.lang.String toString()
          Provides a textual chromosome representation
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DoubleChromosome

public DoubleChromosome(DoubleChromosome chromosome)
Creates a new DoubleChromosome as a copy of the specified chromosome

Parameters:
chromosome - the chromosome to be copied

DoubleChromosome

public DoubleChromosome(int length,
                        double lowerBound,
                        double upperBound)
Creates a DoubleChromosome with each allele in the range [lowerBound, upperBound[

Parameters:
length - the chromosome length
lowerBound - the lower bound
upperBound - the upper bound
Method Detail

setDefaultValueAt

public final void setDefaultValueAt(int pos)
Description copied from interface: Chromosome
Sets the default value at a given position

Specified by:
setDefaultValueAt in interface Chromosome<DoubleChromosome>
Parameters:
pos - the position where to set the default value

clone

public final DoubleChromosome clone()
Description copied from interface: Chromosome
Performs a chromosome deep-cloning.

Specified by:
clone in interface Chromosome<DoubleChromosome>
Overrides:
clone in class java.lang.Object
Returns:
a chromosome clone.

swap

public final void swap(int pos1,
                       int pos2)
Description copied from interface: Chromosome
Exchanges two genes at the specified positions

Specified by:
swap in interface Chromosome<DoubleChromosome>
Parameters:
pos1 - the position of first gene
pos2 - the position of second gene

randomize

public final void randomize()
Description copied from interface: Chromosome
Fills the chromosome with random value.

Specified by:
randomize in interface Chromosome<DoubleChromosome>

randomize

public final void randomize(int pos)
Description copied from interface: Chromosome
Sets a random value in the specified position

Specified by:
randomize in interface Chromosome<DoubleChromosome>
Parameters:
pos - a position where to set the random value

leftShift

public final void leftShift(int from,
                            int to)
Description copied from interface: Chromosome
Makes a left-shift of the genes between two positions. The shift is circular, so the most left-side gene becomes the last gene on right.

Specified by:
leftShift in interface Chromosome<DoubleChromosome>
Parameters:
from - the start position to be shifted
to - the final position to be shifted

rightShift

public final void rightShift(int from,
                             int to)
Description copied from interface: Chromosome
Makes a right-shift of the genes between two positions. The shift is circular, so the most right-side gene becomes the first gene on left.

Specified by:
rightShift in interface Chromosome<DoubleChromosome>
Parameters:
from - the start position to be shifted
to - the final position to be shifted

length

public final int length()
Description copied from interface: Chromosome
Returns the number of genes contained in the chromosome.

Specified by:
length in interface Chromosome<DoubleChromosome>
Returns:
the length of chromosome.

setAs

public final void setAs(DoubleChromosome chromosome)
Description copied from interface: Chromosome
Makes the chromosome a copy of another chromosome.

Specified by:
setAs in interface Chromosome<DoubleChromosome>
Parameters:
chromosome - the chromosome to be copied

cross

public final void cross(DoubleChromosome chromosome,
                        int from)
Description copied from interface: Chromosome
Exchanges the genes chromosome starting from a given position

Specified by:
cross in interface Chromosome<DoubleChromosome>
Parameters:
chromosome - the chromosome to cross with
from - the start position of the genes to exchange

cross

public final void cross(DoubleChromosome chromosome,
                        int from,
                        int to)
Description copied from interface: Chromosome
Exchanges the genes chromosome within the range [from,to]

Specified by:
cross in interface Chromosome<DoubleChromosome>
Parameters:
chromosome - the chromosome to cross with
from - the start position of the genes to exchange
to - the final position of the genes to exchange

getValue

public final double getValue(int pos)
Returns the double value at the specified position

Parameters:
pos - a position of this chromosome
Returns:
the double value at the specified position

getValues

public final double[] getValues()
Returns the double values

Returns:
values

getValues

public final double[] getValues(double[] values)
Provides the gene values by the array passed as parameter and returning it on return. If the argument values is null, the array is first created.

Parameters:
values - the array to fill
Returns:
the array of values

setDefaultValue

public final void setDefaultValue(double defaultValue)
Sets the default value of this chromosome

Parameters:
defaultValue - the new default value to be used

getDefaultValue

public final double getDefaultValue()
Returns the default value of this chromosome

Returns:
the double default value of this chromosome

setValue

public final void setValue(int pos,
                           double value)
Sets the specified value at the specified position

Parameters:
pos - the position to be modify
value - the value to be insert

toString

public final java.lang.String toString()
Provides a textual chromosome representation

Overrides:
toString in class java.lang.Object
Returns:
the textual chromosome representation

getLowerBound

public final double getLowerBound()
Returns the lower bound value for a gene of this chromosome

Returns:
the alleles lower bound

getUpperBound

public final double getUpperBound()
Returns the upper bound value for a gene of this chromosome

Returns:
the alleles upper bound

equals

public final boolean equals(DoubleChromosome chromosome)
Compares the chromosome with another.

Specified by:
equals in interface Chromosome<DoubleChromosome>
Parameters:
chromosome - the chromosome to compare to.
Returns:
True, if the two chromosome are equal.