public final class BooleanChromosome extends java.lang.Object implements Chromosome<BooleanChromosome>
BitwiseChromosome
with BooleanCoding
.Chromosome.Util
Constructor and Description |
---|
BooleanChromosome(BooleanChromosome chromosome)
Creates a new BooleanChromosome with the specified chromosome
|
BooleanChromosome(int size)
Creates a new BooleanChromosome with the specified chromosome length
|
Modifier and Type | Method and Description |
---|---|
BooleanChromosome |
clone()
Performs a chromosome deep-cloning.
|
void |
cross(BooleanChromosome chromosome,
int from)
Exchanges the genes chromosome starting from a given position
|
void |
cross(BooleanChromosome chromosome,
int from,
int to)
Exchanges the genes chromosome within the range [from,to]
|
void |
difference(BooleanChromosome chromosome,
double[] diff)
Computes the genetic difference between two chromosomes.
|
boolean |
equals(BooleanChromosome chromosome)
Compares the chromosome with another.
|
boolean |
getDefaultValue()
Returns the default value of this chromosome
|
boolean |
getValue(int pos)
Returns the boolean value at the specified position
|
boolean[] |
getValues()
Returns the boolean values
|
boolean[] |
getValues(boolean[] 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(BooleanChromosome chromosome)
Makes the chromosome a copy of another chromosome.
|
void |
setDefaultValue(boolean defaultValue)
Sets the default value of this chromosome
|
void |
setDefaultValueAt(int pos)
Sets the default value at a given position
|
void |
setValue(int pos,
boolean value)
Sets the specified value at the specified position
|
void |
setValueAt(boolean value,
int position)
Sets a new boolean 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() |
public BooleanChromosome(BooleanChromosome chromosome)
chromosome
- the parameters source chromosomepublic BooleanChromosome(int size)
size
- the chromosome lengthpublic final void setDefaultValueAt(int pos)
Chromosome
setDefaultValueAt
in interface Chromosome<BooleanChromosome>
pos
- the position where to set the default valuepublic final BooleanChromosome clone()
Chromosome
clone
in interface Chromosome<BooleanChromosome>
clone
in class java.lang.Object
public final void randomize()
Chromosome
randomize
in interface Chromosome<BooleanChromosome>
public final void randomize(int pos)
Chromosome
randomize
in interface Chromosome<BooleanChromosome>
pos
- a position where to set the random valuepublic final void swap(int pos1, int pos2)
Chromosome
swap
in interface Chromosome<BooleanChromosome>
pos1
- the position of first genepos2
- the position of second genepublic final void leftShift(int from, int to)
Chromosome
leftShift
in interface Chromosome<BooleanChromosome>
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<BooleanChromosome>
from
- the start position to be shiftedto
- the final position to be shiftedpublic final int length()
Chromosome
length
in interface Chromosome<BooleanChromosome>
public final void setAs(BooleanChromosome chromosome)
Chromosome
setAs
in interface Chromosome<BooleanChromosome>
chromosome
- the chromosome to be copiedpublic final void cross(BooleanChromosome chromosome, int from)
Chromosome
cross
in interface Chromosome<BooleanChromosome>
chromosome
- the chromosome to cross withfrom
- the start position of the genes to exchangepublic final void cross(BooleanChromosome chromosome, int from, int to)
Chromosome
cross
in interface Chromosome<BooleanChromosome>
chromosome
- the chromosome to cross withfrom
- the start position of the genes to exchangeto
- the final position of the genes to exchangepublic final boolean getValue(int pos)
pos
- a gene positionpublic final boolean[] getValues()
public final void setValueAt(boolean value, int position)
value
- the value to be setposition
- the position to modifypublic final boolean[] getValues(boolean[] values)
values
- the array to fillpublic final void setDefaultValue(boolean defaultValue)
defaultValue
- the new default value to be usedpublic final boolean getDefaultValue()
public final void setValue(int pos, boolean value)
pos
- the position to be modifyvalue
- the value to be setpublic final java.lang.String toString()
toString
in class java.lang.Object
public final boolean equals(BooleanChromosome chromosome)
Chromosome
equals
in interface Chromosome<BooleanChromosome>
chromosome
- the cromosome to compare to.public void difference(BooleanChromosome chromosome, double[] diff)
Chromosome
difference
in interface Chromosome<BooleanChromosome>
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<BooleanChromosome>