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.

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

lsmodel

Summary

Attributes

operator

Operator of this expression returned as a string.

index

Index of this expression in the model.

operands

This field returns a readonly map-like structure containing all the operands of this expression.

nbOperands

Number of operands of this expression.

name

Name of this expression or the empty string if no name has been set.

value

Value of this expression in the best solution found by the solver.

context

External function context of this expression.

Functions

isDecision

Returns true if this expression is typed as decision in the model, false otherwise.

isConstraint

Returns true if this expression is tagged as constraint in the model, false otherwise.

isObjective

Returns true if this expression is tagged as objective in the model, false otherwise.

isConstant

Returns true if this expression is typed as constant in the model, false otherwise.

isInt

Returns true if this expression is an integer, false otherwise.

isBool

Returns true if this expression is a boolean (ie 0 or 1), false otherwise.

isDouble

Returns true if this expression is a double, false otherwise.

isCollection

Returns true if this expression is a collection (list or set), false otherwise.

isArray

Returns true if this expression is an array, false otherwise.

isFunction

Returns true if this expression is a function, false otherwise.

isRange

Returns true if this expression is a range, false otherwise.

isViolated

Returns true if the given expression is violated in the best solution found by the solver.

isUndefined

Returns true if the given expression has an undefined value in the best solution found by the solver.

isNamed

Returns true if this expression has a name, and false otherwise.

Overloaded operators

pos

Returns the same expression without change.

neg

Returns a new expression that is the opposite of the current expression.

add

Returns a new expression that is the sum of the current expression and the argument other.

sub

Returns a new expression that is the substraction of the current expression and the argument other.

mul

Returns a new expression that is the product of the current expression and the argument other.

div

Returns a new expression that is the division of the current expression and the argument other.

mod

Returns a new expression that is the remainder of the integer division of the current expression and the argument other.

not

Returns a new expression that is the negative of the current expression.

and

Returns a new expression that is the logical and of the current expression and the argument other.

or

Returns a new expression that is the logical or of the current expression and the argument other.

lt

Returns a new strictly lower expression between the current expression and the argument other.

leq

Returns a new lower or equal expression between the current expression and the argument other.

gt

Returns a new strictly greater expression between the current expression and the argument other.

geq

Returns a new greater or equal expression between the current expression and the argument other.

eq

Returns a new equal expression between the current expression and the argument other.

neq

Returns a new not equal expression between the current expression and the argument other.

range

Returns a new range expression between the current expression and the argument other.

ternary

Returns a new if-then-else expression (also called the ternary operator).

linkable

This operator is applied when the <- sign is used on an lsexpression.

assignable

This operator is applied when the = sign is used on an lsexpression.

modify

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 between 0 and operands.count() - 1. Accessing a value outside these bounds throws an exception.

  • An overloaded iterator operator to iterate over the operands with a for 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() and lssolution.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 states PAUSED or STOPPED.

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 or STOPPED. 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 or STOPPED.

Return type

bool

lsexpression.isDouble()

Returns true if this expression is a double, false otherwise. Only allowed in states PAUSED or STOPPED.

Return type

bool

lsexpression.isCollection()

Returns true if this expression is a collection (list or set), false otherwise. Only allowed in states PAUSED or STOPPED.

Return type

bool

lsexpression.isArray()

Returns true if this expression is an array, false otherwise. Only allowed in states PAUSED or STOPPED.

Return type

bool

lsexpression.isFunction()

Returns true if this expression is a function, false otherwise. Only allowed in states PAUSED or STOPPED.

Return type

bool

lsexpression.isRange()

Returns true if this expression is a range, false otherwise. Only allowed in states PAUSED or STOPPED.

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 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 or STOPPED. This method is a shortcut for lssolution.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 2 cases:

  • It is a a double and its value is NaN (NotANumber).

  • It is an integer or boolean with no valid value (arithmetic or out of bounds exception).

Only allowed in states PAUSED or STOPPED. This method is a shortcut for lssolution.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

lsexpression.neg()

Returns a new expression that is the opposite of the current expression.

Return type

lsexpression

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

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

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

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

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

lsexpression.not(other)

Returns a new expression that is the negative of the current expression. NOT(a) = 1 - a.

Return type

lsexpression

lsexpression.and(other)
lsexpression.rand(other)

Returns a new expression that is the logical and 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 (logical and with constant 1 or true) or returns the lsexpression representing the constant 0 (logical and with constant 0 or false).

Parameters

other – Can be a bool or another lsexpression

Return type

lsexpression

lsexpression.or(other)
lsexpression.ror(other)

Returns a new expression that is the logical or 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 (logical or with constant 0 or false) or returns the lsexpression representing the constant 1 (logical or with constant 1 or true).

Parameters

other – Can be a bool or another lsexpression

Return type

lsexpression

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

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

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

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

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

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

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

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

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

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.