LocalSolver logo
is now
Hexaly logo

We're excited to share that we are moving forward. We're leaving behind the LocalSolver brand and transitioning to our new identity: Hexaly. This represents a leap forward in our mission to enable every organization to make better decisions faster when faced with operational and strategic challenges.

This page is for an old version of Hexaly Optimizer. We recommend that you update your version and read the documentation for the latest stable release.

LSOperator Enumeration

class localsolver.LSOperator

Mathematical operators available for modeling. These operators are used to type the expressions created in LocalSolver mathematical optimization model.

As other enumerations present in the localsolver module, LSOperator is enumerable and indexable:

print (LSOperator[0])        # Shows LSOperator.BOOL
print (LSState.BOOL.value)   # Shows 0

# Iterates over the members of LSOperator
for e in LSOperator:
    print e
BOOL

Boolean decision. Decisional operator with no operand. Decision variable with domain {0,1}.

FLOAT

Float decision. Operator with two operands that represent the lower bound and the upper bound of the decision (domain [lb, ub]). The bounds must be constants (integers or doubles).

Since:4.0
CONST

Constant. Unary operator. Can be equal to any integer. Note that constants 0 or 1 are considered as boolean. Constants are implicitly created when passing integer arguments to LSModel.create_expression() or LSExpression.add_operand().

SUM

Sum. N-ary arithmetic operator. SUM(e1, e2, ..., eN) is equal to the sum of all operands e1, e2, ..., eN. This operator returns an integer if all the operands are booleans or integers and a double as soon as one operand is a double.

With ranges

This operator can also be used with RANGE to create expressions with a dynamic number of operands. In that case, this operator becomes a binary operator that takes a range as first operand and a function (FUNCTION or NATIVE_FUNCTION) as second operand. The operator will call the function on each value of the range and sum all the values computed and returned by the function.

SUB

Substraction. Binary arithmetic operator. SUB(x, y) is equal to the value of x - y. This operator returns an integer or a double according to the type of its operands.

Since:4.0
PROD

Product. N-ary arithmetic operator. PROD(e1, e2, ..., eN) is equal to the product of all operands e1, e2, ..., eN. This operator returns an integer if all the operands are booleans or integers, and a double as soon as one operand is a double.

With ranges

This operator can also be used with RANGE to create expressions with a dynamic number of operands. In that case, this operator becomes a binary operator that takes a range as first operand and a function (FUNCTION or NATIVE_FUNCTION) as second operand. The operator will call the function on each value of the range and compute the product of all the values returned by the function.

MAX

Maximum. N-ary arithmetic operator. MAX(e1, e2, ..., eN) is equal to the maximum value among all operands e1, e2, ..., eN. This operator returns an integer if all the operands are booleans or integers, and a double as soon as one operand is a double.

With ranges

This operator can also be used with RANGE to create expressions with a dynamic number of operands. In that case, this operator becomes a binary operator that takes a range as first operand and a function (FUNCTION or NATIVE_FUNCTION) as second operand. The operator will call the function on each value of the range and find the maximum value among all the values returned by the function.

MIN

Minimum. N-ary arithmetic operator. MIN(e1, e2, ..., eN) is equal to the minimum value among all operands e1, e2, ..., eN. This operator returns an integer if all the operands are booleans or integers, and a double as soon as one operand is a double.

With ranges

This operator can also be used with RANGE to create expressions with a dynamic number of operands. In that case, this operator becomes a binary operator that takes a range as first operand and a function (FUNCTION or NATIVE_FUNCTION) as second operand. The operator will call the function on each value of the range and find the minimum value among all the values returned by the function.

EQ

Equal. Binary relational operator. EQ(a, b) = 1 if a == b, and 0 otherwise. This operator returns a boolean.

NEQ

Not equal to. Binary relational operator. NEQ(a,b) = 1 if a != b, and 0 otherwise. This operator returns a boolean.

GEQ

Greater than or equal to. Binary relational operator. GEQ(a,b) = 1 if a >= b, and 0 otherwise. This operator returns a boolean.

LEQ

Lower than or equal to. Binary relational operator. LEQ(a,b) = 1 if a <= b, and 0 otherwise. This operator returns a boolean.

GT

Strictly greater than. Binary relational operator. GT(a,b) = 1 if a > b, and 0 otherwise. This operator returns a boolean.

LT

Strictly lower than. Binary relational operator. LQ(a, b) = 1 if a < b, and 0 otherwise. This operator returns a boolean.

IF

If-Then-Else. Ternary conditional operator. IF(a,b,c) is equal to b if a is true, and c otherwise. Note that the first operand must be a boolean (that is, equal to 0 or 1). This operator returns a boolean, an integer or a double according to the type of the second and third operands.

NOT

Not. Unary logical operator. NOT(a) = 1 - a. Note that the operand must be boolean (that is, equal to 0 or 1). This operator returns a boolean.

AND

And. N-ary logical operator. AND(e1, e2, ..., eN) is equal to 1 (true) if all the operands e1, e2, ..., eN are 1, and 0 otherwise. All the operands must be boolean (that is, equal to 0 or 1). This operator returns a boolean.

With ranges

This operator can also be used with RANGE to create expressions with a dynamic number of operands. In that case, this operator becomes a binary operator that takes a range as first operand and a function (FUNCTION or NATIVE_FUNCTION) as second operand. The operator will call the function on each value of the range and will return 1 if all the values returned by the function are 1 and 0 otherwise.

OR

Or. N-ary logical operator. OR(e1, e2, ..., eN) is equal to 0 (false) if all operands e1, e2, ..., eN are 0, and 1 otherwise. All the operands must be boolean (that is, equal to 0 or 1). This operator returns a boolean.

With ranges

This operator can also be used with RANGE to create expressions with a dynamic number of operands. In that case, this operator becomes a binary operator that takes a range as first operand and a function (FUNCTION or NATIVE_FUNCTION) as second operand. The operator will call the function on each value of the range and will return 0 if all the values returned by the function are 0 and 1 otherwise.

XOR

Exclusive or (also called “xor”). N-ary logical operator. XOR(e1, e2, ..., eN) is equal to 0 if the number of operands with value 1 among e1, e2, ..., eN is even, and 1 otherwise. Remarkable case: XOR(a,b) = 1 if a == b, and 0 otherwise. All the operands must be boolean (that is, equal to 0 or 1). This operator returns a boolean.

With ranges

This operator can also be used with RANGE to create expressions with a dynamic number of operands. In that case, this operator becomes a binary operator that takes a range as first operand and a function (FUNCTION or NATIVE_FUNCTION) as second operand. The operator will call the function on each value of the range and will return 0 if the number of value 1 returned by the function is even, and 1 otherwise.

ABS

Absolute value. Unary arithmetic operator. ABS(e) = e >= 0 ? e : -e. This operator returns an integer or a double according to the type of its operand.

DIST

Distance between two numbers. Binary arithmetic operator. DIST(a,b) = ABS(a-b). This operator returns an integer or a double according to the type of its operands.

DIV

Division. Binary arithmetic operator. This operator always returns a double. Note that until version 4.0, the division was an integer division if both operands were integers.

MOD

Modulo (remainder of the integer division). Binary arithmetic operator. MOD(a,b) = r such that a = q * b + r with q, r integers and |r| < b. An error will be thrown if b equals 0 at an iteration of the search. Note that the operands must be integers. This operator returns an integer.

ARRAY

Array. An array is a collection of elements. Indexes begin at 0. It could be used with operators like AT or SCALAR. An array doesn’t have a value by itself, but can contain operands of type boolean, integer, double or array (for multi-dimensional arrays). All the elements of an array must be of the same type.

With ranges

This operator can also be used with RANGE to create an array with a dynamic number of elements. In that case, this operator becomes a binary operator that takes a range as first operand and a function (FUNCTION or NATIVE_FUNCTION) as second operand. The operator will call the function on each value of the range and the returned values will be used to populate the array.

Since:2.1
AT

Returns the element of an array. my_array[i] returns the i element of the array my_array. An error will be thrown if i is out of range. This operator returns a boolean, an integer or a double according to the type of the operands in the array.

Since:2.1
SCALAR

Scalar product. SCALAR(a, x) = sum(a[i]*x[i]) with a and x two arrays. This operator returns an integer or a double according to the type of the operands in the arrays.

Since:2.1
CEIL

Ceil. Unary arithmetic operator. Returns a value rounded to the next highest integer. This operator returns an integer.

Since:3.0
FLOOR

Floor. Unary arithmetic operator. Returns a value rounded to the next lowest integer. This operator returns an integer.

Since:3.0
ROUND

Round. Unary arithmetic operator. Returns a value rounded to the nearest integer. This operator returns an integer.

Since:3.0
SQRT

Square root. Unary arithmetic operator. This operator returns a double.

Since:3.0
LOG

Natural logarithm (base-e). Unary arithmetic operator. This operator returns a double.

Since:3.0
EXP

Base-e exponential. Unary arithmetic operator. This operator returns a double.

Since:3.0
POW

Power operator. POW(x, y) is equals to the value of x to the power of y. This operator returns a double.

Since:3.0
COS

Cosine. Unary arithmetic operator. This operator returns a double.

Since:3.0
SIN

Sine. Unary arithmetic operator. This operator returns a double.

Since:3.0
TAN

Tangent. Unary arithmetic operator. This operator returns a double.

Since:3.0
INT

Integer decision variable. Decisional operator with two operands min and max. Decision variable with domain [min,max].

Since:5.0
PIECEWISE

Piecewise-linear function operator. The piecewise linear function is defined by two arrays of numbers giving the breakpoints of the function. This operator has exactly 3 operands: The first two operands must be two arrays of equal lengths (necessarily larger or equal to 2). These arrays must contain constant numbers (int or double). The first array must contain numbers in ascending order. The third operand must be an integer or double expression. An exception will be thrown if its value is strictly smaller that the first element of the first array, or strictly larger than the last element of the first array. This operator returns a double.

PIECEWISE(x,y,z) returns the image of z by the function defined by geometric points (x[0], y[0]), (x[1], y[1]), ..... (x[n-1], y[n-1]), For instance PIECEWISE({0, 50, 100}, {0, 10, 100}, 75) returns 55.

Discontinuities are allowed in the definition of the function, that is to say that two geometric points can share the same x-coordinate. By convention the value taken by the function at such a discontinuous point is the one associated to the last occurrence of this x-coordinate in array x. For instance PIECEWISE({0, 50, 50, 100},{0, 0.1, 0.9, 1}, 50) returns 0.9;

Since:5.0
LIST

A list is a collection of integers within a range [0, n-1] where n is the unique argument of this operator. Mathematically a list is a permutation of a subset of [0, n-1]. This operator takes exactly one operand: a strictly positive integer constant. All values in the list will be pairwise different, non negative and strictly smaller that this number.

The elements of the list can be accessed individually with the operator AT.

COUNT

The number of elements in a collection. This operator takes exactly one argument of type list.

Since:5.5
INDEXOF

The index of a value in a list (-1 if the value is not in the list). This operator takes exactly two arguments: the first one is a list, the second one is an integer expression.

Since:5.5
PARTITION

Partition. N-ary logical operator. PARTITION(l1, l2, ..., lN) is true if all lists l1,l2..lN form a partition of their common range. All parameters of this operator must be lists on the same range.

Since:5.5
DISJOINT

Disjoint. N-ary logical operator. DISJOINT(l1, l2, ..., lN) is true if all lists l1, l2, ..., lN are pairwise disjoint. All parameters of this operator must be lists on the same range.

Since:5.5
NATIVE_FUNCTION

Native function.

Native functions are used to retrieve the value of expressions from external functions written with your favorite language. Native functions are created with the dedicated method LSModel.create_native_function().

Since:6.0
CALL

Call a particular function.

The first operand must be a function (like NATIVE_FUNCTION). The other operands are passed to the function as arguments.

Since:6.0
FUNCTION

Function. Functions are created with the dedicated method LSModel.create_function().

Since:7.0
ARGUMENT

Argument of a function. Arguments are automatically and implicitely created when you create a function with method LSModel.create_function().

Since:7.0
RANGE

Range expression. A range doesn’t have a value by itself but can be used with N-ary operators like SUM, PROD, MIN, MAX, OR, AND, XOR or ARRAY to create expressions that have a dynamic number of operands.

A range must have exacty two operands that represent the lower bound and the upper bound of the range. These operands must be integers.

Since:7.0