jenes.chromosome
Class PermutationChromosome

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

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

This class provides a chromosome able to model permutations. An array of integer values is its genoma. Each value is in the range [0,length-1] where length is the chromosome length. The most importatnt property is that each value is never duplicated: each value is contained just once. All the chromosome operations preserve this chromosome property.

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

Field Summary
protected  int[] permutation
          This data structure keeps the permutation order
protected  int[] position
          This data structure keeps the position of elements in the permuted order
 
Constructor Summary
PermutationChromosome(int length)
          Creates a new PermutationChromosome with the specified length.
PermutationChromosome(PermutationChromosome chromosome)
          Creates a new PermutationChromosome using the specified one as model
 
Method Summary
 PermutationChromosome clone()
          Performs a chromosome deep-cloning.
 void cross(PermutationChromosome chromosome, int from)
          Exchanges the genes chromosome starting from a given position
 void cross(PermutationChromosome chromosome, int from, int to)
          Exchanges the genes chromosome within the range [from,to]
 boolean equals(PermutationChromosome chromosome)
          Compares the chromosome with another.
 int getElementAt(int index)
          Returns the element at the specified position
 int getPositionOf(int element)
          Provides the element position
 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)
          Perform a random transformation of gene at the specified positions, by exchanging it with another element randomly chosen.
 void rightShift(int from, int to)
          Makes a right-shift of the genes between two positions.
 void setAs(PermutationChromosome chromosome)
          Makes the chromosome a copy of another chromosome.
 void setDefaultValueAt(int pos)
          Sets the default 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
 

Field Detail

permutation

protected int[] permutation
This data structure keeps the permutation order


position

protected int[] position
This data structure keeps the position of elements in the permuted order

Constructor Detail

PermutationChromosome

public PermutationChromosome(PermutationChromosome chromosome)
Creates a new PermutationChromosome using the specified one as model

Parameters:
chromosome - the chromosome model

PermutationChromosome

public PermutationChromosome(int length)
Creates a new PermutationChromosome with the specified length.

Parameters:
length - the chromosome length
Method Detail

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

getElementAt

public final int getElementAt(int index)
Returns the element at the specified position

Parameters:
index - of the element to return
Returns:
the desired allele value

getPositionOf

public final int getPositionOf(int element)
Provides the element position

Parameters:
element - a chromosome element
Returns:
the position of the specified element

setDefaultValueAt

public final void setDefaultValueAt(int pos)
Sets the default value at the specified position. For the permutation chromosome it is the original value in that position, that is pos itself.

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

cross

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

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

cross

public final void cross(PermutationChromosome 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<PermutationChromosome>
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

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<PermutationChromosome>
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<PermutationChromosome>
Parameters:
from - the start position to be shifted
to - the final position to be shifted

randomize

public final void randomize(int pos)
Perform a random transformation of gene at the specified positions, by exchanging it with another element randomly chosen.

Specified by:
randomize in interface Chromosome<PermutationChromosome>
Parameters:
pos - the position to randomize

randomize

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

Specified by:
randomize in interface Chromosome<PermutationChromosome>

setAs

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

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

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

equals

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

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

clone

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

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

toString

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