java.lang.Object
org.cicirello.search.representations.RealVector
All Implemented Interfaces:
RealValued, Copyable<RealVector>
Direct Known Subclasses:
BoundedRealVector

public class RealVector extends Object implements RealValued, Copyable<RealVector>
A simple class for representing the parameters to a multivariate function.
  • Constructor Summary

    Constructors
    Constructor
    Description
    RealVector(double[] x)
    Initializes the vector to the specified values.
    RealVector(int n)
    Initializes this vector to all 0.0 values.
    Initializes the vector 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.
    static void
    exchange(RealVector v1, RealVector v2, int firstIndex, int lastIndex)
    Exchanges a sequence of doubles between two RealVector objects.
    final double
    get(int i)
    Accesses the current value of a specified parameter.
    int
    Returns a hash code value for the function input object.
    final int
    Gets the number of parameters.
    void
    set(double[] values)
    Sets all values from an array (copies values from the array).
    void
    set(int i, double value)
    Sets a function parameter 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

    • RealVector

      public RealVector(int n)
      Initializes this vector to all 0.0 values.
      Parameters:
      n - The length of the vector.
    • RealVector

      public RealVector(double[] x)
      Initializes the vector to the specified values.
      Parameters:
      x - The initial values for the vector.
    • RealVector

      public RealVector(RealVector other)
      Initializes the vector as a copy of another.
      Parameters:
      other - The other vector 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(int i)
      Description copied from interface: RealValued
      Accesses the current value of a specified parameter.
      Specified by:
      get in interface RealValued
      Parameters:
      i - The parameter to get.
      Returns:
      The current value of the i-th parameter.
    • 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(int i, double value)
      Description copied from interface: RealValued
      Sets a function parameter to a specified value.
      Specified by:
      set in interface RealValued
      Parameters:
      i - The parameter to set.
      value - The new value for the i-th parameter.
    • set

      public void set(double[] values)
      Description copied from interface: RealValued
      Sets all values from an array (copies values from the array).
      Specified by:
      set in interface RealValued
      Parameters:
      values - an array of new values
    • exchange

      public static void exchange(RealVector v1, RealVector v2, int firstIndex, int lastIndex)
      Exchanges a sequence of doubles between two RealVector objects.
      Parameters:
      v1 - The first RealVector.
      v2 - The second RealVector.
      firstIndex - The first index of the sequence to exchange, inclusive.
      lastIndex - The last index of the sequence to exchange, inclusive.
      Throws:
      IndexOutOfBoundsException - if either index is negative, or if either index ≥ v1.length(), or if either index ≥ v2.length()
    • copy

      public RealVector copy()
      Creates an identical copy of this object.
      Specified by:
      copy in interface Copyable<RealVector>
      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 values.
      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 values.
    • hashCode

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