public final class IntegerChromosome extends java.lang.Object implements Chromosome<IntegerChromosome>
Chromosome
Chromosome.Util
Constructor and Description |
---|
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]
|
Modifier and Type | Method and Description |
---|---|
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]
|
void |
difference(IntegerChromosome chromosome,
double[] diff)
Computes the genetic difference between two chromosomes.
|
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.Object[] |
toArray()
Returns an array containing all of the genes in chromosome.
|
java.lang.String |
toString()
Provides a textual chromosome representation
|
public IntegerChromosome(IntegerChromosome chromosome)
chromosome
- the parameters source chromosomepublic IntegerChromosome(int length, int lowerBound, int upperBound)
length
- the chromosome lengthlowerBound
- the allele lower boundupperBound
- the allele upper boundpublic final int getLowerBound()
public final int getUpperBound()
public final void setDefaultValueAt(int pos)
Chromosome
setDefaultValueAt
in interface Chromosome<IntegerChromosome>
pos
- the position where to set the default valuepublic final IntegerChromosome clone()
Chromosome
clone
in interface Chromosome<IntegerChromosome>
clone
in class java.lang.Object
public final void randomize()
Chromosome
randomize
in interface Chromosome<IntegerChromosome>
public final void swap(int pos1, int pos2)
Chromosome
swap
in interface Chromosome<IntegerChromosome>
pos1
- the position of first genepos2
- the position of second genepublic final void randomize(int pos)
Chromosome
randomize
in interface Chromosome<IntegerChromosome>
pos
- a position where to set the random valuepublic final void leftShift(int from, int to)
Chromosome
leftShift
in interface Chromosome<IntegerChromosome>
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<IntegerChromosome>
from
- the start position to be shiftedto
- the final position to be shiftedpublic final int length()
Chromosome
length
in interface Chromosome<IntegerChromosome>
public final void setAs(IntegerChromosome chromosome)
Chromosome
setAs
in interface Chromosome<IntegerChromosome>
chromosome
- the chromosome to be copiedpublic final void cross(IntegerChromosome chromosome, int from)
Chromosome
cross
in interface Chromosome<IntegerChromosome>
chromosome
- the chromosome to cross withfrom
- the start position of the genes to exchangepublic final void cross(IntegerChromosome chromosome, int from, int to)
Chromosome
cross
in interface Chromosome<IntegerChromosome>
chromosome
- the chromosome to cross withfrom
- the start position of the genes to exchangeto
- the final position of the genes to exchangepublic final int getValue(int pos)
pos
- a position into this populationpublic final int[] getValues()
public final int[] getValues(int[] values)
values
- the array to fillpublic final void setDefaultValue(int defaultValue)
defaultValue
- the new default value to be usedpublic final int getDefaultValue()
public final void setValue(int pos, int value)
pos
- the position to be modifyvalue
- the value to be insertpublic final java.lang.String toString()
toString
in class java.lang.Object
public final boolean equals(IntegerChromosome chromosome)
equals
in interface Chromosome<IntegerChromosome>
chromosome
- the chromosome to compare to.public void difference(IntegerChromosome chromosome, double[] diff)
Chromosome
difference
in interface Chromosome<IntegerChromosome>
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<IntegerChromosome>