|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjenes.chromosome.PermutationChromosome
public final class 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.
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 |
---|
protected int[] permutation
protected int[] position
Constructor Detail |
---|
public PermutationChromosome(PermutationChromosome chromosome)
chromosome
- the chromosome modelpublic PermutationChromosome(int length)
length
- the chromosome lengthMethod Detail |
---|
public final int length()
Chromosome
length
in interface Chromosome<PermutationChromosome>
public final int getElementAt(int index)
index
- of the element to return
public final int getPositionOf(int element)
element
- a chromosome element
public final void setDefaultValueAt(int pos)
setDefaultValueAt
in interface Chromosome<PermutationChromosome>
pos
- the position where to set the default valuepublic final void cross(PermutationChromosome chromosome, int from)
Chromosome
cross
in interface Chromosome<PermutationChromosome>
chromosome
- the chromosome to cross withfrom
- the start position of the genes to exchangepublic final void cross(PermutationChromosome chromosome, int from, int to)
Chromosome
cross
in interface Chromosome<PermutationChromosome>
chromosome
- the chromosome to cross withfrom
- the start position of the genes to exchangeto
- the final position of the genes to exchangepublic final void leftShift(int from, int to)
Chromosome
leftShift
in interface Chromosome<PermutationChromosome>
from
- the start position to be shiftedto
- the final position to be shiftedpublic final void rightShift(int from, int to)
Chromosome
rightShift
in interface Chromosome<PermutationChromosome>
from
- the start position to be shiftedto
- the final position to be shiftedpublic final void randomize(int pos)
randomize
in interface Chromosome<PermutationChromosome>
pos
- the position to randomizepublic final void randomize()
Chromosome
randomize
in interface Chromosome<PermutationChromosome>
public final void setAs(PermutationChromosome chromosome)
Chromosome
setAs
in interface Chromosome<PermutationChromosome>
chromosome
- the chromosome to be copiedpublic final void swap(int pos1, int pos2)
Chromosome
swap
in interface Chromosome<PermutationChromosome>
pos1
- the position of first genepos2
- the position of second genepublic final boolean equals(PermutationChromosome chromosome)
Chromosome
equals
in interface Chromosome<PermutationChromosome>
chromosome
- the cromosome to compare to.
public final PermutationChromosome clone()
Chromosome
clone
in interface Chromosome<PermutationChromosome>
clone
in class java.lang.Object
public final java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |