Package org.moeaframework.core.variable
Class BinaryIntegerVariable
java.lang.Object
org.moeaframework.core.variable.BinaryVariable
org.moeaframework.core.variable.BinaryIntegerVariable
- All Implemented Interfaces:
Serializable
,Variable
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
ConstructorDescriptionBinaryIntegerVariable
(int lowerBound, int upperBound) Constructs an integer-valued variable in the rangelowerBound <= x <= upperBound
with an uninitialized value.BinaryIntegerVariable
(int lowerBound, int upperBound, boolean gray) Constructs an integer-valued variable in the rangelowerBound <= x <= upperBound
with an uninitialized value.BinaryIntegerVariable
(int value, int lowerBound, int upperBound) Constructs an integer-valued variable in the rangelowerBound <= x <= upperBound
with the specified initial value.BinaryIntegerVariable
(int value, int lowerBound, int upperBound, boolean gray) Constructs an integer-valued variable in the rangelowerBound <= x <= upperBound
with the specified initial value. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
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
getValue()
Returns the current value of this decision variable.int
hashCode()
protected boolean
isGray()
Returnstrue
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.toString()
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
-
Constructor Details
-
BinaryIntegerVariable
public BinaryIntegerVariable(int lowerBound, int upperBound) Constructs an integer-valued variable in the rangelowerBound <= x <= upperBound
with an uninitialized value. Uses gray coding by default.- Parameters:
lowerBound
- the lower bound of this decision variable, inclusiveupperBound
- the upper bound of this decision variable, inclusive
-
BinaryIntegerVariable
public BinaryIntegerVariable(int value, int lowerBound, int upperBound) Constructs an integer-valued variable in the rangelowerBound <= x <= upperBound
with the specified initial value. Uses gray coding by default.- Parameters:
value
- the initial value of this decision variablelowerBound
- the lower bound of this decision variable, inclusiveupperBound
- 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 rangelowerBound <= x <= upperBound
with an uninitialized value.- Parameters:
lowerBound
- the lower bound of this decision variable, inclusiveupperBound
- the upper bound of this decision variable, inclusivegray
- 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 rangelowerBound <= x <= upperBound
with the specified initial value. Uses gray coding by default.- Parameters:
value
- the initial value of this decision variablelowerBound
- the lower bound of this decision variable, inclusiveupperBound
- the upper bound of this decision variable, inclusivegray
- 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 boundupperBound
- 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()Returnstrue
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
Description copied from interface:Variable
Returns an independent copy of this decision variable. It is required thatx.copy()
is completely independent fromx
. This means any method invoked onx.copy()
in no way alters the state ofx
and vice versa. It is typically the case thatx.copy().getClass() == x.getClass()
andx.copy().equals(x)
.- Specified by:
copy
in interfaceVariable
- Overrides:
copy
in classBinaryVariable
- Returns:
- an independent copy of this decision variable
-
hashCode
public int hashCode()- Overrides:
hashCode
in classBinaryVariable
-
equals
- Overrides:
equals
in classBinaryVariable
-
toString
Description copied from interface:Variable
Returns a human-readable representation of this value.- Specified by:
toString
in interfaceVariable
- Overrides:
toString
in classBinaryVariable
- 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 interfaceVariable
- Overrides:
randomize
in classBinaryVariable
-