genopt.algorithm.util.math
Class Point

java.lang.Object
  extended by genopt.algorithm.util.math.Point
All Implemented Interfaces:
java.lang.Comparable<Point>
Direct Known Subclasses:
ResultManager.ResultPoint

public class Point
extends java.lang.Object
implements java.lang.Comparable<Point>

Abstract class for a point with continuous and discrete coordinates.

The discrete parameters are stored as zero-based indices. This class has methods to get for each discrete parameter its value as a Gray coded binary int[] arrays.

This project was carried out at:

and supported by

GenOpt Copyright (c) 1998-2011, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.

Version:
GenOpt(R) 3.1.0 (December 8, 2011)

Author:
Michael Wetter

Field Summary
protected  java.lang.String com
          the point's comment
protected  double[] cooCon
          the point's continuous coordinates
protected  int[] cooDis
          the point's discrete coordinates
protected  int[] cooDisBitLength
          the length of the binary string representation
protected  int[] cooDisMax
          the maximum allowed value for the point's discrete coordinates.
protected  int dimCon
          the number of continuous independent variables
protected  int dimDis
          the number of discrete independent variables
protected  int dimF
          the dimension of the function value vector
static double EPSILON
          Accuracy for testing of rounding errors
protected  double[] fun
          the point's function values
static double ONEMINUSEPSILON
           
static double ONEPLUSEPSILON
           
protected  int simNum
          the number of the simulation corresponding to this point
protected  int steNum
          the point's step number
 
Constructor Summary
Point(double[] xCon, double[] f, int stepNumber, java.lang.String comment)
          Constructor for a point with only continuous independent variables
Point(double[] xCon, int[] xDis, double[] f, int stepNumber, java.lang.String comment)
          Constructor for a point with continuous and discrete independent variables
Point(double[] xCon, int[] xDis, int[] xDisMax, double[] f, int stepNumber, java.lang.String comment, int simulationNumber)
          Constructor for a point with continuous and discrete independent variables
Point(int[] xDis, double[] f, int stepNumber, java.lang.String comment)
          Constructor for a point with only discrete independent variables
Point(int nCon, int nDis, int nF)
          Constructor
 
Method Summary
private  void _initialize(int nCon, int nDis, int nF)
          Allocates all arrays.
protected static boolean areEqual(double x1, double x2)
          Compares two numbers for equality.
 java.lang.Object clone()
          Clones the object.
 int compare(Point o1, Point o2)
          Compares two objects for equality, whereas only the x-coordinates in (float precision), the index of the discrete variables, and the step number are compared.
 int compareTo(Point pt)
          Compares this object with the specified object for equality, whereas only the x-coordinates in (float precision), the index of the discrete variables, and the step number are compared.
 boolean equals(Point o)
          Compares this object with the specified object for equality, whereas only the x-coordinates in (float precision), the index of the discrete variables, and the step number are compared.
 java.lang.String getComment()
          Gets the point's comment
 int getDimensionContinuous()
          Gets the number of continuous coordinates
 int getDimensionDiscrete()
          Gets the number of discrete coordinates
 int getDimensionF()
          Gets the dimension of the points function value vector
 double[] getF()
          Gets the point's function values
 double getF(int i)
          Gets the point's function values
 int[] getGrayBinaryString(int index)
          Gets the value of a discrete variable encoded as a binary string using Gray encoding.
 int getGrayBinaryStringLength(int index)
          Gets the string length used to represent the maximum value of the parameter as a Gray coded binary string.
 int[] getIndex()
          Gets the indices of the discrete point's
 int getIndex(int i)
          Gets the i-th point's index
 int[] getMaximumIndex()
          Gets the maximum allowed value of the indices of the discrete point's
 int getSimulationNumber()
          Gets the simulation number
 int getStepNumber()
          Gets the point's step number
 double[] getX()
          Gets the point's continuous independent variables
 double getX(int i)
          Gets the point's i-th continuous coordinate
static void main(java.lang.String[] args)
           
 void set(double[] x, double[] f, int stepNumber, java.lang.String comment)
          Sets a point with only continuous independent variables
 void set(double[] xCon, int[] xDis, double[] f, int stepNumber, java.lang.String comment)
          Sets a point with continuous and discrete independent variables
 void set(double[] xCon, int[] xDis, int[] xDisMax, double[] f, int stepNumber, java.lang.String comment)
          Sets a point with continuous and discrete independent variables
 void set(double[] x, int stepNumber, java.lang.String comment)
          Sets a point with only continuous independent variables
 void set(int[] x, double[] f, int stepNumber, java.lang.String comment)
          Sets a point with only discrete independent variables
 void set(int[] x, int stepNumber, java.lang.String comment)
          Sets a point with only discrete independent variables
 void setComment(java.lang.String comment)
          Sets a comment
 void setF(double[] f)
          Sets a point's function value
 void setF(int i, double f)
          Sets a point's function value
 void setGrayBinaryString(int index, int[] graBinStr)
          Sets the value of a discrete variable as a Gray encoded binary string.
 void setIndex(int[] x)
          Sets the indices of the point's discrete variables
 void setIndex(int[] xDis, int[] xDisMax)
          Sets the indices of the point's discrete variables and its maximum allowed values
 void setIndex(int i, int ind)
          Sets the index of the point's i-th discrete variables
 void setMaximumIndex(int i, int max)
          Sets the maximum value for the index of the point's i-th discrete variables.
 void setSimulationNumber(int simulationNumber)
          Sets a the simulation number
 void setStepNumber(int stepNumber)
          Sets a the step number
 void setX(double[] x)
          Sets the point's continuous coordinates
 void setX(int i, double x)
          Sets the i-th continuous independent variable
 void setX(int variableNumber, int index)
          Deprecated. replaced by setIndex(int, int)
 void setXIndex(double[] xCon, int[] xDis)
          Sets the point's discrete and continuous coordinates
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EPSILON

public static double EPSILON
Accuracy for testing of rounding errors


ONEMINUSEPSILON

public static double ONEMINUSEPSILON

ONEPLUSEPSILON

public static double ONEPLUSEPSILON

cooCon

protected double[] cooCon
the point's continuous coordinates


cooDis

protected int[] cooDis
the point's discrete coordinates


cooDisMax

protected int[] cooDisMax
the maximum allowed value for the point's discrete coordinates. This field is used to compute the length of the binary string representation.


cooDisBitLength

protected int[] cooDisBitLength
the length of the binary string representation


fun

protected double[] fun
the point's function values


com

protected java.lang.String com
the point's comment


steNum

protected int steNum
the point's step number


dimCon

protected int dimCon
the number of continuous independent variables


dimDis

protected int dimDis
the number of discrete independent variables


dimF

protected int dimF
the dimension of the function value vector


simNum

protected int simNum
the number of the simulation corresponding to this point

Constructor Detail

Point

public Point(int nCon,
             int nDis,
             int nF)
Constructor

Parameters:
nCon - number of continuous variables
nDis - number of discrete variables
nF - number of function values

Point

public Point(int[] xDis,
             double[] f,
             int stepNumber,
             java.lang.String comment)
Constructor for a point with only discrete independent variables

Parameters:
xDis - the point's discrete coordinates
f - its function values
stepNumber - the step number
comment - a comment

Point

public Point(double[] xCon,
             double[] f,
             int stepNumber,
             java.lang.String comment)
Constructor for a point with only continuous independent variables

Parameters:
xCon - the point's continuous coordinates
f - its function values
stepNumber - the step number
comment - a comment

Point

public Point(double[] xCon,
             int[] xDis,
             double[] f,
             int stepNumber,
             java.lang.String comment)
Constructor for a point with continuous and discrete independent variables

Parameters:
xCon - the point's continuous coordinates
xDis - the point's discrete coordinates
f - its function values
stepNumber - the step number
comment - a comment

Point

public Point(double[] xCon,
             int[] xDis,
             int[] xDisMax,
             double[] f,
             int stepNumber,
             java.lang.String comment,
             int simulationNumber)
Constructor for a point with continuous and discrete independent variables

Parameters:
xCon - the point's continuous coordinates
xDis - the point's discrete coordinates
xDisMax - the point's maximum value of the discrete coordinates
f - its function values
stepNumber - the step number
comment - a comment
simulationNumber - the number of the simulation
Throws:
java.lang.IllegalArgumentException - if xDis and xDisMax are not null but of different length
Method Detail

_initialize

private void _initialize(int nCon,
                         int nDis,
                         int nF)
Allocates all arrays.

Parameters:
nCon - number of continuous variables
nDis - number of discrete variables
nF - number of function values

clone

public java.lang.Object clone()
Clones the object.

Overrides:
clone in class java.lang.Object
Returns:
a copy of the object

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object

getF

public double[] getF()
Gets the point's function values

Returns:
the point's function values

getF

public double getF(int i)
Gets the point's function values

Parameters:
i - the index of the function value
Returns:
the point's function values

getX

public double[] getX()
Gets the point's continuous independent variables

Returns:
the point's continuous independent variables

getIndex

public int[] getIndex()
Gets the indices of the discrete point's

Returns:
the indices of the discrete point's

getMaximumIndex

public int[] getMaximumIndex()
Gets the maximum allowed value of the indices of the discrete point's

Returns:
the maximum allowed value of the indices of the discrete point's

getX

public double getX(int i)
Gets the point's i-th continuous coordinate

Parameters:
i - the index of the continuous coordinate
Returns:
the point's i-th continuous coordinate

getIndex

public int getIndex(int i)
Gets the i-th point's index

Parameters:
i - the number of the discrete variable
Returns:
the i-th point's index

getDimensionContinuous

public int getDimensionContinuous()
Gets the number of continuous coordinates

Returns:
the number of continuous coordinates

getDimensionDiscrete

public int getDimensionDiscrete()
Gets the number of discrete coordinates

Returns:
the number of discrete coordinates

getDimensionF

public int getDimensionF()
Gets the dimension of the points function value vector

Returns:
the dimension of the points function value vector

getStepNumber

public int getStepNumber()
Gets the point's step number

Returns:
the point's step number

getComment

public java.lang.String getComment()
Gets the point's comment

Returns:
the point's comment

setX

public void setX(double[] x)
Sets the point's continuous coordinates

Parameters:
x - the point's continuous coordinates

setIndex

public void setIndex(int[] x)
              throws java.lang.IllegalArgumentException
Sets the indices of the point's discrete variables

Parameters:
x - the indices of the point's discrete variables
Throws:
java.lang.IllegalArgumentException - if an element is negative, or an element is larger than the maximum allowed value, or the length of the argument is different from the one allocated by this object

setIndex

public void setIndex(int[] xDis,
                     int[] xDisMax)
Sets the indices of the point's discrete variables and its maximum allowed values

Parameters:
xDis - the indices of the point's discrete variables
xDisMax - the maximum allowed value for the indices of the point's discrete variables
Throws:
java.lang.IllegalArgumentException - if an element is negative, or an element is larger than the maximum allowed value, or the array lengths are different

setIndex

public void setIndex(int i,
                     int ind)
              throws java.lang.IllegalArgumentException
Sets the index of the point's i-th discrete variables

Parameters:
i - number of discrete variable
ind - index of the point's i-th discrete variables
Throws:
java.lang.IllegalArgumentException - if the argument is negative or larger than the maximum allowed value

setXIndex

public void setXIndex(double[] xCon,
                      int[] xDis)
               throws java.lang.IllegalArgumentException
Sets the point's discrete and continuous coordinates

Parameters:
xCon - the point's continuous coordinates
xDis - the point's discrete coordinates
Throws:
java.lang.IllegalArgumentException - if an element is negative, or an element is larger than the maximum allowed value, or the length of the argument is different from the one allocated by this object

setX

public void setX(int i,
                 double x)
Sets the i-th continuous independent variable

Parameters:
i - the zero-based index of the continuous independent variable
x - value to be set

setX

public void setX(int variableNumber,
                 int index)
Deprecated. replaced by setIndex(int, int)

Sets the index of the point's i-th discrete independent variable

Parameters:
variableNumber - the zero-based index of the discrete independent variable
index - the index of the variable
Throws:
java.lang.IllegalArgumentException - if the argument is negative or larger than the maximum allowed value

setF

public void setF(int i,
                 double f)
Sets a point's function value

Parameters:
i - the index of the function value
f - points function value

setF

public void setF(double[] f)
Sets a point's function value

Parameters:
f - a points function value

setStepNumber

public void setStepNumber(int stepNumber)
Sets a the step number

Parameters:
stepNumber - the step number

setSimulationNumber

public void setSimulationNumber(int simulationNumber)
Sets a the simulation number

Parameters:
simulationNumber - the number of the simulation

getSimulationNumber

public int getSimulationNumber()
Gets the simulation number

Returns:
simulationNumber the number of the simulation

setComment

public void setComment(java.lang.String comment)
Sets a comment

Parameters:
comment - the comment

set

public void set(double[] x,
                double[] f,
                int stepNumber,
                java.lang.String comment)
         throws java.lang.IllegalArgumentException
Sets a point with only continuous independent variables

Parameters:
x - the point's continuous coordinates
f - its function values
stepNumber - its step number
comment - its comment
Throws:
java.lang.IllegalArgumentException - if an element of x is negative, or is larger than the maximum allowed value, or the length of the argument is different from the one allocated by this object

set

public void set(int[] x,
                double[] f,
                int stepNumber,
                java.lang.String comment)
         throws java.lang.IllegalArgumentException
Sets a point with only discrete independent variables

Parameters:
x - the point's discrete coordinates
f - its function values
stepNumber - its step number
comment - its comment
Throws:
java.lang.IllegalArgumentException - if an element of x is negative, or is larger than the maximum allowed value, or the length of the argument is different from the one allocated by this object

