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).

See:

HxSolutionStatus

Summary

Functions

setValue

Sets the value of the given expression in this solution.

setValue

Sets the value of the given expression in this solution.

setValue

Sets the value of the given expression in this solution.

setIntValue

Sets the value of the given expression in this solution.

setDoubleValue

Sets the value of the given expression in this solution.

setIntervalValue

Sets the value of the given expression in this solution.

getValue

Returns the value of the given expression in this solution.

getDoubleValue

Returns the value of the given expression in this solution.

getIntervalValue

Returns the value of the given expression in this solution.

isViolated

Returns true if the given expression is violated in this solution.

isUndefined

Returns true if the given expression has an undefined value in this solution.

getIntValue

Returns the value of the given expression in this solution.

getCollectionValue

Returns the value of the given expression in this solution.

getArrayValue

Returns the value of the given expression in this solution.

getStatus

Returns the status of the solution.

getObjectiveBound

Returns the bound computed by the optimizer for the given objective.

getIntObjectiveBound

Returns the bound computed by the optimizer for the given objective.

getDoubleObjectiveBound

Returns the bound computed by the optimizer for the given objective.

getObjectiveGap

Returns the gap computed by the optimizer for the given objective.

clear

Clear the solution and set all decisions to zero.

Functions

void HxSolution::setValue(const HxExpression &expr, hxint value)

Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in state S_Stopped. Only allowed if this expression is an integer or a boolean. If the optimizer was not launched, this value will be used as an initial value for the decision. This method has the same behavior as HxSolution::setIntValue().

Parameters:
  • expr – Decision.

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

See:

HxExpression::isDecision()

See:

HxExpression::isInt()

See:

HxExpression::isBool()

void HxSolution::setValue(const HxExpression &expr, hxdouble value)

Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in state S_Stopped. Only allowed if this expression is a double. If the optimizer was not launched, this value will be used as an initial value for the decision. This method has the same behavior as HxSolution::setDoubleValue().

Parameters:
  • expr – Decision.

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

See:

HxExpression::isDecision()

See:

HxExpression::isDouble()

void HxSolution::setValue(const HxExpression &expr, HxInterval value)

Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in state S_Stopped. Only allowed if this expression is an interval. If the optimizer was not launched, this value will be used as an initial value for the decision. This method has the same behavior as HxSolution::setIntervalValue().

Parameters:
  • expr – Decision.

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

See:

HxExpression::isDecision()

See:

HxExpression::isInterval()

void HxSolution::setIntValue(const HxExpression &expr, hxint value)

Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in state S_Stopped. Only allowed if this expression is an integer or a boolean. If the optimizer was not launched, this value will be used as an initial value for the decision.

Parameters:
  • expr – Decision.

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

See:

HxExpression::isDecision()

See:

HxExpression::isInt()

Since:

3.0

void HxSolution::setDoubleValue(const HxExpression &expr, hxdouble value)

Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in state S_Stopped. If the optimizer was not launched, this value will be used as an initial value for the decision. Only allowed if this expression is a double.

Parameters:
  • expr – Decision.

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

See:

HxExpression::isDecision()

See:

HxExpression::isDouble()

Since:

3.0

void HxSolution::setIntervalValue(const HxExpression &expr, HxInterval value)

Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in state S_Stopped. If the optimizer was not launched, this value will be used as an initial value for the decision. Only allowed if this expression is an interval.

Parameters:
  • expr – Decision.

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

See:

HxExpression::isDecision()

See:

HxExpression::isInterval()

Since:

12.0

hxint HxSolution::getValue(const HxExpression &expr)

Returns the value of the given expression in this solution. Only allowed in states S_Paused or S_Stopped. Only allowed if this expression is an integer or a boolean. This method has the same behavior as HxSolution::getIntValue().

Parameters:

expr – Expression.

See:

HxExpression::isInt()

See:

HxExpression::isBool()

Returns:

Value of the expression in this solution.

hxdouble HxSolution::getDoubleValue(const HxExpression &expr)

Returns the value of the given expression in this solution. Only allowed in states S_Paused or S_Stopped. Only allowed if this expression is a double.

Parameters:

expr – Expression.

See:

HxExpression::isDouble()

Returns:

Value of the expression in this solution.

Since:

3.0

HxInterval HxSolution::getIntervalValue(const HxExpression &expr)

