|
MOEA Framework 2.5 API Specification |
|||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||
java.lang.Objectorg.moeaframework.core.variable.EncodingUtils
public class EncodingUtils
Helper methods for working with various decision variable types and encodings. First, these methods perform any necessary type checking and type conversion. Instead of writing:
double value = ((RealVariable)solution.getVariable(i)).getValue()the following simplified version is allowed:
double value = getReal(solution.getVariable(i));
Support for integer encodings is now supported using the
newInt(int, int), getInt(Variable),
setInt(Variable, int) methods. Internally, integers are
represented by floating-point values. In order to remain consistent,
only use these methods to create, set, and get the value of
integer decision variables.
This class also provides methods for converting between RealVariable
and BinaryVariable in both binary and gray code formats.
| Method Summary | |
|---|---|
static void |
binaryToGray(BinaryVariable variable)
Converts a binary variable from a binary encoding to gray encoding. |
static long |
decode(BinaryVariable binary)
Decodes the specified binary variable into its integer value. |
static void |
decode(BinaryVariable binary,
RealVariable real)
Decodes the specified binary variable into its real value. |
static void |
encode(long value,
BinaryVariable binary)
Encodes the integer into the specified binary variable. |
static void |
encode(RealVariable real,
BinaryVariable binary)
Encodes the specified real variable into a binary variable. |
static boolean[] |
getBinary(Variable variable)
Returns the value stored in a binary decision variable as a boolean array. |
static BitSet |
getBitSet(Variable variable)
Returns the value stored in a binary decision variable as a BitSet. |
static boolean |
getBoolean(Variable variable)
Returns the value stored in a boolean decision variable. |
static int[] |
getInt(Solution solution)
Returns the array of integer-valued decision variables stored in a solution. |
static int[] |
getInt(Solution solution,
int startIndex,
int endIndex)
Returns the array of integer-valued decision variables stored in a solution between the specified indices. |
static int |
getInt(Variable variable)
Returns the value stored in an integer-valued decision variable. |
static int[] |
getPermutation(Variable variable)
Returns the value stored in a permutation decision variable. |
static double[] |
getReal(Solution solution)
Returns the array of floating-point decision variables stored in a solution. |
static double[] |
getReal(Solution solution,
int startIndex,
int endIndex)
Returns the array of floating-point decision variables stored in a solution between the specified indices. |
static double |
getReal(Variable variable)
Returns the value stored in a floating-point decision variable. |
static void |
grayToBinary(BinaryVariable variable)
Converts a binary variable from a gray encoding to binary encoding. |
static BinaryVariable |
newBinary(int length)
Returns a new binary decision variable with the specified number of bits. |
static BinaryVariable |
newBoolean()
Returns a new boolean decision variable. |
static RealVariable |
newInt(int lowerBound,
int upperBound)
Returns a new integer-valued decision variable bounded within the specified range. |
static Permutation |
newPermutation(int length)
Returns a new permutation with the specified number of items. |
static RealVariable |
newReal(double lowerBound,
double upperBound)
Returns a new floating-point decision variable bounded within the specified range. |
static void |
setBinary(Variable variable,
boolean[] values)
Sets the bits in a binary decision variable using the given boolean array. |
static void |
setBitSet(Variable variable,
BitSet bitSet)
Sets the bits in a binary decision variable using the given BitSet. |
static void |
setBoolean(Variable variable,
boolean value)
Sets the value of a boolean decision variable. |
static void |
setInt(Solution solution,
int[] values)
Sets the values of all integer-valued decision variables stored in the solution. |
static void |
setInt(Solution solution,
int startIndex,
int endIndex,
int[] values)
Sets the values of the integer-valued decision variables stored in a solution between the specified indices. |
static void |
setInt(Variable variable,
int value)
Sets the value of an integer-valued decision variable. |
static void |
setPermutation(Variable variable,
int[] values)
Sets the value of a permutation decision variable. |
static void |
setReal(Solution solution,
double[] values)
Sets the values of all floating-point decision variables stored in the solution. |
static void |
setReal(Solution solution,
int startIndex,
int endIndex,
double[] values)
Sets the values of the floating-point decision variables stored in a solution between the specified indices. |
static void |
setReal(Variable variable,
double value)
Sets the value of a floating-point decision variable. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void encode(RealVariable real,
BinaryVariable binary)
binary.getNumberOfBits().
real - the real variablebinary - the binary variable to which the real value is encoded
public static void decode(BinaryVariable binary,
RealVariable real)
binary - the binary variablereal - the real variable to which the value is decoded
public static void encode(long value,
BinaryVariable binary)
binary.getNumberOfBits().
value - an integerbinary - the binary variable to which the value is encodedpublic static long decode(BinaryVariable binary)
binary - the binary variable
public static void binaryToGray(BinaryVariable variable)
1 bit (a Hamming distance of 1).
variable - the variable to be convertedpublic static void grayToBinary(BinaryVariable variable)
variable - the variable to be converted
public static RealVariable newReal(double lowerBound,
double upperBound)
lowerBound - the lower bound of the floating-point valueupperBound - the upper bound of the floating-point value
public static RealVariable newInt(int lowerBound,
int upperBound)
lowerBound - the lower bound of the integer valueupperBound - the upper bound of the integer value
public static BinaryVariable newBoolean()
public static BinaryVariable newBinary(int length)
length - the number of bits in the binary decision variable
public static Permutation newPermutation(int length)
length - the number of items in the permutation
public static double getReal(Variable variable)
variable - the decision variable
IllegalArgumentException - if the decision variable is not of type
RealVariablepublic static int getInt(Variable variable)
variable - the decision variable
IllegalArgumentException - if the decision variable is not of type
RealVariablepublic static BitSet getBitSet(Variable variable)
BitSet.
variable - the decision variable
BitSet
IllegalArgumentException - if the decision variable is not of type
BinaryVariablepublic static boolean[] getBinary(Variable variable)
variable - the decision variable
IllegalArgumentException - if the decision variable is not of type
BinaryVariablepublic static boolean getBoolean(Variable variable)
variable - the decision variable
IllegalArgumentException - if the decision variable is not of type
BinaryVariablepublic static int[] getPermutation(Variable variable)
variable - the decision variable
IllegalArgumentException - if the decision variable is not of type
Permutationpublic static double[] getReal(Solution solution)
solution - the solution
IllegalArgumentException - if any decision variable contained in
the solution is not of type RealVariable
public static double[] getReal(Solution solution,
int startIndex,
int endIndex)
solution - the solutionstartIndex - the start index (inclusive)endIndex - the end index (exclusive)
IllegalArgumentException - if any decision variable contained in
the solution between the start and end index is not of type
RealVariablepublic static int[] getInt(Solution solution)
solution - the solution
IllegalArgumentException - if any decision variable contained in
the solution is not of type RealVariable
public static int[] getInt(Solution solution,
int startIndex,
int endIndex)
solution - the solutionstartIndex - the start index (inclusive)endIndex - the end index (exclusive)
IllegalArgumentException - if any decision variable contained in
the solution between the start and end index is not of type
RealVariable
public static void setReal(Variable variable,
double value)
variable - the decision variablevalue - the value to assign the floating-point decision variable
IllegalArgumentException - if the decision variable is not of type
RealVariable
IllegalArgumentException - if the value is out of bounds
(value < getLowerBound()) || (value > getUpperBound())
public static void setReal(Solution solution,
double[] values)
solution - the solutionvalues - the array of floating-point values to assign the solution
IllegalArgumentException - if any decision variable contained in
the solution is not of type RealVariable
IllegalArgumentException - if any of the values are out of bounds
(value < getLowerBound()) || (value > getUpperBound())
public static void setReal(Solution solution,
int startIndex,
int endIndex,
double[] values)
solution - the solutionstartIndex - the start index (inclusive)endIndex - the end index (exclusive)values - the array of floating-point values to assign the
decision variables
IllegalArgumentException - if any decision variable contained in
the solution between the start and end index is not of type
RealVariable
IllegalArgumentException - if an invalid number of values are
provided
IllegalArgumentException - if any of the values are out of bounds
(value < getLowerBound()) || (value > getUpperBound())
public static void setInt(Variable variable,
int value)
variable - the decision variablevalue - the value to assign the integer-valued decision variable
IllegalArgumentException - if the decision variable is not of type
RealVariable
IllegalArgumentException - if the value is out of bounds
(value < getLowerBound()) || (value > getUpperBound())
public static void setInt(Solution solution,
int[] values)
solution - the solutionvalues - the array of integer values to assign the solution
IllegalArgumentException - if any decision variable contained in
the solution is not of type RealVariable
IllegalArgumentException - if any of the values are out of bounds
(value < getLowerBound()) || (value > getUpperBound())
public static void setInt(Solution solution,
int startIndex,
int endIndex,
int[] values)
solution - the solutionstartIndex - the start index (inclusive)endIndex - the end index (exclusive)values - the array of floating-point values to assign the
decision variables
IllegalArgumentException - if any decision variable contained in
the solution between the start and end index is not of type
RealVariable
IllegalArgumentException - if an invalid number of values are
provided
IllegalArgumentException - if any of the values are out of bounds
(value < getLowerBound()) || (value > getUpperBound())
public static void setBitSet(Variable variable,
BitSet bitSet)
BitSet.
variable - the decision variablebitSet - the bits to set in the binary decision variable
IllegalArgumentException - if the decision variable is not of type
BinaryVariable
public static void setBinary(Variable variable,
boolean[] values)
variable - the decision variablevalues - the bits to set in the binary decision variable
IllegalArgumentException - if the decision variable is not of type
BinaryVariable
IllegalArgumentException - if an invalid number of values are
provided
public static void setBoolean(Variable variable,
boolean value)
variable - the decision variablevalue - the value to assign the boolean decision variable
IllegalArgumentException - if the decision variable is not of type
BinaryVariable
IllegalArgumentException - if the number of bits in the binary
variable is not 1
public static void setPermutation(Variable variable,
int[] values)
variable - the decision variablevalues - the permutation to assign the permutation decision variable
IllegalArgumentException - if the decision variable is not of type
Permutation
IllegalArgumentException - if values is not a valid
permutation
|
MOEA Framework 2.5 API Specification |
|||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||