|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jenes.chromosome.BitwiseChromosome
public final class BitwiseChromosome
This class provides chromosomes made of bits. Its genome contains objects
coded according to a specified BitwiseChromosome.BitCoding
. Typically objects coded by this chromosome
are numeric values. The default integer representation is used
when no BitCoding is specified.
A BitwiseChromosome has size and length attributes. The size is the number of coded value contained by its genoma; the length is the number of bits. The length depends on which coding is used for translating objects into bits. The relation between size and length is shown below:
where aCoding.SIZE.BITS is the number of bits required for coding one object.aBitwiseChromosome.length() = aBitwiseChromosome.getSize() * aCoding.SIZE.BITS
This Chromosome performs genetic operations at bit level, processing an array of integer, thus ensuring a high throughput and minimal memory occupation. Using a 16 bit representation, a chromosome holding 4 objects (size) will be represented by 32 bits (length), thus by 2 integers (as each of integer is represented by 32 bit)
Nested Class Summary | |
---|---|
static class |
BitwiseChromosome.BitCoding<T>
Represents the coding used by a BitwiseChromosome . |
static class |
BitwiseChromosome.BitSize
Definition of the number bit length and mask to use in the coding operations. |
Constructor Summary | |
---|---|
BitwiseChromosome(BitwiseChromosome chromosome)
Creates a new BitwiseChromosome using the specified one as prototype |
|
BitwiseChromosome(int size)
Creates a new BitwiseChromosome with the specified number of objects. |
|
BitwiseChromosome(int size,
BitwiseChromosome.BitCoding coding)
Creates a new BitwiseChromosome with the specified number of objects and coding. |
Method Summary | |
---|---|
BitwiseChromosome |
clone()
Makes a chromosome copy |
void |
cross(BitwiseChromosome chromosome,
int from)
Exchanges the chromosome bits from the specified cross site to the final position |
void |
cross(BitwiseChromosome chromosome,
int from,
int to)
Exchanges the chromosome bits in the range [from,to]. |
boolean |
equals(BitwiseChromosome chromosome)
Compares the chromosome with another. |
int |
getBitValueAt(int index)
Returns the bit value at the specified position. |
int |
getIntLength()
Returns the chromosome length expressed in integers |
int |
getIntSize()
Returns the number of integer used by the chromosome for coding the objects |
int |
getIntValueAt(int index)
Returns the int value at the specified position |
int |
getSize()
Returns the number of coded objects contained by this chromosome. |
BitwiseChromosome.BitCoding |
getType()
Returns the BitwiseChromosome.BitCoding used by this chromosome |
java.lang.Object |
getValueAt(int index)
Returns the object value at the specified position in the chromosome. |
void |
leftShift(int from,
int to)
Executes the left shift of bits within the specified range. |
int |
length()
Returns the chromosome length expressed in bits. |
void |
randomize()
Randomizes each chromosome bit |
void |
randomize(int pos)
Randomizes the bit at the given position |
void |
rightShift(int from,
int to)
Executes the right shift of bits within the specified range. |
void |
setAs(BitwiseChromosome chromosome)
Sets this chromosome as a copy of another. |
void |
setBitValueAt(int index,
int bit)
Sets the bit at a given position. |
void |
setDefaultValueAt(int pos)
Sets the default bit value at the a given position |
void |
setIntValueAt(int index,
int value)
Sets the int value at the specified position |
void |
setValue(int index,
java.lang.Object value)
Sets the specified object value at the given position. |
void |
swap(int pos1,
int pos2)
Swaps two bits at given positions |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BitwiseChromosome(int size)
size
- the number of objects the chromosone representspublic BitwiseChromosome(int size, BitwiseChromosome.BitCoding coding)
size
- the number of chromosome coded objectscoding
- the coding to usepublic BitwiseChromosome(BitwiseChromosome chromosome)
chromosome
- the chromosome to copyMethod Detail |
---|
public final BitwiseChromosome.BitCoding getType()
BitwiseChromosome.BitCoding
used by this chromosome
public final int getSize()
public final int getIntValueAt(int index)
index
- the index of the value to return
public final void setIntValueAt(int index, int value)
index
- the index of the element to be modifyvalue
- the value to setpublic final int getIntSize()
public final java.lang.Object getValueAt(int index)
index
- the position
public final void setValue(int index, java.lang.Object value)
index
- the positionvalue
- the object value to be placedpublic final int getBitValueAt(int index)
index
- the position
public final void setBitValueAt(int index, int bit)
index
- the positionbit
- the bit valuepublic final void cross(BitwiseChromosome chromosome, int from, int to)
cross
in interface Chromosome<BitwiseChromosome>
chromosome
- the chromosome to cross withfrom
- the initial cross siteto
- the final cross sitepublic final void cross(BitwiseChromosome chromosome, int from)
cross
in interface Chromosome<BitwiseChromosome>
chromosome
- the chromosome to cross withfrom
- the initial cross sitepublic final boolean equals(BitwiseChromosome chromosome)
equals
in interface Chromosome<BitwiseChromosome>
chromosome
- the chromosome to compare to.
public final int length()
Integer.SIZE
)
length
in interface Chromosome<BitwiseChromosome>
public final int getIntLength()
public final void randomize(int pos)
randomize
in interface Chromosome<BitwiseChromosome>
pos
- the position of bit to alterpublic final void randomize()
randomize
in interface Chromosome<BitwiseChromosome>
public final void leftShift(int from, int to)
leftShift
in interface Chromosome<BitwiseChromosome>
from
- the lower range limitto
- the upper range limitpublic final void rightShift(int from, int to)
rightShift
in interface Chromosome<BitwiseChromosome>
from
- the lower range limitto
- the upper range limitpublic final void setAs(BitwiseChromosome chromosome)
setAs
in interface Chromosome<BitwiseChromosome>
chromosome
- the chromosome to copypublic final void setDefaultValueAt(int pos)
setDefaultValueAt
in interface Chromosome<BitwiseChromosome>
pos
- bit positionpublic final void swap(int pos1, int pos2)
swap
in interface Chromosome<BitwiseChromosome>
pos1
- first bit positionpos2
- second bit positionpublic final BitwiseChromosome clone()
clone
in interface Chromosome<BitwiseChromosome>
clone
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |