LSModel Class¶
- class LSModel¶
Mathematical optimization model. A model is composed of expressions (some of which are decisions), organized as a tree. 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 resolve 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.- See:
Summary¶
Returns true if the model is closed, false otherwise. |
|
Closes the model. |
|
Reopens the model. |
Fields¶
- LSModel.expressions¶
This field returns a readonly map-like structure containing all expressions added to this model. The returned structure has the following features:
A count field to get the number of expressions, e.g.
expressions.count()
.An overloaded index
[]
operator to get a specific expression, e.g.expressions[0]
. The index must be between0
andexpressions.count() - 1
. Accessing a value outside these bounds throws an exception.An overloaded
iterator
operator to iterate over the expressions with afor
statement.
- Return type:
map-like structure containing objects of type
LSExpression
.
- LSModel.decisions¶
This field returns a readonly map-like structure containing all decisions added to this model. The returned structure has the following features:
A count field to get the number of decisions, e.g.
decisions.count()
.An overloaded index
[]
operator to get a specific decision, e.g.decisions[0]
. The index must be between0
anddecisions.count() - 1
. Accessing a value outside these bounds throws an exception.An overloaded
iterator
operator to iterate over the decisions with afor
statement.
- Return type:
map-like structure containing objects of type
LSExpression
.
- LSModel.constraints¶
This field returns a readonly map-like structure containing all constraints added to this model. The returned structure has the following features:
A count field to get the number of constraints, e.g.
constraints.count()
.An overloaded index
[]
operator to get a specific constraint, e.g.constraints[0]
. The index must be between0
andconstraints.count() - 1
. Accessing a value outside these bounds throws an exception.An overloaded
iterator
operator to iterate over the constraints with afor
statement.
- Return type:
map-like structure containing objects of type
LSExpression
.
- LSModel.objectives¶
This field returns a readonly map-like structure containing all objectives added to this model. The returned structure has the following features:
A count field to get the number of objectives, e.g.
objectives.count()
.An overloaded index
[]
operator to get a specific objective, e.g.objectives[0]
. The index must be between0
andobjectives.count() - 1
. Accessing a value outside these bounds throws an exception.An overloaded
iterator
operator to iterate over the objectives with afor
statement.
- Return type:
map-like structure containing objects of type
LSExpression
.
- LSModel.objectiveDirections¶
This field returns a readonly map-like structure containing the directions of the objectives expressed as strings (
MINIMIZE
orMAXIMIZE
). The returned structure has the following features:A count field to get the number of objectives, e.g.
objectiveDirections.count()
.An overloaded index
[]
operator to get a specific objective direction, e.g.objectiveDirections[0]
. The index must be between0
andobjectiveDirections.count() - 1
. Accessing a value outside these bounds throws an exception.An overloaded
iterator
operator to iterate over the objective directions with afor
statement.
- Return type:
map-like structure containing strings
MINIMIZE
orMAXIMIZE
.
- LSModel.nbExpressions¶
Number of expressions added to this model so far.
- LSModel.nbDecisions¶
Number of decisions added to this model so far.
- LSModel.nbConstraints¶
Number of constraints added to this model so far.
- LSModel.nbObjectives¶
Number of objectives added to this model so far.
- LSModel.nbOperands¶
Number of operands added to this model so far. 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.
Methods¶
- LSModel.isClosed()¶
Returns true if the model is closed, false otherwise.
- Return type:
bool
- LSModel.close()¶
Closes the model. Only allowed in state
MODELING
. When this method is called, the solver is placed in stateSTOPPED
.Once the model is closed, no expressions, constraints or objectives can be added or removed unless the model is reopened. The model must be closed before starting its resolution.
- See:
- LSModel.open()¶
Reopens the model. Only allowed in state
STOPPED
. When this method is called, the solver is placed in stateMODELING
.In this state, the model can be modified: it is possible to add new expressions, constraints or objectives, modify expression operands, and remove existing constraints and objectives. However, existing expressions cannot be deleted.
- See: