public final class DoubleChromosome extends java.lang.Object implements Chromosome<DoubleChromosome>
Chromosome.Util
Modifier and Type | Field and Description |
---|---|
protected double |
defaultValue |
protected double[] |
genes |
protected double |
lowerBound |
protected double |
upperBound |
Constructor and Description |
---|
DoubleChromosome(DoubleChromosome chromosome)
Creates a new DoubleChromosome as a copy of the specified chromosome
|
DoubleChromosome(int length,
double lowerBound,
double upperBound)
Creates a DoubleChromosome with each allele in the range
[lowerBound, upperBound[
|
Modifier and Type | Method and Description |
---|---|
void |
average(DoubleChromosome chromosome,
double ratio)
Performs the weighted average between the genes in the two chromosomes.
|
DoubleChromosome |
clone()
Performs a chromosome deep-cloning.
|
void |
cross(DoubleChromosome chromosome,
int from)
Exchanges the genes chromosome starting from a given position
|
void |
cross(DoubleChromosome chromosome,
int from,
int to)
Exchanges the genes chromosome within the range [from,to]
|
void |
difference(DoubleChromosome chromosome,
double[] diff)
Computes the genetic difference between two chromosomes.
|
boolean |
equals(DoubleChromosome chromosome)
Compares the chromosome with another.
|
double |
getDefaultValue()
Returns the default value of this chromosome
|
double |
getLowerBound()
Returns the lower bound value for a gene of this chromosome
|
double |
getUpperBound()
Returns the upper bound value for a gene of this chromosome
|
double |
getValue(int pos)
Returns the double value at the specified position
|
double[] |
getValues()
Returns the double values
|
double[] |
getValues(double[] 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 |
owa(DoubleChromosome chromosome,
double ratio)
Performs the ordered weighted average (OWA) between the genes in the two chromosomes.
|
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(DoubleChromosome chromosome)
Makes the chromosome a copy of another chromosome.
|
void |
setDefaultValue(double defaultValue)
Sets the default value of this chromosome
|
void |
setDefaultValueAt(int pos)
Sets the default value at a given position
|
void |
setValue(int pos,
double 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
|
protected double[] genes
protected double upperBound
protected double lowerBound
protected double defaultValue
public DoubleChromosome(DoubleChromosome chromosome)
chromosome
- the chromosome to be copiedpublic DoubleChromosome(int length, double lowerBound, double upperBound)
length
- the chromosome lengthlowerBound
- the lower boundupperBound
- the upper boundpublic final void setDefaultValueAt(int pos)
Chromosome
setDefaultValueAt
in interface Chromosome<DoubleChromosome>
pos
- the position where to set the default valuepublic final DoubleChromosome clone()
Chromosome
clone
in interface Chromosome<DoubleChromosome>
clone
in class java.lang.Object
public final void swap(int pos1, int pos2)
Chromosome
swap
in interface Chromosome<DoubleChromosome>
pos1
- the position of first genepos2
- the position of second genepublic final void randomize()
Chromosome
randomize
in interface Chromosome<DoubleChromosome>
public final void randomize(int pos)
Chromosome
randomize
in interface Chromosome<DoubleChromosome>
pos
- a position where to set the random valuepublic final void leftShift(int from, int to)
Chromosome
leftShift
in interface Chromosome<DoubleChromosome>
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<DoubleChromosome>
from
- the start position to be shiftedto
- the final position to be shiftedpublic final int length()
Chromosome
length
in interface Chromosome<DoubleChromosome>
public final void setAs(DoubleChromosome chromosome)
Chromosome
setAs
in interface Chromosome<DoubleChromosome>
chromosome
- the chromosome to be copiedpublic final void cross(DoubleChromosome chromosome, int from)
Chromosome
cross
in interface Chromosome<DoubleChromosome>
chromosome
- the chromosome to cross withfrom
- the start position of the genes to exchangepublic final void cross(DoubleChromosome chromosome, int from, int to)
Chromosome
cross
in interface Chromosome<DoubleChromosome>
chromosome
- the chromosome to cross withfrom
- the start position of the genes to exchangeto
- the final position of the genes to exchangepublic final void average(DoubleChromosome chromosome, double ratio)
chromosome
- - the chromosome to combineratio
- - the coefficient used in the weighted averagepublic final void owa(DoubleChromosome chromosome, double ratio)
chromosome
- - the chromosome to combineratio
- - the coefficient used in the weighted averagepublic final double getValue(int pos)
pos
- a position of this chromosomepublic final double[] getValues()
public final double[] getValues(double[] values)
values
- the array to fillpublic final void setDefaultValue(double defaultValue)
defaultValue
- the new default value to be usedpublic final double getDefaultValue()
public final void setValue(int pos, double 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 double getLowerBound()
public final double getUpperBound()
public final boolean equals(DoubleChromosome chromosome)
equals
in interface Chromosome<DoubleChromosome>
chromosome
- the chromosome to compare to.public void difference(DoubleChromosome chromosome, double[] diff)
Chromosome
difference
in interface Chromosome<DoubleChromosome>
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<DoubleChromosome>