Package org.moeaframework.core.variable
Class BinaryIntegerVariable
java.lang.Object
org.moeaframework.core.variable.AbstractVariable
org.moeaframework.core.variable.BinaryVariable
org.moeaframework.core.variable.BinaryIntegerVariable
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.moeaframework.core.Defined
Defined.ConstructorComparator -
Field Summary
Fields inherited from class org.moeaframework.core.variable.AbstractVariable
name -
Constructor Summary
ConstructorsConstructorDescriptionBinaryIntegerVariable(int lowerBound, int upperBound) Constructs an integer-valued variable in the rangelowerBound <= x <= upperBound.BinaryIntegerVariable(int lowerBound, int upperBound, boolean gray) Constructs an integer-valued variable in the rangelowerBound <= x <= upperBound.BinaryIntegerVariable(String name, int lowerBound, int upperBound) Constructs an integer-valued variable in the rangelowerBound <= x <= upperBoundwith the given name.BinaryIntegerVariable(String name, int lowerBound, int upperBound, boolean gray) Constructs an integer-valued variable in the rangelowerBound <= x <= upperBoundwith the given name. -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates and returns a copy of this object.booleanReturns the string representation, or definition, of this object.static int[]Returns the array of integer-valued decision variables stored in a solution.static int[]Returns the array of integer-valued decision variables stored in a solution between the specified indices.static intReturns the value stored in an integer-valued decision variable.intReturns the lower bound of this decision variable.static final intgetNumberOfBits(int lowerBound, int upperBound) Returns the minimum number of bits required to represent an integer within the given bounds.intReturns the upper bound of this decision variable.intgetValue()Returns the current value of this decision variable.inthashCode()protected booleanisGray()Returnstrueif the binary representation using gray coding.voidRandomly assign the value of this variable.static voidSets the values of all integer-valued decision variables stored in the solution.static voidSets the values of the integer-valued decision variables stored in a solution between the specified indices.static voidSets the value of an integer-valued decision variable.voidsetValue(int value) Sets the value of this decision variable.toString()Returns a human-readable representation of this value.withValue(int value) CallssetValue(int)and returns this instance, mainly allowing one to create and set the value of a decision variable on one line.Methods inherited from class org.moeaframework.core.variable.BinaryVariable
cardinality, clear, decode, encode, get, getBinary, getBitSet, getBitSet, getNumberOfBits, hammingDistance, isEmpty, set, setBinary, setBitSetMethods inherited from class org.moeaframework.core.variable.AbstractVariable
getName
-
Constructor Details
-
BinaryIntegerVariable
public BinaryIntegerVariable(int lowerBound, int upperBound) Constructs an integer-valued variable in the rangelowerBound <= x <= upperBound. Uses gray coding by default.- Parameters:
lowerBound- the lower bound of this decision variable, inclusiveupperBound- the upper bound of this decision variable, inclusive
-
BinaryIntegerVariable
Constructs an integer-valued variable in the rangelowerBound <= x <= upperBoundwith the given name. Uses gray coding by default.- Parameters:
name- the name of this decision variablelowerBound- the lower bound of this decision variable, inclusiveupperBound- the upper bound of this decision variable, inclusive
-
BinaryIntegerVariable
public BinaryIntegerVariable(int lowerBound, int upperBound, boolean gray) Constructs an integer-valued variable in the rangelowerBound <= x <= upperBound.- 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
Constructs an integer-valued variable in the rangelowerBound <= x <= upperBoundwith the given name.- Parameters:
name- the name 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
-
-
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())
-
withValue
CallssetValue(int)and returns this instance, mainly allowing one to create and set the value of a decision variable on one line.- Parameters:
value- the new value for this decision variable- Returns:
- this decision variable
- Throws:
IllegalArgumentException- if the value is out of bounds(value < getLowerBound()) || (value > getUpperBound())
-
isGray
protected boolean isGray()Returnstrueif the binary representation using gray coding. Gray coding ensures that two successive values differ by only one bit.- Returns:
trueif the binary representation using gray coding;falseotherwise
-
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:CopyableCreates and returns a copy of this object. It is required thatx.copy()is completely independent fromx. This means any method invoked onx.copy()in no way alters the state ofxand vice versa. It is typically the case thatx.copy().getClass() == x.getClass()andx.copy().equals(x).- Specified by:
copyin interfaceCopyable<Variable>- Overrides:
copyin classBinaryVariable- Returns:
- the copy
-
getDefinition
Description copied from interface:DefinedReturns the string representation, or definition, of this object.- Specified by:
getDefinitionin interfaceDefined- Overrides:
getDefinitionin classBinaryVariable- Returns:
- the definition
-
hashCode
public int hashCode()- Overrides:
hashCodein classBinaryVariable
-
equals
- Overrides:
equalsin classBinaryVariable
-
toString
Description copied from interface:VariableReturns a human-readable representation of this value.- Specified by:
toStringin interfaceVariable- Overrides:
toStringin classBinaryVariable- Returns:
- the value of this variable formatted as a string
-
randomize
public void randomize()Description copied from interface:VariableRandomly assign the value of this variable.- Specified by:
randomizein interfaceVariable- Overrides:
randomizein classBinaryVariable
-
getInt
Returns the value stored in an integer-valued decision variable.- Parameters:
variable- the decision variable- Returns:
- the value stored in an integer-valued decision variable
- Throws:
IllegalArgumentException- if the decision variable is not convertible to an integer
-
getInt
Returns the array of integer-valued decision variables stored in a solution. The solution must contain only integer-valued decision variables.- Parameters:
solution- the solution- Returns:
- the array of integer-valued decision variables stored in a solution
- Throws:
IllegalArgumentException- if any decision variable contained in the solution is not of typeRealVariable
-
getInt
Returns the array of integer-valued decision variables stored in a solution between the specified indices. The decision variables located between the start and end index must all be integer-valued decision variables.- Parameters:
solution- the solutionstartIndex- the start index (inclusive)endIndex- the end index (exclusive)- Returns:
- the array of integer-valued decision variables stored in a solution between the specified indices
- Throws:
IllegalArgumentException- if any decision variable contained in the solution between the start and end index is not of typeRealVariable
-
setInt
Sets the value of an integer-valued decision variable.- Parameters:
variable- the decision variablevalue- the value to assign the integer-valued decision variable- Throws:
IllegalArgumentException- if the decision variable is not convertible to an integerIllegalArgumentException- if the value is out of bounds (value < getLowerBound()) || (value > getUpperBound())
-
setInt
Sets the values of all integer-valued decision variables stored in the solution. The solution must contain only integer-valued decision variables.- Parameters:
solution- the solutionvalues- the array of integer values to assign the solution- Throws:
IllegalArgumentException- if the decision variable is not convertible to an integerIllegalArgumentException- if any of the values are out of bounds (value < getLowerBound()) || (value > getUpperBound())
-
setInt
Sets the values of the integer-valued decision variables stored in a solution between the specified indices. The decision variables located between the start and end index must all be integer-valued decision variables.- Parameters:
solution- the solutionstartIndex- the start index (inclusive)endIndex- the end index (exclusive)values- the array of floating-point values to assign the decision variables- Throws:
IllegalArgumentException- if the decision variables are not convertible to an integerIllegalArgumentException- if an invalid number of values are providedIllegalArgumentException- if any of the values are out of bounds (value < getLowerBound()) || (value > getUpperBound())
-