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.

LSModel Class

class localsolver.LSModel

Mathematical optimization model. A model is composed of expressions (some of which are decisions), organized as a Directed Acyclic Graph (DAG). Then, some expressions of the model can be constrained or optimized. Once your optimization model is created and closed, the solver can be launched to solve it. Note that you cannot modify a model which has been closed: you must reopen-it (with open()) or instantiate another LocalSolver environment to optimize another model.

Summary

Methods
create_constant Creates a constant expression representing the given value.
create_expression Creates a new expression of the given type with the given operands.
get_nb_expressions Returns the number of expressions added to this model.
get_expression Gets the expression with the given index or the given name in this model.
get_nb_decisions Gets the number of decisions in the model.
get_decision Gets the decision with the given index.
add_constraint Adds the given expression to the list of constraints.
constraint Shortcut for add_constraint().
remove_constraint Removes the given expression from the list of constraints.
get_nb_constraints Gets the number of constraints added to this model.
get_constraint Gets the constraint with the given index.
add_objective Adds the given expression to the list of objectives to optimize.
minimize Shortcut for add_objective(expr, LSObjectiveDirection.MINIMIZE).
maximize Shortcut for add_objective(expr, LSObjectiveDirection.MAXIMIZE).
remove_objective Removes the objective at the given position in the list of objectives.
get_nb_objectives Gets the number of objectives added to this model.
get_objective Gets the objective with the given index.
get_objective_direction Gets the direction of the objective with the given index.
get_nb_operands Gets the number of operands in the model.
close Closes the model.
open Opens or reopens the model.
is_closed Returns true if the model is closed, false otherwise.
bool Creates a boolean decision.
float Creates a float decision.
int Creates an integer decision.
sum Creates a sum expression with the given operands.
sub Creates a sub expression with two operands.
prod Creates a product expression.
max Creates a max expression.
min Creates a min expression.
or_ Creates a boolean or expression.
and_ Creates a boolean and expression.
xor Creates a boolean xor expression.
not_ Creates a boolean not expression.
eq Creates an equality expression.
neq Creates a disequality expression.
geq Creates an inequality ‘greater than or equal to’.
leq Creates an inequality ‘smaller than or equal to’.
gt Creates an inequality ‘strictly greater than’.
lt Creates an inequality ‘strictly smaller than’.
iif Creates a ternary conditional operator.
abs Creates an absolute value expression.
dist Creates a distance expression.
div Creates a division expression.
mod Creates a modulo expression.
array Creates a new array.
at Creates a “at” expression.
scalar Creates a scalar product between two arrays.
ceil Creates a ceil expression.
floor Creates a floor expression.
round Creates a ceil expression.
sqrt Creates a square root expression.
log Creates a log expression.
exp Creates an exponential expression.
pow Creates a power expression.
cos Creates a cosine expression.
sin Creates a sine expression.
tan Creates a tangent expression.
piecewise Creates a piecewise linear expression.
list Creates a list variable.
count Creates a count expression.
index Creates an indexOf expression.
partition Creates a partition expression.
disjoint Creates a disjoint expression.
Attributes
nb_expressions Number of expressions in this model.
nb_operands Number of operands in this model.
nb_objectives Number of objectives in this model.
nb_constraints Number of constraints in this model.
nb_decisions Number of objectives in this model.
expressions List of the expressions of the model.
decisions List of the decisions of the model.
objectives List of the objectives of the model.
objective_directions List of the objective directions of the model.
constraints List of the constraints of the model.
Special methods
__str__ Returns a string representation of this model.

Instance methods

LSModel.create_constant(value)

Creates a constant expression representing the given value. The given value can be a boolean, an integer or a double. Only allowed in state LSState.MODELING. Note that if a constant has been already created with the same value, this method can return the same expression, but it is not guaranteed. The exact behavior is implementation defined.

Parameters:value – Value of the constant (can be a boolean, integer or double).
Returns:Created constant expression
Return type:LSExpression
LSModel.create_expression(operator)
localsolver.create_expression(operator, operands)
localsolver.create_expression(operator, *operands)

Creates a new expression of the given type with the given operands. Only allowed in state LSState.MODELING. This method cannot be used to create constants: use LSModel.create_constant() instead.

The operands parameter accept any object that implements the __iter__ method. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments.

Each operand can be an LSExpression, a boolean, an integer or a double.

Since:

5.5

Parameters:
  • operator (LSOperator) – Type of the expression to create.
  • operands – Operands to add. The object must be iterable.
Returns:

Created expression

Return type:

LSExpression

LSModel.get_nb_expressions()

