LSArray Class¶
- class localsolver.LSArray¶
Value type for array expressions. Such value is obtained with
LSExpression.GetArrayValue()
orLSSolution.GetArrayValue(LSExpression)
. An array can contain numbers (int, double), other LSArray (for multi-dimensional arrays) or LSCollection (list, set).Arrays are not decisions and cannot be modified.
- Since
7.5
- See
- See
- See
Summary¶
Returns the number of values in the array. |
|
Returns true if the value at the given position is a boolean. |
|
Returns true if the value at the given position is an integer. |
|
Returns true if the value at the given position is a double. |
|
Returns true if the value at the given position is an interval. |
|
Returns true if the value at the given position is an array. |
|
Returns true if the value at the given position is undefined. |
|
Returns the integer value at the given position. |
|
Returns the double value at the given position. |
|
Returns the interval value at the given position. |
|
Returns the array value at the given position. |
|
Returns a string representation of the values in the array in the format { val0, val1, ..., valN }. |
|
Copy all the values of this array to the given array. |
Instance methods¶
- int Count()¶
Returns the number of values in the array. Elements in arrays are indexed from 0 to count()-1.
- Returns
Number of values in the array.
- Return type
int
- bool IsBool(int position)¶
Returns true if the value at the given position is a boolean. You can retrieve the value with
GetIntValue()
.- Arguments
position (int) – Position of the value to query.
- Returns
True if the value at the given position is a boolean.
- Return type
bool
- bool IsInt(int position)¶
Returns true if the value at the given position is an integer. You can retrieve the value with
GetIntValue()
.- Arguments
position (int) – Position of the value to query.
- Returns
True if the value at the given position is an integer.
- Return type
bool
- bool IsDouble(int position)¶
Returns true if the value at the given position is a double. You can retrieve the value with
GetDoubleValue()
.- Arguments
position (int) – Position of the value to query.
- Returns
True if the value at the given position is a boolean.
- Return type
bool
- bool IsInterval(int position)¶
Returns true if the value at the given position is an interval. You can retrieve the value with
GetIntervalValue()
.- Arguments
position (int) – Position of the value to query.
- Returns
True if the value at the given position is an interval.
- Return type
bool
- bool IsArray(int position)¶
Returns true if the value at the given position is an array. You can retrieve the value with
GetArrayValue()
.- Arguments
position (int) – Position of the value to query.
- Returns
True if the value at the given position is an array.
- Return type
bool
- bool IsUndefined(int position)¶
Returns true if the value at the given position is undefined. A value can be undefined in 4 cases:
It is a 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).
- Arguments
position (int) – Position of the value to query.
- Returns
True if the value at the given position is undefined.
- Return type
bool
- long GetIntValue(int position)¶
Returns the integer value at the given position. If the value is neither an integer, nor a boolean, an exception is thrown.
- Arguments
position (int) – Position of the value to query.
- Returns
Integer value.
- Return type
long
- double GetDoubleValue(int position)¶
Returns the double value at the given position. If the value is not a double, an exception is thrown.
- Arguments
position (int) – Position of the value to query.
- Returns
Double value.
- Return type
double
- LSInterval GetIntervalValue(int position)¶
Returns the interval value at the given position. If the value is not an interval, an exception is thrown.
- Arguments
position (int) – Position of the value to query.
- Returns
Interval value.
- Return type
- LSArray GetArrayValue(int position)¶
Returns the array value at the given position. If the value is not an array, an exception is thrown.
- Arguments
position (int) – Position of the value to query.
- Returns
Array value.
- Return type
- string ToString()¶
Returns a string representation of the values in the array in the format
{ val0, val1, ..., valN }
.- Returns
A String representation of the array
- Return type
string
- void CopyTo(long[] values)¶
Copy all the 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); }
- Arguments
values (long[]) – Array that will receive the integer values of this array.
- void CopyTo(double[] values)
Copy all the 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.GetDoubleValue(i); }
- Arguments
values (double[]) – Array that will receive the double values of this array.