net.openai.ai.ga.cell.encoding
Class FixedBinaryString

java.lang.Object
  |
  +--net.openai.ai.ga.cell.encoding.FixedBinaryString

public class FixedBinaryString
extends java.lang.Object

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.

Since:
JDK1.3
Version:
%I%, %G%
Author:
Jared Grubb

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

FixedBinaryString

public FixedBinaryString(java.lang.String name,
                         int size)
Creates a new FixedBinaryString with the specified bit- length and given name.

Parameters:
name - a String representing the string's name
size - the length of the binary string in bits

FixedBinaryString

public FixedBinaryString(java.lang.String name,
                         int size,
                         long value)
Creates a new FixedBinaryString with the specified bit-length and initial value and given name.

Parameters:
name - a String representing the string's name
size - the length of the binary string in bits
value - the initial value for the binary string

FixedBinaryString

public FixedBinaryString(FixedBinaryString toClone)
Creates and returns a clone of the given FixedBinaryString. Throws NullPointerException when passed null.

Parameters:
toClone - the binary string to clone
Method Detail

getSize

public int getSize()
Returns the length of this binary string in bits


setSize

public void setSize(int size)
Sets the length of this binary string in bits

Parameters:
size - the length of the binary string in bits

getLong

public long getLong()
Returns the value of this binary string as a long.


setLong

public void setLong(long newVal)
Sets the binary string to the value as a long. Performs a bit-wise AND (&) to clear all bits above the length of this binary string.

Parameters:
newVal - a long value to set this to

getBit

public boolean getBit(int bitNum)
Returns the bit-status of a certain bit in this binary string.


setBit

public void setBit(int bitNum)
Sets a given bit in the binary string

Parameters:
bitNum - sets the given bit to true ("1")

clearBit

public void clearBit(int bitNum)
Clears a given bit in the binary string

Parameters:
bitNum - sets the given bit to false ("0")

setName

public void setName(java.lang.String name)
Sets the name of this binary string to the given name

Parameters:
name - a String for the new name

getName

public java.lang.String getName()
Gets the name of this binary string


toBinaryString

public java.lang.String toBinaryString()
Returns a String representation of this binary string as a string of binary digits. Leading zeroes are trimmed.


toFullBinaryString

public java.lang.String toFullBinaryString()
Returns a String representation of this binary string as a string of binary digits, including leading zeroes


toHexString

public java.lang.String toHexString()
Returns a String representation of this binary string as a string of hex digits. Leading zeroes are trimmed.


toFullHexString

public java.lang.String toFullHexString()
Returns a String representation of this binary string as a string of hexadecimal digits, including leading zeroes


cross

public static FixedBinaryString cross(FixedBinaryString first,
                                      FixedBinaryString second)
Returns a new 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.


mutate

public void mutate(int amount)
Mutates a given number of bits in the binary string. The mutation is the inversion of the bit. A non-positive argument results in no change in the string.

Parameters:
amount - the number of bits to invert ("mutate")


Copyright - 2001 OpenAI Labs. All Rights Reserved.