MOEA Framework 2.12
API Specification

org.moeaframework.core.variable
Class BinaryIntegerVariable

java.lang.Object
  extended by org.moeaframework.core.variable.BinaryVariable
      extended by org.moeaframework.core.variable.BinaryIntegerVariable
All Implemented Interfaces:
Serializable, Variable

public class BinaryIntegerVariable
extends BinaryVariable

Decision variable for integers encoded as a binary string. Note that if upperBound-lowerBound is not a power of 2, then some values will occur more frequently after a variation operator.

See Also:
Serialized Form

Constructor Summary
BinaryIntegerVariable(int lowerBound, int upperBound)
          Constructs an integer-valued variable in the range lowerBound <= x <= upperBound with an uninitialized value.
BinaryIntegerVariable(int lowerBound, int upperBound, boolean gray)
          Constructs an integer-valued variable in the range lowerBound <= x <= upperBound with an uninitialized value.
BinaryIntegerVariable(int value, int lowerBound, int upperBound)
          Constructs an integer-valued variable in the range lowerBound <= x <= upperBound with the specified initial value.
BinaryIntegerVariable(int value, int lowerBound, int upperBound, boolean gray)
          Constructs an integer-valued variable in the range lowerBound <= x <= upperBound with the specified initial value.
 
Method Summary
 BinaryIntegerVariable copy()
          Returns an independent copy of this decision variable.
 boolean equals(Object obj)
           
 int getLowerBound()
          Returns the lower bound of this decision variable.
static int getNumberOfBits(int lowerBound, int upperBound)
          Returns the minimum number of bits required to represent an integer within the given bounds.
 int getUpperBound()
          Returns the upper bound of this decision variable.
 int getValue()
          Returns the current value of this decision variable.
 int hashCode()
           
protected  boolean isGray()
          Returns true if the binary representation using gray coding.
 void randomize()
          Randomly assign the value of this variable.
 void setValue(int value)
          Sets the value of this decision variable.
 String toString()
           
 
Methods inherited from class org.moeaframework.core.variable.BinaryVariable
cardinality, clear, get, getBitSet, getNumberOfBits, hammingDistance, isEmpty, set
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BinaryIntegerVariable

public BinaryIntegerVariable(int lowerBound,
                             int upperBound)
Constructs an integer-valued variable in the range lowerBound <= x <= upperBound with an uninitialized value. Uses gray coding by default.

Parameters:
lowerBound - the lower bound of this decision variable, inclusive
upperBound - the upper bound of this decision variable, inclusive

BinaryIntegerVariable

public BinaryIntegerVariable(int value,
                             int lowerBound,
                             int upperBound)
Constructs an integer-valued variable in the range lowerBound <= x <= upperBound with the specified initial value. Uses gray coding by default.

Parameters:
value - the initial value of this decision variable
lowerBound - the lower bound of this decision variable, inclusive
upperBound - the upper bound of this decision variable, inclusive
Throws:
IllegalArgumentException - if the value is out of bounds (value < lowerBound) || (value > upperBound)

BinaryIntegerVariable

public BinaryIntegerVariable(int lowerBound,
                             int upperBound,
                             boolean gray)
Constructs an integer-valued variable in the range lowerBound <= x <= upperBound with an uninitialized value.

Parameters:
lowerBound - the lower bound of this decision variable, inclusive
upperBound - the upper bound of this decision variable, inclusive
gray - if the binary representation uses gray coding

BinaryIntegerVariable

public BinaryIntegerVariable(int value,
                             int lowerBound,
                             int upperBound,
                             boolean gray)
Constructs an integer-valued variable in the range lowerBound <= x <= upperBound with the specified initial value. Uses gray coding by default.

Parameters:
value - the initial value of this decision variable
lowerBound - the lower bound of this decision variable, inclusive
upperBound - the upper bound of this decision variable, inclusive
gray - if the binary representation uses gray coding
Throws:
IllegalArgumentException - if the value is out of bounds (value < lowerBound) || (value > upperBound)
Method Detail

getNumberOfBits

public static final int getNumberOfBits(int lowerBound,
                                        int upperBound)
Returns the minimum number of bits required to represent an integer within the given bounds.

Parameters:
lowerBound - the lower bound
upperBound - the upper bound
Returns:
the minimum number of bits required to represent an integer within the given bounds

getValue

public int getValue()
Returns the current value of this decision variable.

Returns:
the current value of this decision variable

setValue

public void setValue(int value)
Sets the value of this decision variable.

Parameters:
value - the new value for this decision variable
Throws:
IllegalArgumentException - if the value is out of bounds (value < getLowerBound()) || (value > getUpperBound())

isGray

protected boolean isGray()
Returns true if the binary representation using gray coding. Gray coding ensures that two successive values differ by only one bit.

Returns:
true if the binary representation using gray coding; false otherwise

getLowerBound

public int getLowerBound()
Returns the lower bound of this decision variable.

Returns:
the lower bound of this decision variable, inclusive

getUpperBound

public int getUpperBound()
Returns the upper bound of this decision variable.

Returns:
the upper bound of this decision variable, inclusive

copy

public BinaryIntegerVariable copy()
Description copied from interface: Variable
Returns an independent copy of this decision variable. It is required that x.copy() is completely independent from x. This means any method invoked on x.copy() in no way alters the state of x and vice versa. It is typically the case that x.copy().getClass() == x.getClass() and x.copy().equals(x).

Specified by:
copy in interface Variable
Overrides:
copy in class BinaryVariable
Returns:
an independent copy of this decision variable

hashCode

public int hashCode()
Overrides:
hashCode in class BinaryVariable

equals

public boolean equals(Object obj)
Overrides:
equals in class BinaryVariable

toString

public String toString()
Overrides:
toString in class BinaryVariable

randomize

public void randomize()
Description copied from interface: Variable
Randomly assign the value of this variable. In general, the randomization should follow a uniform distribution.

Specified by:
randomize in interface Variable
Overrides:
randomize in class BinaryVariable

MOEA Framework 2.12
API Specification

Copyright 2009-2016 MOEA Framework. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage. Visit us on Github!