java.lang.Object
org.cicirello.search.representations.SingleReal
- All Implemented Interfaces:
RealValued,Copyable<SingleReal>
A simple class for representing the input to a univariate function.
-
Constructor Summary
ConstructorsConstructorDescriptionInitializes to 0.0.SingleReal(double x) Initializes to a specified value.SingleReal(SingleReal other) Initializes as a copy of another. -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates an identical copy of this object.booleanIndicates whether some other object is "equal to" this one.final doubleget()Accesses the current value.final doubleget(int i) Accesses the current value.inthashCode()Returns a hash code value for the function input object.final intlength()Gets the number of parameters.voidset(double x) Sets to a specified value.final voidset(double[] values) Sets this function input to a specified value.final voidset(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.
-
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
Initializes as a copy of another.- Parameters:
other- The other to copy.
-
-
Method Details
-
length
public final int length()Description copied from interface:RealValuedGets the number of parameters.- Specified by:
lengthin interfaceRealValued- 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 theRealValuedinterface. 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 theget()method regardless of value passed for i.- Specified by:
getin interfaceRealValued- 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:RealValuedAccesses the current values of all of the parameters.- Specified by:
toArrayin interfaceRealValued- 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 theRealValuedinterface. 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 theset(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 overrideset(double).- Specified by:
setin interfaceRealValued- 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 theRealValuedinterface. 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 overrideset(double).- Specified by:
setin interfaceRealValued- Parameters:
values- The values to set.
-
copy
Creates an identical copy of this object.- Specified by:
copyin interfaceCopyable<SingleReal>- Returns:
- an identical copy of this object
-
equals
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. -
hashCode
public int hashCode()Returns a hash code value for the function input object.
-