LSExpression Type¶
- type lsexpression¶
Mathematical modeling expression. Expressions are used to build the mathematical optimization model associated to LocalSolver. An expression is composed of an operator (which corresponds to its type) and its operands (which are other expressions of the model).
- See
Summary¶
Operator of this expression returned as a string. |
|
Index of this expression in the model. |
|
This field returns a readonly map-like structure containing all the operands of this expression. |
|
Number of operands of this expression. |
|
Name of this expression or the empty string if no name has been set. |
|
Value of this expression in the best solution found by the solver. |
|
External function context of this expression. |
Returns true if this expression is typed as decision in the model, false otherwise. |
|
Returns true if this expression is tagged as constraint in the model, false otherwise. |
|
Returns true if this expression is tagged as objective in the model, false otherwise. |
|
Returns true if this expression is typed as constant in the model, false otherwise. |
|
Returns true if this expression is an integer, false otherwise. |
|
Returns true if this expression is a boolean (ie 0 or 1), false otherwise. |
|
Returns true if this expression is a double, false otherwise. |
|
Returns true if this expression is a collection (list or set), false otherwise. |
|
Returns true if this expression is an array, false otherwise. |
|
Returns true if this expression is a function, false otherwise. |
|
Returns true if this expression is a range, false otherwise. |
|
Returns true if the given expression is violated in the best solution found by the solver. |
|
Returns true if the given expression has an undefined value in the best solution found by the solver. |
|
Returns true if this expression has a name, and false otherwise. |
Returns the same expression without change. |
|
Returns a new expression that is the opposite of the current expression. |
|
Returns a new expression that is the sum of the current expression and the argument other. |
|
Returns a new expression that is the substraction of the current expression and the argument other. |
|
Returns a new expression that is the product of the current expression and the argument other. |
|
Returns a new expression that is the division of the current expression and the argument other. |
|
Returns a new expression that is the remainder of the integer division of the current expression and the argument other. |
|
Returns a new expression that is the negative of the current expression. |
|
Returns a new expression that is the logical and of the current expression and the argument other. |
|
Returns a new expression that is the logical or of the current expression and the argument other. |
|
Returns a new strictly lower expression between the current expression and the argument other. |
|
Returns a new lower or equal expression between the current expression and the argument other. |
|
Returns a new strictly greater expression between the current expression and the argument other. |
|
Returns a new greater or equal expression between the current expression and the argument other. |
|
Returns a new equal expression between the current expression and the argument other. |
|
Returns a new not equal expression between the current expression and the argument other. |
|
Returns a new range expression between the current expression and the argument other. |
|
Returns a new if-then-else expression (also called the ternary operator). |
|
This operator is applied when the <- sign is used on an lsexpression. |
|
This operator is applied when the = sign is used on an lsexpression. |
|
This operator is called when an expression is used with one of the three special modifiers : MINIMIZE, MAXIMIZE or CONSTRAINT. |
Attributes¶
- lsexpression.operator¶
Operator of this expression returned as a string.
- Return type
string
- lsexpression.index¶
Index of this expression in the model.
- Return type
int
- lsexpression.operands¶
This field returns a readonly map-like structure containing all the operands of this expression. The returned structure has the following features:
A count field to get the number of operands, e.g.
operands.count()
.An overloaded index
[]
operator to get a specific operand, e.g.operands[0]
. The index must be between0
andoperands.count() - 1
. Accessing a value outside these bounds throws an exception.An overloaded
iterator
operator to iterate over the operands with afor
statement.
- Return type
map-like structure containing objects of
lsexpression
.
- lsexpression.nbOperands¶
Number of operands of this expression.
- Return type
int
- lsexpression.name¶
Name of this expression or the empty string if no name has been set.
This attribute is read-write but it can only be changed in state
MODELING
.- Return type
string
- lsexpression.value¶
Value of this expression in the best solution found by the solver. This method is a shortcut for
lssolution.getValue()
andlssolution.setValue()
.The type of the returned value depends on the type of the expression. It can be a number if the expression has an integer or double value, an array if the expression is an array, or a collection if the expression is a list or a set decision.
This attribute is read-write but it can only be changed in state
STOPPED
and queried in statesPAUSED
orSTOPPED
.- Return type
a number, an array or a collection depending on the type of the expression.
- lsexpression.context¶
External function context of this expression. Only set and allowed if this expression is an external function.
- Return type
lsexternalcontext
Functions¶
- lsexpression.isDecision()¶
Returns true if this expression is typed as decision in the model, false otherwise.
- Return type
bool
- lsexpression.isConstraint()¶
Returns true if this expression is tagged as constraint in the model, false otherwise.
- Return type
bool
- lsexpression.isObjective()¶
Returns true if this expression is tagged as objective in the model, false otherwise.
- Return type
bool
- lsexpression.isConstant()¶
Returns true if this expression is typed as constant in the model, false otherwise.
- Return type
bool
- lsexpression.isInt()¶
Returns true if this expression is an integer, false otherwise. Only allowed in states
PAUSED
orSTOPPED
. Note that a boolean is also an integer.- Return type
bool
- lsexpression.isBool()¶
Returns true if this expression is a boolean (ie 0 or 1), false otherwise. Only allowed in states
PAUSED
orSTOPPED
.- Return type
bool
- lsexpression.isDouble()¶
Returns true if this expression is a double, false otherwise. Only allowed in states
PAUSED
orSTOPPED
.- Return type
bool
- lsexpression.isCollection()¶
Returns true if this expression is a collection (list or set), false otherwise. Only allowed in states
PAUSED
orSTOPPED
.- Return type
bool
- lsexpression.isArray()¶
Returns true if this expression is an array, false otherwise. Only allowed in states
PAUSED
orSTOPPED
.- Return type
bool
- lsexpression.isFunction()¶
Returns true if this expression is a function, false otherwise. Only allowed in states
PAUSED
orSTOPPED
.- Return type
bool
- lsexpression.isRange()¶
Returns true if this expression is a range, false otherwise. Only allowed in states
PAUSED
orSTOPPED
.- Return type
bool
- lsexpression.isViolated()¶
Returns true if the given expression is violated in the best solution found by the solver. An expression can be violated in 3 cases:
It is a constraint and its value is 0.
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).
Only allowed in states
PAUSED
orSTOPPED
. This method is a shortcut forlssolution.isViolated()
.- Return type
bool
- lsexpression.isUndefined()¶
Returns true if the given expression has an undefined value in the best solution found by the solver. An expression 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).
Only allowed in states
PAUSED
orSTOPPED
. This method is a shortcut forlssolution.isUndefined()
.- Return type
bool
- lsexpression.isNamed()¶
Returns true if this expression has a name, and false otherwise.
- Return type
bool
Overloaded operators¶
- lsexpression.pos()¶
Returns the same expression without change.
- Return type
- lsexpression.neg()¶
Returns a new expression that is the opposite of the current expression.
- Return type
- lsexpression.add(other)¶
- lsexpression.radd(other)¶
Returns a new expression that is the sum of the current expression and the argument
other
. This operator exists in two versions depending on the position of the current expression in the addition (left or right).Note that in some cases, this operator can return one of the two operands rather than creating a new expression (sum with constant 0).
- Parameters
other – Can be a bool, an integer, a double or another lsexpression
- Return type
- lsexpression.sub(other)¶
- lsexpression.rsub(other)¶
Returns a new expression that is the substraction of the current expression and the argument
other
. This operator exists in two versions depending on the position of the current expression in the substraction (left or right).Note that in some cases, this operator can return the left operand instead of creating a new expression if the right operand is the constant 0.
- Parameters
other – Can be a bool, an integer, a double or another lsexpression
- Return type
- lsexpression.mul(other)¶
- lsexpression.rmul(other)¶
Returns a new expression that is the product of the current expression and the argument
other
. This operator exists in two versions depending on the position of the current expression in the product (left or right).Note that in some cases, this operator can return one of the two operands rather than creating a new expression (product with constant 1) or returns the lsexpression representing the constant 0 (product with constant 0).
- Parameters
other – Can be a bool, an integer, a double or another lsexpression
- Return type
- lsexpression.div(other)¶
- lsexpression.rdiv(other)¶
Returns a new expression that is the division of the current expression and the argument
other
. This operator exists in two versions depending on the position of the current expression in the division (left or right).Note that in some cases, this operator can return the left operand instead of creating a new expression if the right operand is the constant 1.
- Parameters
other – Can be a bool, an integer, a double or another lsexpression
- Return type
- lsexpression.mod(other)¶
- lsexpression.rmod(other)¶
Returns a new expression that is the remainder of the integer division of the current expression and the argument
other
. This operator exists in two versions depending on the position of the current expression in the modulo (left or right).Note that in some cases, this operator can return the lsexpression representing the constant 0 if the right operand is the constant 1.
- Parameters
other – Can be a bool, an integer or another lsexpression
- Return type
- lsexpression.not(other)¶
Returns a new expression that is the negative of the current expression.
NOT(a) = 1 - a
.- Return type
- lsexpression.and(other)¶
- lsexpression.rand(other)¶
Returns a new expression that is the logical
and
of the current expression and the argumentother
. This operator exists in two versions depending on the position of the current expression in the product (left or right).Note that in some cases, this operator can return one of the two operands rather than creating a new expression (logical
and
with constant 1 or true) or returns the lsexpression representing the constant 0 (logicaland
with constant 0 or false).- Parameters
other – Can be a bool or another lsexpression
- Return type
- lsexpression.or(other)¶
- lsexpression.ror(other)¶
Returns a new expression that is the logical
or
of the current expression and the argumentother
. This operator exists in two versions depending on the position of the current expression in the product (left or right).Note that in some cases, this operator can return one of the two operands rather than creating a new expression (logical
or
with constant 0 or false) or returns the lsexpression representing the constant 1 (logicalor
with constant 1 or true).- Parameters
other – Can be a bool or another lsexpression
- Return type
- lsexpression.lt(other)¶
- lsexpressionr.rlt(other)¶
Returns a new strictly lower expression between the current expression and the argument
other
. This operator exists in two versions depdending on the position of the current expression (left or right).- Parameters
other – Can be a bool, an integer, a double or another lsexpression
- Return type
- lsexpression.leq(other)¶
- lsexpression.rleq(other)¶
Returns a new lower or equal expression between the current expression and the argument
other
. This operator exists in two versions depdending on the position of the current expression (left or right).- Parameters
other – Can be a bool, an integer, a double or another lsexpression
- Return type
- lsexpression.gt(other)¶
- lsexpressionr.rgt(other)¶
Returns a new strictly greater expression between the current expression and the argument
other
. This operator exists in two versions depdending on the position of the current expression (left or right).- Parameters
other – Can be a bool, an integer, a double or another lsexpression
- Return type
- lsexpression.geq(other)¶
- lsexpression.rgeq(other)¶
Returns a new greater or equal expression between the current expression and the argument
other
. This operator exists in two versions depdending on the position of the current expression (left or right).- Parameters
other – Can be a bool, an integer, a double or another lsexpression
- Return type
- lsexpression.eq(other)¶
- lsexpressionr.req(other)¶
Returns a new equal expression between the current expression and the argument
other
. This operator exists in two versions depdending on the position of the current expression (left or right).- Parameters
other – Can be a bool, an integer, a double or another lsexpression
- Return type
- lsexpression.neq(other)¶
- lsexpression.rneq(other)¶
Returns a new not equal expression between the current expression and the argument
other
. This operator exists in two versions depdending on the position of the current expression (left or right).- Parameters
other – Can be a bool, an integer, a double or another lsexpression
- Return type
- lsexpression.range(other)¶
- lsexpression.rrange(other)¶
Returns a new range expression between the current expression and the argument
other
. This operator exists in two versions depdending on the position of the current expression (left or right).- Parameters
other – Can be a bool, an integer, a double or another lsexpression
- Return type
- lsexpression.ternary(trueValue, falseValue)¶
Returns a new if-then-else expression (also called the ternary operator). The current expression is used as the condition and the arguments as true and false values respectively.
- Parameters
trueValue – Can be a bool, an integer, a double or an lsexpression
falseValue – Can be a bool, an integer, a double or an lsexpression
- Return type
- lsexpression.index(index)
Returns a new at expression. The current expression is used as the array and the argument as the index.
- Parameters
index – Can be a bool, an integer or another lspexression
- Return type
- lsexpression.linkable()¶
This operator is applied when the
<-
sign is used on an lsexpression. It only returns the current lsexpression, without changing anything
- lsexpression.assignable()¶
This operator is applied when the
=
sign is used on an lsexpression. The implemented behavior is to throw an exception. lsexpressions can only be manipulated with the<-
operator.
- lsexpression.modify({MINIMIZE, MAXIMIZE, CONSTRAINT})¶
This operator is called when an expression is used with one of the three special modifiers : MINIMIZE, MAXIMIZE or CONSTRAINT. It adds the expression to the list of objectives or constraints of the current model.