|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.openai.ai.ga.cell.encoding.FixedBinaryString
The FixedBinaryString
is an encoding method using a string
of binary digits. The value is represented as a long
and has
a fixed length in bits. It supports single cross-over and mutation.
Constructor Summary | |
FixedBinaryString(FixedBinaryString toClone)
Creates and returns a clone of the given FixedBinaryString . |
|
FixedBinaryString(java.lang.String name,
int size)
Creates a new FixedBinaryString with the specified bit-
length and given name. |
|
FixedBinaryString(java.lang.String name,
int size,
long value)
Creates a new FixedBinaryString with the specified bit-length
and initial value and given name. |
Method Summary | |
void |
clearBit(int bitNum)
Clears a given bit in the binary string |
static FixedBinaryString |
cross(FixedBinaryString first,
FixedBinaryString second)
Returns a new FixedBinaryString based on two other
binary strings of the same length. |
boolean |
getBit(int bitNum)
Returns the bit-status of a certain bit in this binary string. |
long |
getLong()
Returns the value of this binary string as a long . |
java.lang.String |
getName()
Gets the name of this binary string |
int |
getSize()
Returns the length of this binary string in bits |
void |
mutate(int amount)
Mutates a given number of bits in the binary string. |
void |
setBit(int bitNum)
Sets a given bit in the binary string |
void |
setLong(long newVal)
Sets the binary string to the value as a long . |
void |
setName(java.lang.String name)
Sets the name of this binary string to the given name |
void |
setSize(int size)
Sets the length of this binary string in bits |
java.lang.String |
toBinaryString()
Returns a String representation of this binary string as a
string of binary digits. |
java.lang.String |
toFullBinaryString()
Returns a String representation of this binary string as a
string of binary digits, including leading zeroes |
java.lang.String |
toFullHexString()
Returns a String representation of this binary string as a
string of hexadecimal digits, including leading zeroes |
java.lang.String |
toHexString()
Returns a String representation of this binary string as a
string of hex digits. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public FixedBinaryString(java.lang.String name, int size)
FixedBinaryString
with the specified bit-
length and given name.
name
- a String
representing the string's namesize
- the length of the binary string in bitspublic FixedBinaryString(java.lang.String name, int size, long value)
FixedBinaryString
with the specified bit-length
and initial value and given name.
name
- a String
representing the string's namesize
- the length of the binary string in bitsvalue
- the initial value for the binary stringpublic FixedBinaryString(FixedBinaryString toClone)
FixedBinaryString
.
Throws NullPointerException
when passed null
.
toClone
- the binary string to cloneMethod Detail |
public int getSize()
public void setSize(int size)
size
- the length of the binary string in bitspublic long getLong()
long
.
public void setLong(long newVal)
long
. Performs a
bit-wise AND (&) to clear all bits above the length of this binary string.
newVal
- a long
value to set this topublic boolean getBit(int bitNum)
public void setBit(int bitNum)
bitNum
- sets the given bit to true
("1")public void clearBit(int bitNum)
bitNum
- sets the given bit to false
("0")public void setName(java.lang.String name)
name
- a String
for the new namepublic java.lang.String getName()
public java.lang.String toBinaryString()
String
representation of this binary string as a
string of binary digits. Leading zeroes are trimmed.
public java.lang.String toFullBinaryString()
String
representation of this binary string as a
string of binary digits, including leading zeroes
public java.lang.String toHexString()
String
representation of this binary string as a
string of hex digits. Leading zeroes are trimmed.
public java.lang.String toFullHexString()
String
representation of this binary string as a
string of hexadecimal digits, including leading zeroes
public static FixedBinaryString cross(FixedBinaryString first, FixedBinaryString second)
FixedBinaryString
based on two other
binary strings of the same length. A cross-over point is picked at
random and all bits before this point are the same as the first parent's
and all bits after this point are the same as the second parent's.
Neither parent is altered during this call.
public void mutate(int amount)
amount
- the number of bits to invert ("mutate")
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |