HxSolution Class

class 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

Methods

getValue

Returns the value of the given expression in this solution.

setValue

Sets the value of the given expression in this solution.

clear

Clear the solution and set all decisions to zero.

Fields

HxSolution.status

Status of the solution. Only allowed in states PAUSED or STOPPED. The returned value can be one of the following strings:

  • INCONSISTENT: Solution and model are inconsistent. The solver was able to prove that the model admits no feasible solution. Note that even a model without any constraint can be inconsistent, because some computations can yield undefined results. For instance, computing, SQRT(x) with negative x yields an undefined value, which causes the solution to be invalid if it is used in an objective or a constraint (directly or indirectly).

  • INFEASIBLE: Solution is infeasible (some constraints are violated).

  • FEASIBLE: Solution is feasible but optimality was not proven.

  • OPTIMAL: Solution is optimal (all objective bounds are reached).

Return type:

a string among INCONSISTENT, INFEASIBLE, FEASIBLE or OPTIMAL.

HxSolution.objectiveBounds

Bounds computed by the solver for all objectives. This field returns a readonly map-like structure with the following features:

  • A count field e.g. objectiveBounds.count(). This count field is always equal to the number of objectives present in the model.

  • An overloaded index [] operator to get a bound for a specific objective, e.g. objectiveBounds[0]. The index must be between 0 and objectiveBounds.count() - 1. Accessing a value outside these bounds throws an exception.

  • An overloaded iterator operator to iterate over the objective bounds with a for statement.

If the solver has never been launched or if no bound was found for a particular objective, an infinite or a very large number is returned.

Only allowed in states PAUSED or STOPPED.

Return type:

map-like structure containing numbers (integers or doubles).

HxSolution.objectiveGaps

Gaps computed by the solver for all objectives. This field returns a readonly map-like structure with the following features:

  • A count field e.g. objectiveGaps.count(). This count field is always equal to the number of objectives present in the model.

  • An overloaded index [] operator to get a bound for a specific objective, e.g. objectiveGaps[0]. The index must be between 0 and objectiveGaps.count() - 1. Accessing a value outside these bounds throws an exception.

  • An overloaded iterator operator to iterate over the objective gaps with a for statement.

The gap is defined as:

\[|obj - bound| / \max(1, |obj|, |bound|)\]

Only allowed in states PAUSED or STOPPED.

Return type:

map-like structure containing doubles.

Methods

HxSolution.getValue(expression)

Returns the value of the given expression in this solution. 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.

Only allowed in states PAUSED or STOPPED.

Parameters:

expression – Expression for which you want the value

Return type:

a number, an array or a collection depending on the type of the expression.

HxSolution.setValue(expression, value)

Sets the value of the given expression in this solution. Only decisions can be set. The value must be an integer or a double depending on the type of the decision to set. If you want to modify the decisions of type collection (set or list), you should directly modify the collection returned by the method getValue().

If the solver was not launched, this value will be used as an initial value for the decision. Only allowed in state STOPPED.

Parameters:
  • expr – Decision.

  • value – Value assigned to the decision in this solution.

HxSolution.clear()

Clear the solution and set all decisions to zero. Only allowed in state STOPPED.