Package org.moeaframework.core.variable
Class RealVariable
java.lang.Object
org.moeaframework.core.variable.RealVariable
- All Implemented Interfaces:
Serializable
,Variable
Decision variable for real values.
- See Also:
-
Constructor Summary
ConstructorDescriptionRealVariable
(double lowerBound, double upperBound) Constructs a real variable in the rangelowerBound <= x <= upperBound
with an uninitialized value.RealVariable
(double value, double lowerBound, double upperBound) Constructs a real variable in the rangelowerBound <= x <= upperBound
with the specified initial value. -
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.boolean
double
Returns the lower bound of this decision variable.double
Returns the upper bound of this decision variable.double
getValue()
Returns the current value of this decision variable.int
hashCode()
void
Randomly assign the value of this variable.void
setValue
(double value) Sets the value of this decision variable.toString()
Returns a human-readable representation of this value.
-
Constructor Details
-
RealVariable
public RealVariable(double lowerBound, double upperBound) Constructs a real 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, inclusive
-
RealVariable
public RealVariable(double value, double lowerBound, double upperBound) Constructs a real variable in the rangelowerBound <= x <= upperBound
with the specified initial value.- 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)
-
-
Method Details
-
getValue
public double getValue()Returns the current value of this decision variable.- Returns:
- the current value of this decision variable
-
setValue
public void setValue(double value) Sets the value of this decision variable. The value can be set to 0d/0d to indicate no value is assigned.- Parameters:
value
- the new value for this decision variable- Throws:
IllegalArgumentException
- if the value is out of bounds(value < getLowerBound()) || (value > getUpperBound())
-
getLowerBound
public double getLowerBound()Returns the lower bound of this decision variable.- Returns:
- the lower bound of this decision variable, inclusive
-
getUpperBound
public double 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)
. -
toString
Description copied from interface:Variable
Returns a human-readable representation of this value. -
hashCode
public int hashCode() -
equals
-
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. -
encode
Description copied from interface:Variable
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, useVariable.toString()
if a human-readable format is required. This method along withVariable.decode(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.) -
decode
Description copied from interface:Variable
Parses and loads the value of this variable from a string. This must be able to process any string produced byVariable.encode()
.
-