Package org.moeaframework.core.variable
Interface Variable
- All Superinterfaces:
Copyable<Variable>
,Defined
,Named
,Serializable
- All Known Implementing Classes:
AbstractVariable
,BinaryIntegerVariable
,BinaryVariable
,Grammar
,Permutation
,Program
,RealVariable
,Subset
Interface for decision variables.
Implementations are encouraged to also override Object.equals(Object)
and Object.hashCode()
. These
are used, for example, to exclude duplicate solutions from populations.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.moeaframework.core.Defined
Defined.ConstructorComparator
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Parses and loads the value of this variable from a string.encode()
Encodes the value of this variable as a string.static String
getNameOrDefault
(Variable variable, int index) Returns the name of the variable, using either the name assigned to the variable or deriving the name from its index.void
Randomly assign the value of this variable.toString()
Returns a human-readable representation of this value.Methods inherited from interface org.moeaframework.core.Defined
getDefinition
-
Method Details
-
randomize
void randomize()Randomly assign the value of this variable. -
toString
String toString()Returns a human-readable representation of this value. -
encode
String encode()Encodes the value of this variable as a string. This should reflect the internal representation of the value and not necessarily the actual value. For example, a binary-encoded integer should display the bits and not the integer value.Implementations should make an effort to display the value in a meaningful format, but that is not required. Instead, use
toString()
if a human-readable format is required.This method along with
decode(String)
are used primarily for storing values in text files. To make parsing easier, the resulting string must:- Only contain ASCII characters
- Contain no whitespace (no spaces, tabs, newlines, etc.)
- Returns:
- the encoded value as a string
- Throws:
VariableEncodingException
- if an error occurred while encoding this variable
-
decode
Parses and loads the value of this variable from a string. This must be able to process any string produced byencode()
.- Parameters:
value
- the value as a string- Throws:
VariableEncodingException
- if an error occurred while decoding this variable
-
getNameOrDefault
Returns the name of the variable, using either the name assigned to the variable or deriving the name from its index.- Parameters:
variable
- the variableindex
- the index of the variable- Returns:
- the name of the variable
-