jenes.chromosome
Class BooleanChromosome

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

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

A BooleanChromosome is made of an array of booleans. Each gene can assume the value true or false. A faster and less memory demanding alternative to BooleanChromosome is provided by BitwiseChromosome with BooleanCoding.

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

Constructor Summary
BooleanChromosome(BooleanChromosome chromosome)
          Creates a new BooleanChromosome with the specified chromosome
BooleanChromosome(int size)
          Creates a new BooleanChromosome with the specified chromosome length
 
Method Summary
 BooleanChromosome clone()
          Performs a chromosome deep-cloning.
 void cross(BooleanChromosome chromosome, int from)
          Exchanges the genes chromosome starting from a given position
 void cross(BooleanChromosome chromosome, int from, int to)
          Exchanges the genes chromosome within the range [from,to]
 boolean equals(BooleanChromosome chromosome)
          Compares the chromosome with another.
 boolean getDefaultValue()
          Returns the default value of this chromosome
 boolean getValue(int pos)
          Returns the boolean value at the specified position
 boolean[] getValues()
          Returns the boolean values
 boolean[] getValues(boolean[] 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(BooleanChromosome chromosome)
          Makes the chromosome a copy of another chromosome.
 void setDefaultValue(boolean defaultValue)
          Sets the default value of this chromosome
 void setDefaultValueAt(int pos)
          Sets the default value at a given position
 void setValue(int pos, boolean value)
          Sets the specified value at the specified position
 void setValueAt(boolean value, int position)
          Sets a new boolean value at the specified position
 void swap(int pos1, int pos2)
          Exchanges two genes at the specified positions
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BooleanChromosome

public BooleanChromosome(BooleanChromosome chromosome)
Creates a new BooleanChromosome with the specified chromosome

Parameters:
chromosome - the parameters source chromosome

BooleanChromosome

public BooleanChromosome(int size)
Creates a new BooleanChromosome with the specified chromosome length

Parameters:
size - the chromosome length
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<BooleanChromosome>
Parameters:
pos - the position where to set the default value

clone

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

Specified by:
clone in interface Chromosome<BooleanChromosome>
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<BooleanChromosome>

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<BooleanChromosome>
Parameters:
pos - a position where to set the random value

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

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

setAs

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

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

cross

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

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

cross

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

Parameters:
pos - a gene position
Returns:
the boolean value at the specified position

getValues

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

Returns:
values

setValueAt

public final void setValueAt(boolean value,
                             int position)
Sets a new boolean value at the specified position

Parameters:
value - the value to be set
position - the position to modify

getValues

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

Parameters:
defaultValue - the new default value to be used

getDefaultValue

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

Returns:
the boolean default value of this chromosome

setValue

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

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

toString

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

equals

public final boolean equals(BooleanChromosome chromosome)
Description copied from interface: Chromosome
Compares the chromosome with another.

Specified by:
equals in interface Chromosome<BooleanChromosome>
Parameters:
chromosome - the cromosome to compare to.
Returns:
true if the two chromosome are equal, false otherwise.