java.lang.Object
org.cicirello.search.representations.SingleReal
All Implemented Interfaces:
RealValued, Copyable<SingleReal>

public class SingleReal extends Object implements RealValued, Copyable<SingleReal>
A simple class for representing the input to a univariate function.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Initializes to 0.0.
    SingleReal(double x)
    Initializes to a specified value.
    Initializes as a copy of another.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates an identical copy of this object.
    boolean
    equals(Object other)
    Indicates whether some other object is "equal to" this one.
    final double
    get()
    Accesses the current value.
    final double
    get(int i)
    Accesses the current value.
    int
    Returns a hash code value for the function input object.
    final int
    Gets the number of parameters.
    void
    set(double x)
    Sets to a specified value.
    final void
    set(double[] values)
    Sets this function input to a specified value.
    final void
    set(int i, double x)
    Sets this function input to a specified value.
    final double[]
    toArray(double[] values)
    Accesses the current values of all of the parameters.

    Methods inherited from class java.lang.Object

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

    • SingleReal

      public SingleReal()
      Initializes to 0.0.
    • SingleReal

      public SingleReal(double x)
      Initializes to a specified value.
      Parameters:
      x - The initial value.
    • SingleReal

      public SingleReal(SingleReal other)
      Initializes as a copy of another.
      Parameters:
      other - The other to copy.
  • Method Details

    • length

      public final int length()
      Description copied from interface: RealValued
      Gets the number of parameters.
      Specified by:
      length in interface RealValued
      Returns:
      The number of parameters for this function.
    • get

      public final double get()
      Accesses the current value.
      Returns:
      The current value.
    • get

      public final double get(int i)
      Accesses the current value. This method originates with the RealValued interface. Since this is a univariate function, there is only 1 input variable by definition. Rather than throw an exception for values of i other than 0, this method ignores the i parameter and is equivalent to the get() method regardless of value passed for i.
      Specified by:
      get in interface RealValued
      Parameters:
      i - The input to get (ignored by this implementation since this is an input for a univariate function).
      Returns:
      The current value of this function input.
    • toArray

      public final double[] toArray(double[] values)
      Description copied from interface: RealValued
      Accesses the current values of all of the parameters.
      Specified by:
      toArray in interface RealValued
      Parameters:
      values - An array to hold the result. If values is null or if values.length is not equal to this.length(), then a new array is constructed for the result.
      Returns:
      An array containing the current values of all of the parameters.
    • set

      public void set(double x)
      Sets to a specified value.
      Parameters:
      x - The new value.
    • set

      public final void set(int i, double x)
      Sets this function input to a specified value. This method originates with the RealValued interface. Since this is a univariate function, there is only 1 input variable by definition. Rather than throw an exception for values of i other than 0, this method ignores the i parameter and is equivalent to the set(double) method regardless of value passed for i.

      This method delegates work to the set(double) method, so the behavior of this method will be consistent with any subclasses that override set(double).

      Specified by:
      set in interface RealValued
      Parameters:
      i - The input variable to set (ignored by this implementation since this is an input for a univariate function).
      x - The new value for this function input.
    • set

      public final void set(double[] values)
      Sets this function input to a specified value. This method originates with the RealValued interface. Since this is a univariate function, there is only 1 input variable by definition. Rather than throw an exception for values.length greater than 1, this method simply uses values[0] and ignores any extra values.

      This method delegates work to the set(double) method, so the behavior of this method will be consistent with any subclasses that override set(double).

      Specified by:
      set in interface RealValued
      Parameters:
      values - The values to set.
    • copy

      public SingleReal copy()
      Creates an identical copy of this object.
      Specified by:
      copy in interface Copyable<SingleReal>
      Returns:
      an identical copy of this object
    • equals

      public boolean equals(Object other)
      Indicates whether some other object is "equal to" this one. To be equal, the other object must be of the same runtime type and contain the same value of the function input.
      Overrides:
      equals in class Object
      Parameters:
      other - The other object to compare.
      Returns:
      true if other is not null, is of the same runtime type as this, and contains the same function input value.
    • hashCode

      public int hashCode()
      Returns a hash code value for the function input object.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value