Class RealVariable

java.lang.Object
org.moeaframework.core.variable.RealVariable
All Implemented Interfaces:
Serializable, Variable

public class RealVariable extends Object implements Variable
Decision variable for real values.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    RealVariable(double lowerBound, double upperBound)
    Constructs a real variable in the range lowerBound <= x <= upperBound with an uninitialized value.
    RealVariable(double value, double lowerBound, double upperBound)
    Constructs a real variable in the range lowerBound <= x <= upperBound with the specified initial value.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns an independent copy of this decision variable.
    void
    decode(String value)
    Parses and loads the value of this variable from a string.
    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
    Returns the current value of this decision variable.
    int
     
    void
    Randomly assign the value of this variable.
    void
    setValue(double value)
    Sets the value of this decision variable.
    Returns a human-readable representation of this value.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • RealVariable

      public RealVariable(double lowerBound, double upperBound)
      Constructs a real variable in the range lowerBound <= x <= upperBound with an uninitialized value.
      Parameters:
      lowerBound - the lower bound of this decision variable, inclusive
      upperBound - the upper bound of this decision variable, inclusive
    • RealVariable

      public RealVariable(double value, double lowerBound, double upperBound)
      Constructs a real variable in the range lowerBound <= x <= upperBound with the specified initial value.
      Parameters:
      value - the initial value of this decision variable
      lowerBound - the lower bound of this decision variable, inclusive
      upperBound - 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

      public RealVariable copy()
      Description copied from interface: Variable
      Returns an independent copy of this decision variable. It is required that x.copy() is completely independent from x. This means any method invoked on x.copy() in no way alters the state of x and vice versa. It is typically the case that x.copy().getClass() == x.getClass() and x.copy().equals(x).
      Specified by:
      copy in interface Variable
      Returns:
      an independent copy of this decision variable
    • toString

      public String toString()
      Description copied from interface: Variable
      Returns a human-readable representation of this value.
      Specified by:
      toString in interface Variable
      Overrides:
      toString in class Object
      Returns:
      the value of this variable formatted as a string
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • 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.
      Specified by:
      randomize in interface Variable
    • encode

      public String 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: 1. Only contain ASCII characters 2. Contain no whitespace (no spaces, tabs, newlines, etc.)
      Specified by:
      encode in interface Variable
      Returns:
      the encoded value as a string
    • decode

      public void decode(String value)
      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 by Variable.encode().
      Specified by:
      decode in interface Variable
      Parameters:
      value - the value as a string