HxArray Class

class hexaly.optimizer.HxArray

Value type for array expressions.

Such a value is obtained with HxExpression.value when the expression is an array. An array can contain numbers (int, double), other HxArray (for multi-dimensional arrays), HxInterval or HxCollection (list, set).

Arrays are not decisions and cannot be modified.

Since:7.5
See:HxModel
See:HxExpression
See:HxOperator.ARRAY

Summary

Methods
count Returns the number of values in the collection.
is_bool Returns true if the value at the given position is a boolean.
is_int Returns true if the value at the given position is an integer.
is_double Returns true if the value at the given position is a double.
is_interval Returns true if the value at the given position is an interval.
is_array Returns true if the value at the given position is an array.
is_collection Returns true if the value at the given position is a collection (list or set).
is_undefined Returns true if the value at the given position is undefined.
get Gets the value at the given position.
get_int_value Gets the integer value at the given position.
get_double_value Gets the double value at the given position.
get_interval_value Gets the interval value at the given position.
get_array_value Gets the array value at the given position.
get_collection_value Gets the collection value at the given position.
Special methods
__str__ Returns a string representation of the values in the array in the format { val0, val1, ..., valN }ReturnsString representation of this array.
__getitem__ Operator overloading for HxArray.get().
__len__ Returns the length of the array (same result as HxArray.count()).
__iter__ Returns an iterator for the content of this array.

Instance methods

HxArray.count()

Returns the number of values in the collection. Elements in arrays are indexed from 0 to count()-1.

Returns:Number of values in this HxCollection
Return type:int
HxArray.is_bool(pos)

Returns true if the value at the given position is a boolean. You can retrieve the value with get() or with the special overloaded operator __getitem__().

Parameters:pos (int) – Position of the value to query.
Returns:True if the value at the given position is a boolean.
Return type:bool
HxArray.is_int(pos)

Returns true if the value at the given position is an integer. You can retrieve the value with get() or with the special overloaded operator __getitem__().

Parameters:pos (int) – Position of the value to query.
Returns:True if the value at the given position is an integer.
Return type:bool
HxArray.is_double(pos)

Returns true if the value at the given position is a double. You can retrieve the value with get() or with the special overloaded operator __getitem__().

Parameters:pos (int) – Position of the value to query.
Returns:True if the value at the given position is a double.
Return type:bool
HxArray.is_interval(pos)

Returns true if the value at the given position is an interval. You can retrieve the value with get() or with the special overloaded operator __getitem__().

Parameters:pos (int) – Position of the value to query.
Returns:True if the value at the given position is an interval.
Return type:bool
HxArray.is_array(pos)

Returns true if the value at the given position is an array. You can retrieve the value with get() or with the special overloaded operator __getitem__().

Parameters:pos (int) – Position of the value to query.
Returns:True if the value at the given position is an array.
Return type:bool
HxArray.is_collection(pos)

Returns true if the value at the given position is a collection (list or set). You can retrieve the value with get() or with the special overloaded operator __getitem__().

Parameters:pos (int) – Position of the value to query.
Returns:True if the value at the given position is a collection.
Return type:bool
HxArray.is_undefined(pos)

Returns true if the value at the given position is undefined. A value can be undefined in 4 cases:

  • It is a double and its value is NaN (Not a Number).
  • It is an integer or boolean with no valid value (arithmetic or out of bounds exception).
  • It is an interval with at least one undefined bound.
  • It is the result of any ill-defined operation (at with out of bounds index or operations on undefined values for instance).
Parameters:pos (int) – Position of the value to query.
Returns:True if the value at the given position is undefined, or if the array is undefined if no argument is passed.
Return type:bool
HxArray.get(pos)

Gets the value at the given position. The type of the returned value can be a boolean, an integer, a double, a HxInterval, a HxArray or a HxCollection.

Parameters:pos (int) – Position of the value to query.
Returns:Value at the given position
Return type:int, double, HxInterval, HxArray or HxCollection.
HxArray.get_int_value(pos)

Gets the integer value at the given position. This method has the same effect as the get() method but it also ensures that the array is an array of integers. If not, an exception is thrown.

Parameters:pos (int) – Position of the value to query.
Returns:Value at the given position
Return type:int
Since:15.0
HxArray.get_double_value(pos)

Gets the double value at the given position. This method has the same effect as the get() method but it also ensures that the array is an array of doubles. If not, an exception is thrown.

Parameters:pos (int) – Position of the value to query.
Returns:Value at the given position
Return type:double
Since:15.0
HxArray.get_interval_value(pos)

Gets the interval value at the given position. This method has the same effect as the get() method but it also ensures that the array is an array of intervals. If not, an exception is thrown.

Parameters:pos (int) – Position of the value to query.
Returns:Value at the given position
Return type:HxInterval
Since:15.0
HxArray.get_array_value(pos)

Gets the array value at the given position. This method has the same effect as the get() method but it also ensures that the array is a multi-dimensional array (array of arrays). If not, an exception is thrown.

Parameters:pos (int) – Position of the value to query.
Returns:Value at the given position
Return type:HxArray
Since:15.0
HxArray.get_collection_value(pos)

Gets the collection value at the given position. This method has the same effect as the get() method but it also ensures that the array is an array of collections. If not, an exception is thrown.

Parameters:pos (int) – Position of the value to query.
Returns:Value at the given position
Return type:HxCollection
Since:15.0

Special operators and methods

HxArray.__str__()

Returns a string representation of the values in the array in the format { val0, val1, ..., valN }

Returns:String representation of this array.
Return type:str
HxArray.__getitem__(pos)

Operator overloading for HxArray.get().

HxArray.__len__()

Returns the length of the array (same result as HxArray.count()).

HxArray.__iter__()

Returns an iterator for the content of this array.