public final class PermutationChromosome extends java.lang.Object implements Chromosome<PermutationChromosome>
Chromosome.Util
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
PermutationChromosome(int length)
Creates a new PermutationChromosome with the specified length.
|
PermutationChromosome(PermutationChromosome chromosome)
Creates a new PermutationChromosome using the specified one as model
|
Modifier and Type | Method and Description |
---|---|
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]
|
void |
difference(PermutationChromosome chromosome,
double[] diff)
Computes the genetic difference between two chromosomes.
|
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.Object[] |
toArray()
Returns an array containing all of the genes in chromosome.
|
int[] |
toNaturalOrdering()
Provides the gene offsets to reach the natural order, according to equation p = n + o, where
p is the permutation vector, n the natural order (i.e. 0,1,2..) and o the offset vector.
|
java.lang.String |
toString() |
protected int[] permutation
protected int[] position
public PermutationChromosome(PermutationChromosome chromosome)
chromosome
- the chromosome modelpublic PermutationChromosome(int length)
length
- the chromosome lengthpublic final int length()
Chromosome
length
in interface Chromosome<PermutationChromosome>
public final int getElementAt(int index)
index
- of the element to returnpublic final int getPositionOf(int element)
element
- a chromosome elementpublic 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
public final int[] toNaturalOrdering()
public void difference(PermutationChromosome chromosome, double[] diff)
Chromosome
difference
in interface Chromosome<PermutationChromosome>
chromosome
- - the chromosome to quantify the minus fromdiff
- - the variable to be filled by the minus valuespublic java.lang.Object[] toArray()
Chromosome
toArray
in interface Chromosome<PermutationChromosome>