Package org.moeaframework.core.variable
Class RealVariable
java.lang.Object
org.moeaframework.core.variable.AbstractVariable
org.moeaframework.core.variable.RealVariable
Decision variable for real values.
- 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
ConstructorDescriptionRealVariable
(double lowerBound, double upperBound) Constructs a real variable in the rangelowerBound <= x <= upperBound
.RealVariable
(String name, double lowerBound, double upperBound) Constructs a real variable in the rangelowerBound <= x <= upperBound
with the given name. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Creates and returns a copy of this object.void
Parses and loads the value of this variable from a string.encode()
Encodes the value of this variable as a string.boolean
Returns the string representation, or definition, of this object.double
Returns the lower bound of this decision variable.static double[]
Returns the array of floating-point decision variables stored in a solution.static double[]
Returns the array of floating-point decision variables stored in a solution between the specified indices.static double
Returns the value stored in a floating-point 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.static void
Sets the values of all floating-point decision variables stored in the solution.static void
Sets the values of the floating-point decision variables stored in a solution between the specified indices.static void
Sets the value of a floating-point decision variable.void
setValue
(double value) Sets the value of this decision variable.toString()
Returns a human-readable representation of this value.withValue
(double value) CallssetValue(double)
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.AbstractVariable
getName
-
Constructor Details
-
RealVariable
public RealVariable(double lowerBound, double upperBound) Constructs a real variable in the rangelowerBound <= x <= upperBound
.- Parameters:
lowerBound
- the lower bound of this decision variable, inclusiveupperBound
- the upper bound of this decision variable, inclusive
-
RealVariable
Constructs a real variable in the rangelowerBound <= x <= upperBound
with 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, inclusive
-
-
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())
-
withValue
CallssetValue(double)
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())
-
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:Copyable
Creates 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 ofx
and vice versa. It is typically the case thatx.copy().getClass() == x.getClass()
andx.copy().equals(x)
.- Returns:
- the copy
-
getDefinition
Description copied from interface:Defined
Returns the string representation, or definition, of this object.- Returns:
- the definition
-
toString
Description copied from interface:Variable
Returns a human-readable representation of this value. -
hashCode
public int hashCode()- Overrides:
hashCode
in classAbstractVariable
-
equals
- Overrides:
equals
in classAbstractVariable
-
randomize
public void randomize()Description copied from interface:Variable
Randomly assign the value of this variable. -
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, use
Variable.toString()
if a human-readable format is required.This method along with
Variable.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
-
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()
.- Parameters:
value
- the value as a string
-
getReal
Returns the value stored in a floating-point decision variable.- Parameters:
variable
- the decision variable- Returns:
- the value stored in a floating-point decision variable
- Throws:
IllegalArgumentException
- if the decision variable is not of typeRealVariable
-
getReal
Returns the array of floating-point decision variables stored in a solution. The solution must contain only floating-point decision variables.- Parameters:
solution
- the solution- Returns:
- the array of floating-point decision variables stored in a solution
- Throws:
IllegalArgumentException
- if any decision variable contained in the solution is not of typeRealVariable
-
getReal
Returns the array of floating-point decision variables stored in a solution between the specified indices. The decision variables located between the start and end index must all be floating-point decision variables.- Parameters:
solution
- the solutionstartIndex
- the start index (inclusive)endIndex
- the end index (exclusive)- Returns:
- the array of floating-point 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
-
setReal
Sets the value of a floating-point decision variable.- Parameters:
variable
- the decision variablevalue
- the value to assign the floating-point decision variable- Throws:
IllegalArgumentException
- if the decision variable is not of typeRealVariable
IllegalArgumentException
- if the value is out of bounds (value < getLowerBound()) || (value > getUpperBound()
)
-
setReal
Sets the values of all floating-point decision variables stored in the solution. The solution must contain only floating-point decision variables.- Parameters:
solution
- the solutionvalues
- the array of floating-point values to assign the solution- Throws:
IllegalArgumentException
- if any decision variable contained in the solution is not of typeRealVariable
IllegalArgumentException
- if any of the values are out of bounds (value < getLowerBound()) || (value > getUpperBound()
)
-
setReal
Sets the values of the floating-point decision variables stored in a solution between the specified indices. The decision variables located between the start and end index must all be floating-point 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 any decision variable contained in the solution between the start and end index is not of typeRealVariable
IllegalArgumentException
- if an invalid number of values are providedIllegalArgumentException
- if any of the values are out of bounds (value < getLowerBound()) || (value > getUpperBound()
)
-