|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjenes.chromosome.ObjectChromosome
public final class ObjectChromosome
An ObjectChromosome is made of objects. An AlleleSet
is
the ObjectChromosome.Gene
allele values alphabet.
One or more allele sets are required to instantiate an ObjectChromosome. All of genes can
have the same allele set or a different one according to ObjectChromosome constructor invoked.
An example of code is provided below.
ObjectChromosome chrom = new ObjectChromosome( new GenericAlleleSet(1, 2, 3), new GenericAlleleSet (true, false), new AnyDoubleGenericAlleleSetSubtype.createRandom(10, 0, 1) );
We instantiated an ObjectChromosome with three genes: the first one with Integer
allele
values 1, 2 and 3; the second one with Boolean
allele values and the last one with Double
values randomly distributed in the range [0,1].
GenericAlleleSet
is a concrete subclass of AlleleSet
interface; AnyDoubleGenericAlleleSetSubtype
is a subclass of GenericAlleleSet providing a static method to create randomly double values within a
specified range.
AlleleSet
,
GenericAlleleSet
Nested Class Summary | |
---|---|
static class |
ObjectChromosome.Gene
An ObjectChromosome 's gene. |
Field Summary | |
---|---|
protected java.lang.Object |
defaultValue
The default value for this chromosome. |
protected ObjectChromosome.Gene[] |
genes
The chromosome data structure |
Constructor Summary | |
---|---|
ObjectChromosome(AlleleSet... sets)
Creates a new ObjectChromosome with one gene for each AlleleSet within the
specified array. |
|
ObjectChromosome(AlleleSet set,
int size)
Creates a new ObjectChromosome with the specified length and with the same AlleleSet for each Gene . |
|
ObjectChromosome(java.util.List<AlleleSet> list)
Creates a new ObjectChromosome with one gene for each AlleleSet within the
specified list. |
|
ObjectChromosome(ObjectChromosome chromosome)
Creates a new ObjectChromosome; its genes will be equal to the specified ObjectChromosome's ones. |
Method Summary | |
---|---|
ObjectChromosome |
clone()
Performs a chromosome deep-cloning. |
void |
cross(ObjectChromosome chromosome,
int from)
Exchanges the genes chromosome starting from a given position |
void |
cross(ObjectChromosome chromosome,
int from,
int to)
Exchanges the genes chromosome within the range [from,to] |
boolean |
equals(ObjectChromosome chromosome)
Compares the chromosome with another. |
java.lang.Object |
getDeafultValue()
Returns the default value of this chromosome |
ObjectChromosome.Gene |
getGene(int index)
Returns the gene at the specified position |
java.lang.Object |
getValue(int pos)
Returns the object allele value at the specified position |
java.lang.Object[] |
getValues()
Returns the Object values |
java.lang.Object[] |
getValues(java.lang.Object[] values)
gets the array of double values by filling the double values passed as parameters |
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(ObjectChromosome chromosome)
Makes the chromosome a copy of another chromosome. |
void |
setDefaultValue(java.lang.Object defaultValue)
Sets the default value of this chromosome. |
void |
setDefaultValueAt(int pos)
Sets the default value at a given position |
void |
setGene(int pos,
java.lang.Object value)
Sets the specified 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 ObjectChromosome.Gene[] genes
protected java.lang.Object defaultValue
null
or belonging to every AlleleSet
.
Constructor Detail |
---|
public ObjectChromosome(AlleleSet set, int size)
AlleleSet
for each Gene
.
size
- the chromosome lengthset
- the genes' AlleleSet
public ObjectChromosome(ObjectChromosome chromosome)
chromosome
- the source ObjectChromosome
public ObjectChromosome(AlleleSet... sets)
AlleleSet
within the
specified array.
The chromosome genes will contain random allele values.
sets
- the alleleset arraypublic ObjectChromosome(java.util.List<AlleleSet> list)
AlleleSet
within the
specified list.
The chromosome genes will contain random allele values.
list
- the java.util.List
with all of AlleleSet
Method Detail |
---|
public final void setDefaultValueAt(int pos)
Chromosome
setDefaultValueAt
in interface Chromosome<ObjectChromosome>
pos
- the position where to set the default valuepublic final ObjectChromosome clone()
Chromosome
clone
in interface Chromosome<ObjectChromosome>
clone
in class java.lang.Object
public final void randomize()
Chromosome
randomize
in interface Chromosome<ObjectChromosome>
public final void randomize(int pos)
Chromosome
randomize
in interface Chromosome<ObjectChromosome>
pos
- a position where to set the random valuepublic final void swap(int pos1, int pos2)
Chromosome
swap
in interface Chromosome<ObjectChromosome>
pos1
- the position of first genepos2
- the position of second genepublic final void leftShift(int from, int to)
Chromosome
leftShift
in interface Chromosome<ObjectChromosome>
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<ObjectChromosome>
from
- the start position to be shiftedto
- the final position to be shiftedpublic final int length()
Chromosome
length
in interface Chromosome<ObjectChromosome>
public final void setAs(ObjectChromosome chromosome)
Chromosome
setAs
in interface Chromosome<ObjectChromosome>
chromosome
- the chromosome to be copiedpublic final void cross(ObjectChromosome chromosome, int from)
Chromosome
cross
in interface Chromosome<ObjectChromosome>
chromosome
- the chromosome to cross withfrom
- the start position of the genes to exchangepublic final void cross(ObjectChromosome chromosome, int from, int to)
Chromosome
cross
in interface Chromosome<ObjectChromosome>
chromosome
- the chromosome to cross withfrom
- the start position of the genes to exchangeto
- the final position of the genes to exchangepublic final java.lang.Object getValue(int pos)
pos
- a position into this population
public final java.lang.Object[] getValues()
public final java.lang.Object[] getValues(java.lang.Object[] values)
values
-
public final void setDefaultValue(java.lang.Object defaultValue)
null
or belonging to every AlleleSet
.
defaultValue
- the new default value to be usedpublic final java.lang.Object getDeafultValue()
public final void setGene(int pos, java.lang.Object value)
pos
- the position to be modifyvalue
- the value to be setpublic final ObjectChromosome.Gene getGene(int index)
index
- the index of the gene
public final java.lang.String toString()
toString
in class java.lang.Object
public final boolean equals(ObjectChromosome chromosome)
Chromosome
equals
in interface Chromosome<ObjectChromosome>
chromosome
- the cromosome to compare to.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |