HxSolution Class¶
-
class
hexaly.optimizer.HxSolution¶ 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 |
Status of the solution. |
set_value |
Sets the value of the given expression in this solution. |
set_int_value |
Sets the value of the given expression in this solution. |
set_double_value |
Sets the value of the given expression in this solution. |
set_interval_value |
Sets the value of the given expression in this solution. |
get_value |
Returns the value of the given expression in this solution. |
get_int_value |
Returns the integer value of the given expression in this solution. |
get_double_value |
Returns the double value of the given expression in this solution. |
get_interval_value |
Returns the interval value of the given expression in this solution. |
get_collection_value |
Returns the collection value of the given expression in this solution. |
get_array_value |
Returns the array value of the given expression in this solution. |
is_violated |
Returns true if the given expression is violated in this solution. |
is_undefined |
Returns true if the given expression has an undefined value in this solution. |
get_status |
Returns the status of the solution. |
get_objective_bound |
Returns the bound computed by the solver for the given objective. |
get_int_objective_bound |
Returns the integer bound computed by the solver for the given objective. |
get_double_objective_bound |
Returns the double bound computed by the solver for the given objective. |
get_objective_gap |
Returns the gap computed by the solver for the given objective. |
clear |
Clear the solution and set all decisions to zero. |
Instance methods¶
-
HxSolution.set_value(expr, value)¶ Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in state
HxState.STOPPED. The value must be a double, integer, boolean orHxInterval. If the solver was not launched, this value will be used as an initial value for the decision.Parameters: - expr (HxExpression) – Decision
- value (
int,doubleorHxInterval) – Value assigned to the decision in this solution.
-
HxSolution.set_int_value(expr, value)¶ Sets the value of the given expression in this solution. This method has the same effect as
set_value(), but it can only be used if the expression is a boolean or an integer. If not, an exception is thrown.Parameters: - expr (HxExpression) – Integer or boolean decision
- value (int) – Value assigned to the decision in this solution.
Since: 15.0
-
HxSolution.set_double_value(expr, value)¶ Sets the value of the given expression in this solution. This method has the same effect as
set_value(), but it can only be used if the expression is a double. If not, an exception is thrown.Parameters: - expr (HxExpression) – Double decision
- value (double) – Value assigned to the decision in this solution.
Since: 15.0
-
HxSolution.set_interval_value(expr, value)¶ Sets the value of the given expression in this solution. This method has the same effect as
set_value(), but it can only be used if the expression is an interval. If not, an exception is thrown.Parameters: - expr (HxExpression) – Interval decision
- value (HxInterval) – Value assigned to the decision in this solution.
Since: 15.0
-
HxSolution.get_value(expr)¶ Returns the value of the given expression in this solution. Only allowed in states
HxState.PAUSEDorHxState.STOPPED. The type of the returned value depends on the type of the HxExpression. It can be a boolean, an integer, a double, aHxInterval, aHxCollectionor aHxArray.Parameters: expr (HxExpression) – Expression Returns: Value of the expression in this solution. Return type: int,double,HxInterval,HxCollectionorHxArray
-
HxSolution.get_int_value(expr)¶ Returns the integer value of the given expression in this solution. This method has the same effect as
get_value()but it also ensures that the expression is of type int or bool. If not, an exception is thrown.Parameters: expr (HxExpression) – Expression Returns: Value of the expression in this solution. Return type: intSince: 15.0
-
HxSolution.get_double_value(expr)¶ Returns the double value of the given expression in this solution. This method has the same effect as
get_value()but it also ensures that the expression is of type double. If not, an exception is thrown.Parameters: expr (HxExpression) – Expression Returns: Value of the expression in this solution. Return type: doubleSince: 15.0
-
HxSolution.get_interval_value(expr)¶ Returns the interval value of the given expression in this solution. This method has the same effect as
get_value()but it also ensures that the expression is an interval or a range. If not, an exception is thrown.Parameters: expr (HxExpression) – Expression Returns: Value of the expression in this solution. Return type: HxIntervalSince: 15.0
-
HxSolution.get_collection_value(expr)¶ Returns the collection value of the given expression in this solution. This method has the same effect as
get_value()but it also ensures that the expression is a collection. If not, an exception is thrown.Parameters: expr (HxExpression) – Expression Returns: Value of the expression in this solution. Return type: HxCollectionSince: 15.0
-
HxSolution.get_array_value(expr)¶ Returns the array value of the given expression in this solution. This method has the same effect as
get_value()but it also ensures that the expression is an array. If not, an exception is thrown.Parameters: expr (HxExpression) – Expression Returns: Value of the expression in this solution. Return type: HxArraySince: 15.0
-
HxSolution.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
HxState.PAUSEDorHxState.STOPPED.Returns: True if this expression is violated in this solution. Return type: bool
-
HxSolution.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
HxState.PAUSEDorHxState.STOPPED.Returns: True if this expression has an undefined value in this solution. Return type: boolSince: 7.0
-
HxSolution.get_status()¶ Returns the status of the solution. Only allowed in states
HxState.PAUSEDorHxState.STOPPED.You can also use the shortcut member
statusReturns: Status of the solution. Return type: HxSolutionStatus
-
HxSolution.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
HxState.PAUSEDorHxState.STOPPED.Parameters: obj_index (int) – Index of the objective Returns: The bound of the objective Return type: intordouble
-
HxSolution.get_int_objective_bound(obj_index)¶ Returns the integer bound computed by the solver for the given objective. This method has the same effect as
get_objective_bound()but it also ensures that the corresponding objective is a boolean or integer expression. If not, an exception is thrown.Parameters: obj_index (int) – Index of the objective Returns: The bound of the objective Return type: int
-
HxSolution.get_double_objective_bound(obj_index)¶ Returns the double bound computed by the solver for the given objective. This method has the same effect as
get_objective_bound()but it also ensures that the corresponding objective is a double expression. If not, an exception is thrown.Parameters: obj_index (int) – Index of the objective Returns: The bound of the objective Return type: double
-
HxSolution.get_objective_gap(obj_index)¶ Returns the gap computed by the solver for the given objective. The gap for feasible solutions is defined as:
Infeasible solutions have an infinite gap.
Only allowed in states
HxState.PAUSEDorHxState.STOPPED.Parameters: obj_index (int) – Index of the objective Returns: The gap of the objective Return type: double
-
HxSolution.clear()¶ Clear the solution and set all decisions to zero. Only allowed in state
HxState.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.
-
HxSolution.status¶ Status of the solution. This attribute is read-only. It is a shortcut for
get_status().