Returns the number of expressions added to this model.

You can also use the shortcut member nb_expressions

Returns:Number of expressions.
Return type:int
LSModel.get_expression(expr_index)
localsolver.get_expression(expr_name)

Gets the expression with the given index or the given name in this model. Throws an exception if no expression with the given name or the given index exists.

You can also use the shortcut member expressions

Parameters:
  • expr_index (int) – Index of the expression
  • expr_name (str) – Name of the expression.
Returns:

Expression with the given index

Return type:

LSExpression

LSModel.get_nb_decisions()

Gets the number of decisions in the model. This corresponds to the number of decision variables declared in the model.

You can also use the shortcut member nb_decisions

Returns:Number of decisions in the model.
Return type:int
LSModel.get_decision(decision_index)

Gets the decision with the given index.

You can also use the shortcut member decisions

Parameters:decision_index (int) – Index of the decision
Returns:Decision with the given index
Return type:LSExpression
LSModel.add_constraint(expr)

Adds the given expression to the list of constraints. It means that the value of this expression must be constrained to be equal to 1 in any solution found by the solver. Hence, only boolean expressions (that is, expressions whose value is boolean) can be constrained. Only allowed in state LSState.MODELING. If the expression is already a constraint, this method does nothing and returns immediately.

Try to avoid hard constraints as much as possible, because LocalSolver (and more generally local search) is not suited for solving hardly constrained problems. In particular, banish constraints that are not surely satisfied in practice. Ideally, only combinatorial constraints (which induce the combinatorial structure of your problem) have to be set. All the other constraints can be relaxed as primary objectives in order to be “softly” satisfied (goal programming). For instance, constraint a <= b can be transformed into minimize max(b-a, 0).

Parameters:expr (LSExpression) – Expression
LSModel.constraint(expr)

Shortcut for add_constraint(). You can also use the shortcut member constraints

Parameters:expr (LSExpression) – Expression
Since:5.5
LSModel.remove_constraint(expr)
localsolver.remove_constraint(constraint_index)

Removes the given expression from the list of constraints. If the expression was not constrained, this method does nothing and returns immediately. Only allowed in state LSState.MODELING.

Parameters:
  • expr (LSExpression) – Expression.
  • constraint_index (int) – Index of the constraint to remove.
Since:

5.0

LSModel.get_nb_constraints()

Gets the number of constraints added to this model.

You can also use the shortcut member nb_constraints

Returns:Number of constraints
Return type:int
LSModel.get_constraint(index)

Gets the constraint with the given index.

Parameters:index (int) – Index of the constraint
Returns:Constraint with the given index.
Return type:LSExpression
LSModel.add_objective(expr, direction)

Adds the given expression to the list of objectives to optimize. A same expression can be added more than once. Only allowed in state LSState.MODELING. Note that the objectives will be optimized in the order in which they have been added to the model. It is useful for lexicographic multiobjective optimization, and more particularly for goal programming.

Parameters:
LSModel.minimize(expr)

Shortcut for add_objective(expr, LSObjectiveDirection.MINIMIZE).

Parameters:expr (LSExpression) – Expression
LSModel.maximize(expr)

Shortcut for add_objective(expr, LSObjectiveDirection.MAXIMIZE).

Parameters:expr (LSExpression) – Expression
LSModel.remove_objective(obj_index)

