LSSolution Class¶
- class localsolver.LSSolution¶
Solution to the optimization model. A solution carries the values of all expressions in the model. It is used to retrieve the values of all expressions (getting the solution), or to set the values of some decisions (setting the solution).
Summary¶
Status of the solution. |
Sets the value of the given expression in this solution. |
|
Returns the value of the given expression in this solution. |
|
Returns true if the given expression is violated in this solution. |
|
Returns true if the given expression has an undefined value in this solution. |
|
Returns the status of the solution. |
|
Returns the bound computed by the solver for the given objective. |
|
Returns the gap computed by the solver for the given objective. |
|
Clear the solution and set all decisions to zero. |
Instance methods¶
- LSSolution.set_value(expr, value)¶
Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in state
LSState.STOPPED
. The value must be a double, integer, boolean orLSInterval
. If the solver was not launched, this value will be used as an initial value for the decision.- Parameters
expr (LSExpression) – Decision
value – Value assigned to the decision in this solution.
- LSSolution.get_value(expr)¶
Returns the value of the given expression in this solution. Only allowed in states
LSState.PAUSED
orLSState.STOPPED
. The type of the returned value depends on the type of the LSExpression. It can be a boolean, an integer, a double, aLSInterval
, aLSCollection
or aLSArray
.- Parameters
expr (LSExpression) – Expression
- Returns
Value of the expression in this solution.
- Return type
bool
,int
,double
,LSInterval
,LSCollection
orLSArray
- LSSolution.is_violated(expr)¶
Returns true if the given expression is violated in this solution.
An expression can be violated in 2 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
LSState.PAUSED
orLSState.STOPPED
.- Returns
True if this expression is violated in this solution.
- Return type
bool
- LSSolution.is_undefined(expr)¶
Returns true if the given expression has an undefined value in this solution.
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
LSState.PAUSED
orLSState.STOPPED
.- Returns
True if this expression has an undefined value in this solution.
- Return type
bool
- Since
7.0
- LSSolution.get_status()¶
Returns the status of the solution. Only allowed in states
LSState.PAUSED
orLSState.STOPPED
.You can also use the shortcut member
status
- Returns
Status of the solution.
- Return type
- LSSolution.get_objective_bound(obj_index)¶
Returns the bound computed by the solver for the given objective. If the solver has never been launched, this method returns a large integer number or math.inf. Only allowed in states
LSState.PAUSED
orLSState.STOPPED
.- Parameters
obj_index (
int
) – Index of the objective- Returns
The bound of the objective
- Return type
int
ordouble
- LSSolution.get_objective_gap(obj_index)¶
Returns the gap computed by the solver for the given objective. It is defined as:
\[|obj - bound| / \max(1, |obj|, |bound|)\]Only allowed in states
LSState.PAUSED
orLSState.STOPPED
.- Parameters
obj_index (
int
) – Index of the objective- Returns
The gap of the objective
- Return type
double
- LSSolution.clear()¶
Clear the solution and set all decisions to zero. Only allowed in state
LSState.STOPPED
.
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.
- LSSolution.status¶
Status of the solution. This attribute is read-only. It is a shortcut for
get_status()
.