Class HxArray

java.lang.Object
com.hexaly.optimizer.HxArray

public class HxArray extends Object
Value type for array expressions. Such value is obtained with HxExpression.getArrayValue() or HxSolution.getArrayValue(com.hexaly.optimizer.HxExpression). An array contains values of type int, double, HxInterval, HxArray (for multi-dimensional arrays) or HxCollection (list or set). Note that it's possible to mix integers or doubles in the same array. Arrays are not decisions and cannot be modified.
Since:
7.5
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    copyTo(double[] values)
    Copy all the double values of this array to the given array.
    void
    copyTo(long[] values)
    Copy all the integer values of this array to the given array.
    int
    Returns the number of elements in the array.
    boolean
     
    getArrayValue(int pos)
    Returns the array value at the given position.
    Returns the collection value at the given position.
    double
    getDoubleValue(int pos)
    Returns the double value at the given position.
    Returns the interval value at the given position.
    long
    getIntValue(int pos)
    Returns the integer value at the given position.
    int
     
    boolean
    isArray(int pos)
    Returns true if the value at the given position is an array.
    boolean
    isBool(int pos)
    Returns true if the value at the given position is a boolean.
    boolean
    isCollection(int pos)
    Returns true if the value at the given position is a collection (list or set).
    boolean
    isDouble(int pos)
    Returns true if the value at the given position is a double.
    boolean
    isInt(int pos)
    Returns true if the value at the given position is an integer.
    boolean
    isInterval(int pos)
    Returns true if the value at the given position is an interval.
    boolean
    isUndefined(int pos)
    Returns true if the value at the given position is undefined.
    Returns a string representation of the values in the array in the format "{ val0, val1, ..., valN }"

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Method Details

    • count

      public int count()
      Returns the number of elements in the array. Elements in arrays are indexed from 0 to count()-1
      Returns:
      Number of elements in the array.
    • isBool

      public boolean isBool(int pos)
      Returns true if the value at the given position is a boolean. You can retrieve the value with getIntValue(int).
      Parameters:
      pos - Position of the value to query.
      Returns:
      True if the value at the given position is a boolean.
    • isInt

      public boolean isInt(int pos)
      Returns true if the value at the given position is an integer. You can retrieve the value with getIntValue(int).
      Parameters:
      pos - Position of the value to query.
      Returns:
      True if the value at the given position is an integer.
    • isDouble

      public boolean isDouble(int pos)
      Returns true if the value at the given position is a double. You can retrieve the value with getDoubleValue(int).
      Parameters:
      pos - Position of the value to query.
      Returns:
      True if the value at the given position is a double.
    • isInterval

      public boolean isInterval(int pos)
      Returns true if the value at the given position is an interval. You can retrieve the value with getIntervalValue(int).
      Parameters:
      pos - Position of the value to query.
      Returns:
      True if the value at the given position is an interval.
    • isArray

      public boolean isArray(int pos)
      Returns true if the value at the given position is an array. You can retrieve the value with getArrayValue(int).
      Parameters:
      pos - Position of the value to query.
      Returns:
      True if the value at the given position is an array.
    • isCollection

      public boolean isCollection(int pos)
      Returns true if the value at the given position is a collection (list or set). You can retrieve the value with getCollectionValue(int).
      Parameters:
      pos - Position of the value to query.
      Returns:
      True if the value at the given position is a collection.
    • isUndefined

      public boolean isUndefined(int pos)
      Returns true if the value at the given position is undefined. A value can be undefined in 4 cases:
      1. It is a double and its value is NaN (Not a Number).
      2. It is an integer or boolean with no valid value (arithmetic or out of bounds exception).
      3. It is an interval with at least one undefined bound.
      4. It is the result of any ill-defined operation (at with out of bounds index or operations on undefined values for instance).
      Parameters:
      pos - Position of the value to query.
      Returns:
      True if the value at the given position is undefined.
    • getIntValue

      public long getIntValue(int pos)
      Returns the integer value at the given position. If the value is neither an integer nor a boolean, an exception is thrown.
      Parameters:
      pos - Position of the value to query.
      Returns:
      Integer value.
    • getDoubleValue

      public double getDoubleValue(int pos)
      Returns the double value at the given position. If the value is not a double, an exception is thrown.
      Parameters:
      pos - Position of the value to query.
      Returns:
      Double value.
    • getIntervalValue

      public HxInterval getIntervalValue(int pos)
      Returns the interval value at the given position. If the value is not an interval, an exception is thrown.
      Parameters:
      pos - Position of the value to query.
      Returns:
      Interval value.
    • getArrayValue

      public HxArray getArrayValue(int pos)
      Returns the array value at the given position. If the value is not an array, an exception is thrown.
      Parameters:
      pos - Position of the value to query.
      Returns:
      Array value.
    • getCollectionValue

      public HxCollection getCollectionValue(int pos)
      Returns the collection value at the given position. If the value is not a collection, an exception is thrown.
      Parameters:
      pos - Position of the value to query.
      Returns:
      Collection value.
    • copyTo

      public void copyTo(long[] values)

      Copy all the integer values of this array to the given array. Only the integer values are copied to their corresponding position in the array. Cells of the array given in parameters that correspond to positions of non-integer values in this array remain unchanged.

      The length of the array given in parameters can be different from the number of elements in this array. In that case, only the elements that fit in the array are copied.

      This method is recommended if you need to access all the values of this array, instead of the roughly equivalent, but less performant, following code:

       
       for(int i = 0; i < Math.min(values.length, array.count()); ++i) {
           if(!array.isInt(i)) continue;
           values[i] = array.getIntValue(i);
       }
       
       
      Parameters:
      values - array that will receive the integer values of this array.
    • copyTo

      public void copyTo(double[] values)

      Copy all the double values of this array to the given array. Only the double values are copied to their corresponding position in the array. Cells of the array given in parameters that correspond to positions of non-double values in this array remain unchanged.

      The length of the array given in parameters can be different from the number of elements in this array. In that case, only the elements that fit in the array are copied.

      This method is recommended if you need to access all the values of this array, instead of the roughly equivalent, but less performant, following code:

       
       for(int i = 0; i < Math.min(values.length, array.count()); ++i) {
           if(!array.isDouble(i)) continue;
           values[i] = array.getDouble(i);
       }
       
       
      Parameters:
      values - array that will receive the double values of this array.
    • toString

      public String toString()
      Returns a string representation of the values in the array in the format "{ val0, val1, ..., valN }"
      Overrides:
      toString in class Object
      Returns:
      String representation.
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object