Class BinaryIntegerVariable

java.lang.Object
org.moeaframework.core.variable.BinaryVariable
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:
  • Constructor Summary

    Constructors
    Constructor
    Description
    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

    Modifier and Type
    Method
    Description
    Returns an independent copy of this decision variable.
    boolean
     
    int
    Returns the lower bound of this decision variable.
    static final int
    getNumberOfBits(int lowerBound, int upperBound)
    Returns the minimum number of bits required to represent an integer within the given bounds.
    int
    Returns the upper bound of this decision variable.
    int
    Returns the current value of this decision variable.
    int
     
    protected boolean
    Returns true if the binary representation using gray coding.
    void
    Randomly assign the value of this variable.
    void
    setValue(int value)
    Sets the value of this decision variable.
    Returns a human-readable representation of this value.

    Methods inherited from class org.moeaframework.core.variable.BinaryVariable

    cardinality, clear, decode, encode, get, getBitSet, getNumberOfBits, hammingDistance, isEmpty, set

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • 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 Details

    • 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()
      Description copied from interface: Variable
      Returns a human-readable representation of this value.
      Specified by:
      toString in interface Variable
      Overrides:
      toString in class BinaryVariable
      Returns:
      the value of this variable formatted as a string
    • 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