Removes the objective at the given position in the list of objectives. Note that the objectives created after the removed one have their index decreased by 1. Phases are not modified when an objective is removed. It is the user’s responsibility to change the objective index of each phase to keep it coherent (with LSPhase.set_optimized_objective() or to disable it (with LSPhase.enabled). Only allowed in state LSState.MODELING.

Parameters:obj_index (int) – Position of the objective to remove.
Since:5.0
LSModel.get_nb_objectives()

Gets the number of objectives added to this model.

You can also use the shortcut member nb_objectives

Returns:Number of objectives
Return type:int
LSModel.get_objective(obj_index)

Gets the objective with the given index.

You can also use the shortcut member objectives

Parameters:obj_index (int) – Index of the objective
Returns:Objective with the given index
Return type:LSExpression
LSModel.get_objective_direction(obj_index)

Gets the direction of the objective with the given index.

You can also use the shortcut member objective_directions

Parameters:obj_index (int) – Index of the objective
Returns:Objective direction
Return type:LSObjectiveDirection
LSModel.get_nb_operands()

Gets the number of operands in the model. This corresponds to the number of operands for all expressions declared in the model. It is an analog of the number of non zeros in matrix model encountered in mathematical programming: it gives an hint about the size and the density of your model.

You can also use the shortcut member nb_operands

Returns:Number of operands.
Return type:int
LSModel.close()

Closes the model. Only allowed in state LSState.MODELING. Once the model is closed, no expression, constraints or objectives can be added. The model must be closed before starting its resolution. When the model is closed, the state of the LocalSolver changed from LSState.MODELING to LSState.STOPPED.

LSModel.open()

Opens or reopens the model. When this method is called, the solver is placed in state LSState.MODELING. Only allowed in state LSState.STOPPED.

LSModel.is_closed()

Returns true if the model is closed, false otherwise.

Returns:True if the model is closed.
Return type:Boolean
LSModel.bool()

Creates a boolean decision. Binary decision variable with domain [0.1].

Since:5.5
Returns:Expression of type LSOperator.BOOL
Return type:LSExpression
LSModel.float(min, max)

Creates a float decision. Decision variable with domain [min,max]. Bounds of the variable must be booleans, integers or doubles.

Since:5.5
Returns:Expression of type LSOperator.FLOAT
Return type:LSExpression
LSModel.int(min, max)

Creates an integer decision. Decision variable with domain [min,max]. Bounds of the variable must be booleans or integers.

Since:5.5
Returns:Expression of type LSOperator.INT
Return type:LSExpression
LSModel.sum(operands)
LSModel.sum(*operands)

Creates a sum expression with the given operands. Any object that implements the __iter__ method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments.

Each operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:operands – Operands to add. The object must be iterable.
Returns:Expression of type LSOperator.SUM
Return type:LSExpression
LSModel.sub(op1, op2)

Creates a sub expression with two operands. Accepted operands are: LSExpressions, booleans, integers or doubles.

Each operand can be an LSExpression, a boolean, an integer or a double.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression, boolean, integer or double.
  • op2 – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:

Expression of type LSOperator.SUB

Return type:

LSExpression

LSModel.prod(operands)
LSModel.prod(*operands)

Creates a product expression. Any object that implements the __iter__ method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments.

Each operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:operands – Operands to add. The object must be iterable.
Returns:Expression of type LSOperator.PROD
Return type:LSExpression
LSModel.max(operands)
LSModel.max(*operands)

Creates a max expression. Any object that implements the __iter__ method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments.

Each operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:operands – Operands to add. The object must be iterable.
Returns:Expression of type LSOperator.MAX
Return type:LSExpression
LSModel.min(operands)
LSModel.min(*operands)

Creates a min expression. Any object that implements the __iter__ method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments.

Each operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:operands – Operands to add. The object must be iterable.
Returns:Expression of type LSOperator.MIN
Return type:LSExpression
LSModel.or_(operands)
LSModel.or_(*operands)

Creates a boolean or expression. Any object that implements the __iter__ method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments.

Each operand can be an LSExpression or a boolean.

Since:5.5
Parameters:operands – Operands to add. The object must be iterable.
Returns:Expression of type LSOperator.OR
Return type:LSExpression
LSModel.and_(operands)
LSModel.and_(*operands)

Creates a boolean and expression. Any object that implements the __iter__ method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments.

Each operand can be an LSExpression or a boolean.

Since:5.5
Parameters:operands – Operands to add. The object must be iterable.
Returns:Expression of type LSOperator.AND
Return type:LSExpression
LSModel.xor(operands)
LSModel.xor(*operands)

Creates a boolean xor expression. Any object that implements the __iter__ method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments.

Each operand can be an LSExpression or a boolean.

Since:5.5
Parameters:operands – Operands to add. The object must be iterable.
Returns:Expression of type LSOperator.XOR
Return type:LSExpression
LSModel.not_(op)

Creates a boolean not expression. The operand can be an LSExpression or a boolean.

Since:5.5
Parameters:op – Operand. Accepted types: LSExpression or boolean.
Returns:Expression of type LSOperator.NOT
Return type:LSExpression
LSModel.eq(op1, op2)

Creates an equality expression. Accepted operands are: LSExpressions, booleans, integers or doubles.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression, boolean, integer or double.
  • op2 – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:

Expression of type LSOperator.EQ

Return type:

LSExpression

LSModel.neq(op1, op2)

Creates a disequality expression. Accepted operands are: LSExpressions, booleans, integers or doubles.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression, boolean, integer or double.
  • op2 – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:

Expression of type LSOperator.NEQ

Return type:

LSExpression

LSModel.geq(op1, op2)

Creates an inequality ‘greater than or equal to’. Accepted operands are: LSExpressions, booleans, integers or doubles.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression, boolean, integer or double.
  • op2 – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:

Expression of type LSOperator.GEQ

Return type:

LSExpression

LSModel.leq(op1, op2)

Creates an inequality ‘smaller than or equal to’. Accepted operands are: LSExpressions, booleans, integers or doubles.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression, boolean, integer or double.
  • op2 – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:

Expression of type LSOperator.LEQ

Return type:

LSExpression

LSModel.gt(op1, op2)

Creates an inequality ‘strictly greater than’. Accepted operands are: LSExpressions, booleans, integers or doubles.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression, boolean, integer or double.
  • op2 – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:

Expression of type LSOperator.GT

Return type:

LSExpression

LSModel.lt(op1, op2)

Creates an inequality ‘strictly smaller than’. Accepted operands are: LSExpressions, booleans, integers or doubles.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression, boolean, integer or double.
  • op2 – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:

Expression of type LSOperator.LT

Return type:

LSExpression

LSModel.iif(op1, op2, op3)

Creates a ternary conditional operator. The first operand must be an LSExpression with a boolean value or a boolean. The other operands can be LSExpressions, booleans, integers or doubles.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression with boolean value or boolean.
  • op2 – Operand. Accepted types: LSExpression, boolean, integer or double.
  • op3 – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:

Expression of type LSOperator.IF

Return type:

LSExpression

LSModel.abs(op)

Creates an absolute value expression. The operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:op – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:Expression of type LSOperator.ABS
Return type:LSExpression
LSModel.dist(op1, op2)

Creates a distance expression. Accepted operands are: LSExpressions, booleans, integers or doubles.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression, boolean, integer or double.
  • op2 – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:

Expression of type LSOperator.DIST

Return type:

LSExpression

LSModel.div(op1, op2)

Creates a division expression. Accepted operands are: LSExpressions, booleans, integers or doubles.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression, boolean, integer or double.
  • op2 – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:

Expression of type LSOperator.DIV

Return type:

LSExpression

LSModel.mod(op1, op2)

Creates a modulo expression. Accepted operands are: LSExpressions with integer values, booleans, integers.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression with integer value, boolean or integer.
  • op2 – Operand. Accepted types: LSExpression with integer value, boolean or integer.
Returns:

Expression of type LSOperator.MOD

Return type:

LSExpression

LSModel.array(operands)
LSModel.array(*operands)

Creates a new array. Any object that implements the __iter__ method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments.

Each operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:operands – Operands to add. The object must be iterable.
Returns:Expression of type LSOperator.ARRAY
Return type:LSExpression
LSModel.at(array_expr, indices_expr)
LSModel.at(array_expr, *indices_expr)

Creates a “at” expression. The first operand must be an LSExpression with array or collection value. The second operand can be any object that implements the __iter__ method. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It must have at least one element.

Since:

5.5

Parameters:
  • array_expr – Operand. Accepted types: LSExpression with array or collection value.
  • indices_expr – Operands for the indices. The object must be iterable.
Returns:

Expression of type LSOperator.AT

Return type:

LSExpression

LSModel.scalar(op1, op2)

Creates a scalar product between two arrays. The operands must be LSExpressions of type LSOperator.ARRAY.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression with array value.
  • op2 – Operand. Accepted types: LSExpression with array value.
Returns:

Expression of type LSOperator.SCALAR

Return type:

LSExpression

LSModel.ceil(op)

Creates a ceil expression. The operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:op – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:Expression of type LSOperator.CEIL
Return type:LSExpression
LSModel.floor(op)

Creates a floor expression. The operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:op – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:Expression of type LSOperator.FLOOR
Return type:LSExpression
LSModel.round(op)

Creates a ceil expression. The operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:op – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:Expression of type LSOperator.ROUND
Return type:LSExpression
LSModel.sqrt(op)

Creates a square root expression. The operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:op – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:Expression of type LSOperator.SQRT
Return type:LSExpression
LSModel.log(op)

Creates a log expression. The operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:op – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:Expression of type LSOperator.LOG
Return type:LSExpression
LSModel.exp(op)

Creates an exponential expression. The operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:op – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:Expression of type LSOperator.EXP
Return type:LSExpression
LSModel.pow(op1, op2)

Creates a power expression. Accepted operands are: LSExpressions, booleans, integers or doubles.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression, boolean, integer or double.
  • op2 – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:

Expression of type LSOperator.POW

Return type:

LSExpression

LSModel.cos(op)

Creates a cosine expression. The operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:op – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:Expression of type LSOperator.COS
Return type:LSExpression
LSModel.sin(op)

Creates a sine expression. The operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:op – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:Expression of type LSOperator.SIN
Return type:LSExpression
LSModel.tan(op)

Creates a tangent expression. The operand can be an LSExpression, a boolean, an integer or a double.

Since:5.5
Parameters:op – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:Expression of type LSOperator.TAN
Return type:LSExpression
LSModel.piecewise(op1, op2, op3)

Creates a piecewise linear expression. The first and the second operands must be LSExpressions of type LSOperator.ARRAY. The third argument must be an LSExpression, a boolean, an integer or a double.

Since:

5.5

Parameters:
  • op1 – Operand. Accepted types: LSExpression of type LSOperator.ARRAY
  • op2 – Operand. Accepted types: LSExpression of type LSOperator.ARRAY
  • op3 – Operand. Accepted types: LSExpression, boolean, integer or double.
Returns:

Expression of type LSOperator.PIECEWISE

Return type:

LSExpression

LSModel.list(op)

Creates a list variable. The operand must be a boolean or an integer.

Since:5.5
Parameters:op – Operand. Accepted types: boolean or integer.
LSModel.count(op)

Creates a count expression. The operand must be an LSExpression of type collection.

Since:5.5
Parameters:op – Operand. Accepted type: LSExpression with collection value.
Returns:Expression of type LSOperator.COUNT
Return type:LSExpression
LSModel.index(op)

Creates an indexOf expression. The operand must be an LSExpression of type collection.

Since:5.5
Parameters:op – Operand. Accepted type: LSExpression with collection value.
Returns:Expression of type LSOperator.INDEX
Return type:LSExpression
LSModel.count(op)

Creates a count expression. The operand must be an LSExpression of type collection.

Since:5.5
Parameters:op – Operand. Accepted type: LSExpression with collection value.
Returns:Expression of type LSOperator.COUNT
Return type:LSExpression
LSModel.partition(operands)
LSModel.partition(*operands)

Creates a partition expression. Any object that implements the __iter__ method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments.

Each operand must be an LSExpression with collection.

Since:5.5
Parameters:operands – Operands to add. The object must be iterable.
Returns:Expression of type LSOperator.PARTITION
Return type:LSExpression
LSModel.disjoint(operands)
LSModel.disjoint(*operands)

Creates a disjoint expression. Any object that implements the __iter__ method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments.

Each operand must be an LSExpression with collection.

Since:5.5
Parameters:operands – Operands to add. The object must be iterable.
Returns:Expression of type LSOperator.DISJOINT
Return type:LSExpression

Instance attributes

All get/set methods have their attribute counterpart. You can use them as shortcuts to improve the readability or your models and codes.

LSModel.nb_expressions

Number of expressions in this model. This attribute is read-only. It is a shortcut for get_nb_expressions().

LSModel.nb_operands

Number of operands in this model. This attribute is read-only. It is a shortcut for get_nb_operands().

LSModel.nb_objectives

Number of objectives in this model. This attribute is read-only. It is a shortcut for get_nb_objectives().

LSModel.nb_constraints

Number of constraints in this model. This attribute is read-only. It is a shortcut for get_nb_constraints().

LSModel.nb_decisions

Number of objectives in this model. This attribute is read-only. It is a shortcut for get_nb_decisions().

LSModel.expressions

List of the expressions of the model. This attribute is read-only. The returned object is iterable, supports the len function and can be indexed with integers. It is a shortcut for get_expression() and get_nb_expressions() methods.

LSModel.decisions

List of the decisions of the model. This attribute is read-only. The returned object is iterable, supports the len function and can be indexed with integers. It is a shortcut for get_decision() and get_nb_decisions() methods.

LSModel.objectives

List of the objectives of the model. This attribute is read-only. The returned object is iterable, supports the len function and can be indexed with integers. It is a shortcut for get_objective() and get_nb_objectives() methods.

LSModel.objective_directions

List of the objective directions of the model. This attribute is read-only. The returned object is iterable, supports the len function and can be indexed with integers. It is a shortcut for get_objective_direction() and get_nb_objectives() methods.

LSModel.constraints

List of the constraints of the model. This attribute is read-only. The returned object is iterable, supports the len function and can be indexed with integers. It is a shortcut for get_constraint() and get_nb_constraints() methods.

Special operators and methods

LSModel.__str__()

Returns a string representation of this model. This representation provides:

  • The number of expressions, decisions, constraints, and objectives.
  • The density of the model.

Useful for debugging or logging purposes.

Returns:String representation of this model.
Return type:str