set

public void set(double[] xCon,
                int[] xDis,
                double[] f,
                int stepNumber,
                java.lang.String comment)
         throws java.lang.IllegalArgumentException
Sets a point with continuous and discrete independent variables

Parameters:
xCon - the point's continuous coordinates
xDis - the point's discrete coordinates
f - its function values
stepNumber - its step number
comment - its comment
Throws:
java.lang.IllegalArgumentException - if an element of xDis is negative, or is larger than the maximum allowed value, or the length of the argument is different from the one allocated by this object

set

public void set(double[] xCon,
                int[] xDis,
                int[] xDisMax,
                double[] f,
                int stepNumber,
                java.lang.String comment)
         throws java.lang.IllegalArgumentException
Sets a point with continuous and discrete independent variables

Parameters:
xCon - the point's continuous coordinates
xDis - the point's discrete coordinates
xDisMax - the point's maximum value for the discrete coordinates
f - its function values
stepNumber - its step number
comment - its comment
Throws:
java.lang.IllegalArgumentException - if an element of xDis is negative, or is larger than the maximum allowed value, or the length of the argument is different from the one allocated by this object

set

public void set(double[] x,
                int stepNumber,
                java.lang.String comment)
Sets a point with only continuous independent variables

Parameters:
x - the point's continuous coordinates
stepNumber - its step number
comment - its comment

set

public void set(int[] x,
                int stepNumber,
                java.lang.String comment)
         throws java.lang.IllegalArgumentException
Sets a point with only discrete independent variables

Parameters:
x - the point's discrete coordinates
stepNumber - its step number
comment - its comment
Throws:
java.lang.IllegalArgumentException - if an element of x is negative, or is larger than the maximum allowed value, or the length of the argument is different from the one allocated by this object

compareTo

public int compareTo(Point pt)
Compares this object with the specified object for equality, whereas only the x-coordinates in (float precision), the index of the discrete variables, and the step number are compared.

Specified by:
compareTo in interface java.lang.Comparable<Point>
Returns:
0 if the objects are equal, -1 if the received object is the smaller one +1 if the received object is the larger one

areEqual

protected static boolean areEqual(double x1,
                                  double x2)
Compares two numbers for equality. Rounding errors are neglected.

Parameters:
x1 - first number
x2 - second number
Returns:
true if the numbers are equal except for rounding errors

equals

public boolean equals(Point o)
Compares this object with the specified object for equality, whereas only the x-coordinates in (float precision), the index of the discrete variables, and the step number are compared.

Parameters:
o - Object to be compared
Returns:
true if the objects are equal in the sense of the compareTo(Object) method, false otherwise

compare

public int compare(Point o1,
                   Point o2)
Compares two objects for equality, whereas only the x-coordinates in (float precision), the index of the discrete variables, and the step number are compared.

Parameters:
o1 - Object to be compared
o2 - Object to be compared
Returns:
0 if the objects are equal, -1 if o1 > o2, +1 if o1 < o2, in the sense of the compareTo(Object) method

setMaximumIndex

public void setMaximumIndex(int i,
                            int max)
                     throws java.lang.IllegalArgumentException
Sets the maximum value for the index of the point's i-th discrete variables. This function must be called before the value of the i-th discrete variable is requested as a binary string.

Parameters:
i - index of discrete variable
max - maximum value of the point's i-th discrete variables
Throws:
java.lang.IllegalArgumentException - if max < 0

getGrayBinaryStringLength

public int getGrayBinaryStringLength(int index)
                              throws java.lang.IllegalArgumentException
Gets the string length used to represent the maximum value of the parameter as a Gray coded binary string.

Parameters:
index - index of the discrete variable
Returns:
the string length used to represent the maximum value of the parameter
Throws:
java.lang.IllegalArgumentException - if the maximum value has not been set for this variable

getGrayBinaryString

public int[] getGrayBinaryString(int index)
Gets the value of a discrete variable encoded as a binary string using Gray encoding.

Parameters:
index - index of the discrete variable
Returns:
the value of the discrete variable, Gray encoded, as a binary string

setGrayBinaryString

public void setGrayBinaryString(int index,
                                int[] graBinStr)
Sets the value of a discrete variable as a Gray encoded binary string. If graBinStr represent a larger value than the maximum allowed value for this variable, then the variable value will be set to its maximum value.

Parameters:
index - index of the discrete variable
graBinStr - the value of the discrete variable as a Gray encoded binary string
Throws:
java.lang.IllegalArgumentException - if no maximum is set for this variable

main

public static void main(java.lang.String[] args)