Package org.moeaframework.core
Interface Variable
- All Superinterfaces:
Serializable
- All Known Implementing Classes:
BinaryIntegerVariable
,BinaryVariable
,Grammar
,Permutation
,Program
,RealVariable
,Subset
Interface for decision variables. This interface ensures independent copies of decision variables can be
constructed. Implementations are strongly encouraged to also override
Object.equals(Object)
and
Object.hashCode()
.-
Method Summary
Modifier and TypeMethodDescriptioncopy()
Returns an independent copy of this decision variable.void
Parses and loads the value of this variable from a string.encode()
Encodes the value of this variable as a string.void
Randomly assign the value of this variable.toString()
Returns a human-readable representation of this value.
-
Method Details
-
copy
Variable copy()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)
.- Returns:
- an independent copy of this decision variable
-
randomize
void randomize()Randomly assign the value of this variable. In general, the randomization should follow a uniform distribution. -
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, usetoString()
if a human-readable format is required. This method along withdecode(String)
are used primarily for storing values in text files. To make parsing easier, the resulting string must: 1. Only contain ASCII characters 2. Contain no whitespace (no spaces, tabs, newlines, etc.)- Returns:
- the encoded value as a string
-
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
-