jmetal.encodings.variable
Class Binary

java.lang.Object
  extended by jmetal.core.Variable
      extended by jmetal.encodings.variable.Binary
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BinaryReal

public class Binary
extends Variable

This class implements a generic binary string encodings.variable.It can be used as a base class other binary string based classes (e.g., binary coded integer or real variables).

See Also:
Serialized Form

Field Summary
 java.util.BitSet bits_
          Stores the bits constituting the binary string.
protected  int numberOfBits_
          Store the length of the binary string
 
Constructor Summary
Binary()
          Default constructor.
Binary(Binary variable)
          Copy constructor.
Binary(int numberOfBits)
          Constructor
 
Method Summary
 void decode()
          This method is intended to be used in subclass of Binary, for examples the classes, BinaryReal and BinaryInt.
 Variable deepCopy()
          Creates an exact copy of a Binary object
 boolean getIth(int bit)
          Returns the value of the ith bit.
 int getNumberOfBits()
          Returns the length of the binary string.
 int hammingDistance(Binary other)
          Obtain the hamming distance between two binary strings
 void setIth(int bit, boolean value)
          Sets the value of the ith bit.
 java.lang.String toString()
           
 
Methods inherited from class jmetal.core.Variable
getLowerBound, getUpperBound, getValue, getVariableType, setLowerBound, setUpperBound, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

bits_

public java.util.BitSet bits_
Stores the bits constituting the binary string. It is implemented using a BitSet object


numberOfBits_

protected int numberOfBits_
Store the length of the binary string

Constructor Detail

Binary

public Binary()
Default constructor.


Binary

public Binary(int numberOfBits)
Constructor

Parameters:
numberOfBits - Length of the bit string

Binary

public Binary(Binary variable)
Copy constructor.

Parameters:
variable - The Binary encodings.variable to copy.
Method Detail

decode

public void decode()
This method is intended to be used in subclass of Binary, for examples the classes, BinaryReal and BinaryInt. In this classes, the method allows to decode the value enconded in the binary string. As generic variables do not encode any value, this method do noting


deepCopy

public Variable deepCopy()
Creates an exact copy of a Binary object

Specified by:
deepCopy in class Variable
Returns:
An exact copy of the object.

getNumberOfBits

public int getNumberOfBits()
Returns the length of the binary string.

Returns:
The length

getIth

public boolean getIth(int bit)
Returns the value of the ith bit.

Parameters:
bit - The bit to retrieve
Returns:
The ith bit

setIth

public void setIth(int bit,
                   boolean value)
Sets the value of the ith bit.

Parameters:
bit - The bit to set

hammingDistance

public int hammingDistance(Binary other)
Obtain the hamming distance between two binary strings

Parameters:
other - The binary string to compare
Returns:
The hamming distance

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object