jenes.chromosome
Class IntegerChromosome

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

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

An IntegerChromosome is made of an array of integers. Each value (i.e. allele) is within the range [lowerBound,upperBound]. Both bounds are included. These bounds are specified ad the instantiation time. IntegerChromosome is a fixed length chromosome. Thus the numebr of genes is specified at the instantiation time and cannot be modified after.

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

Constructor Summary
IntegerChromosome(IntegerChromosome chromosome)
          Creates a new IntegerIndividual with the specified chromosome
IntegerChromosome(int length, int lowerBound, int upperBound)
          Creates a new IntegerIndividual with each allele in the range [lowerBound, upperBound]
 
Method Summary
 IntegerChromosome clone()
          Performs a chromosome deep-cloning.
 void cross(IntegerChromosome chromosome, int from)
          Exchanges the genes chromosome starting from a given position
 void cross(IntegerChromosome chromosome, int from, int to)
          Exchanges the genes chromosome within the range [from,to]
 boolean equals(IntegerChromosome chromosome)
          Compares the chromosome with another.
 int getDefaultValue()
          Returns the default value of this chromosome
 int getLowerBound()
          Returns the lower bound value for a gene of this chromosome
 int getUpperBound()
          Returns the upper bound value for a gene of this chromosome
 int getValue(int pos)
          Returns the integer value at the specified position
 int[] getValues()
          Returns the integer values
 int[] getValues(int[] 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(IntegerChromosome chromosome)
          Makes the chromosome a copy of another chromosome.
 void setDefaultValue(int defaultValue)
          Sets the default value of this chromosome
 void setDefaultValueAt(int pos)
          Sets the default value at a given position
 void setValue(int pos, int 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

IntegerChromosome

public IntegerChromosome(IntegerChromosome chromosome)
Creates a new IntegerIndividual with the specified chromosome

Parameters:
chromosome - the parameters source chromosome

IntegerChromosome

public IntegerChromosome(int length,
                         int lowerBound,
                         int upperBound)
Creates a new IntegerIndividual with each allele in the range [lowerBound, upperBound]

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

getLowerBound

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

Returns:
the alleles lower bound

getUpperBound

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

Returns:
the alleles upper bound

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<IntegerChromosome>
Parameters:
pos - the position where to set the default value

clone

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

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

randomize

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

Specified by:
randomize in interface Chromosome<IntegerChromosome>

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<IntegerChromosome>
Parameters:
pos1 - the position of first gene
pos2 - the position of second gene

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<IntegerChromosome>
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<IntegerChromosome>
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<IntegerChromosome>
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<IntegerChromosome>
Returns:
the length of chromosome.

setAs

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

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

cross

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

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

cross

public final void cross(IntegerChromosome 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<IntegerChromosome>
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 int getValue(int pos)
Returns the integer value at the specified position

Parameters:
pos - a position into this population
Returns:
the integer value at the specified position

getValues

public final int[] getValues()
Returns the integer values

Returns:
values

getValues

public final int[] getValues(int[] 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(int defaultValue)
Sets the default value of this chromosome

Parameters:
defaultValue - the new default value to be used

getDefaultValue

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

Returns:
the integer default value of this chromosome

setValue

public final void setValue(int pos,
                           int 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

equals

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

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