Returns the value of the given expression in this solution. Only allowed in states S_Paused or S_Stopped. Only allowed if this expression is an interval.

Parameters:

expr – Expression.

See:

HxExpression::isInterval()

Returns:

Value of the expression in this solution.

Since:

12.0

bool HxSolution::isViolated(const HxExpression &expr)

Returns true if the given expression is violated in this solution. An expression can be violated in 3 cases:

  1. it is a constraint and its value is 0

  2. it is a double objective and its value is NaN (Not a Number)

  3. it is an integer or boolean with no valid value (arithmetic or out of bounds exception or NaN operands).

Note that only constraints and objectives can be violated. Other expression can have undefined value provided that it does not impact a constraint or objective.

Only allowed in states S_Paused or S_Stopped.

Parameters:

expr – Expression.

Returns:

True if this expression is violated in this solution.

Since:

5.5

See:

HxSolution::isUndefined()

bool HxSolution::isUndefined(const HxExpression &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 S_Paused or S_Stopped.

Parameters:

expr – Expression.

Returns:

True if this expression has an undefined value in this solution.

Since:

7.0

hxint HxSolution::getIntValue(const HxExpression &expr)

Returns the value of the given expression in this solution. Only allowed in states S_Paused or S_Stopped. Only allowed if this expression is an integer or a boolean.

Parameters:

expr – Expression.

See:

HxExpression::isInt()

See:

HxExpression::isBool()

Returns:

Value of the expression in this solution.

Since:

3.0

HxCollection HxSolution::getCollectionValue(const HxExpression &expr)

Returns the value of the given expression in this solution. Only allowed in states S_Paused or S_Stopped. Only allowed if this expression is a collection (list or set).

Parameters:

expr – Expression.

See:

HxExpression::isCollection()

Returns:

Value of the expression in this solution.

Since:

5.5

HxArray HxSolution::getArrayValue(const HxExpression &expr)

Returns the value of the given expression in this solution. Only allowed in states S_Paused or S_Stopped. Only allowed if this expression is an array.

Parameters:

expr – Expression.

See:

HxExpression::isArray()

Returns:

Value of the expression in this solution.

Since:

7.5

HxSolutionStatus HxSolution::getStatus()

Returns the status of the solution. Only allowed in states S_Paused or S_Stopped.

Returns:

Status of the solution.

See:

HxSolutionStatus

hxint HxSolution::getObjectiveBound(int objectiveIndex)

Returns the bound computed by the optimizer for the given objective. If the optimizer has never been launched, this method returns LONG_LONG_MIN or LONG_LONG_MAX depending on the optimization direction of the objective. Only allowed in states S_Paused or S_Stopped. Only allowed if this expression is an integer or a boolean. This method has the same behavior as HxSolution::getIntObjectiveBound().

Parameters:

objectiveIndex – Index of the objective.

Returns:

Bound of the given objective.

See:

HxExpression::isInt()

See:

HxExpression::isBool()

Since:

8.5

hxint HxSolution::getIntObjectiveBound(int objectiveIndex)

Returns the bound computed by the optimizer for the given objective. If the optimizer has never been launched, this method returns LONG_LONG_MIN or LONG_LONG_MAX depending on the optimization direction of the objective. Only allowed in states S_Paused or S_Stopped. Only allowed if this expression is an integer or a boolean.

Parameters:

objectiveIndex – Index of the objective.

Returns:

Bound of the given objective.

See:

HxExpression::isInt()

See:

HxExpression::isBool()

Since:

8.5

hxdouble HxSolution::getDoubleObjectiveBound(int objectiveIndex)

Returns the bound computed by the optimizer for the given objective. If the optimizer has never been launched, this method returns INFINITY or -INFINITY depending on the optimization direction of the objective. Only allowed in states S_Paused or S_Stopped. Only allowed if this expression is a double.

Parameters:

objectiveIndex – Index of the objective.

Returns:

Bound of the given objective.

See:

HxExpression::isDouble()

Since:

8.5

hxdouble HxSolution::getObjectiveGap(int objectiveIndex)

Returns the gap computed by the optimizer for the given objective. It is defined as:

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

Only allowed in states S_Paused or S_Stopped.

Parameters:

objectiveIndex – Index of the objective.

Returns:

Gap of the given objective.

void HxSolution::clear()

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