This page is for an old version of Hexaly Optimizer. We recommend that you update your version and read the documentation for the latest stable release.

LSSolution Class

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

See:

LSSolutionStatus

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 solver for the given objective.

getIntObjectiveBound

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

getDoubleObjectiveBound

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

getObjectiveGap

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

clear

Clear the solution and set all decisions to zero.

Functions

void LSSolution::setValue(const LSExpression &expr, lsint 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 solver was not launched, this value will be used as an initial value for the decision. This method has the same behavior as LSSolution::setIntValue().

Parameters:
  • expr – Decision.

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

See:

LSExpression::isDecision()

See:

LSExpression::isInt()

See:

LSExpression::isBool()

void LSSolution::setValue(const LSExpression &expr, lsdouble 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 solver was not launched, this value will be used as an initial value for the decision. This method has the same behavior as LSSolution::setDoubleValue().

Parameters:
  • expr – Decision.

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

See:

LSExpression::isDecision()

See:

LSExpression::isDouble()

void LSSolution::setValue(const LSExpression &expr, LSInterval 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 solver was not launched, this value will be used as an initial value for the decision. This method has the same behavior as LSSolution::setIntervalValue().

Parameters:
  • expr – Decision.

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

See:

LSExpression::isDecision()

See:

LSExpression::isInterval()

void LSSolution::setIntValue(const LSExpression &expr, lsint 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 solver 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:

LSExpression::isDecision()

See:

LSExpression::isInt()

Since:

3.0

void LSSolution::setDoubleValue(const LSExpression &expr, lsdouble value)

Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in state S_Stopped. If the solver 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:

LSExpression::isDecision()

See:

LSExpression::isDouble()

Since:

3.0

void LSSolution::setIntervalValue(const LSExpression &expr, LSInterval value)

Sets the value of the given expression in this solution. Only decisions can be set. Only allowed in state S_Stopped. If the solver 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:

LSExpression::isDecision()

See:

LSExpression::isInterval()

Since:

12.0

lsint LSSolution::getValue(const LSExpression &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 LSSolution::getIntValue().

Parameters:

expr – Expression.

See:

LSExpression::isInt()

See:

LSExpression::isBool()

Returns:

Value of the expression in this solution.

lsdouble LSSolution::getDoubleValue(const LSExpression &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:

LSExpression::isDouble()

Returns:

Value of the expression in this solution.

Since:

3.0

LSInterval LSSolution::getIntervalValue(const LSExpression &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:

LSExpression::isInterval()

Returns:

Value of the expression in this solution.

Since:

12.0

bool LSSolution::isViolated(const LSExpression &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:

LSSolution::isUndefined()

bool LSSolution::isUndefined(const LSExpression &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

lsint LSSolution::getIntValue(const LSExpression &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:

LSExpression::isInt()

See:

LSExpression::isBool()

Returns:

Value of the expression in this solution.

Since:

3.0

LSCollection LSSolution::getCollectionValue(const LSExpression &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:

LSExpression::isCollection()

Returns:

Value of the expression in this solution.

Since:

5.5

LSArray LSSolution::getArrayValue(const LSExpression &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:

LSExpression::isArray()

Returns:

Value of the expression in this solution.

Since:

7.5

LSSolutionStatus LSSolution::getStatus()

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

Returns:

Status of the solution.

See:

LSSolutionStatus

lsint LSSolution::getObjectiveBound(int objectiveIndex)

Returns the bound computed by the solver for the given objective. If the solver 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 LSSolution::getIntObjectiveBound().

Parameters:

objectiveIndex – Index of the objective.

Returns:

Bound of the given objective.

See:

LSExpression::isInt()

See:

LSExpression::isBool()

Since:

8.5

lsint LSSolution::getIntObjectiveBound(int objectiveIndex)

Returns the bound computed by the solver for the given objective. If the solver 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:

LSExpression::isInt()

See:

LSExpression::isBool()

Since:

8.5

lsdouble LSSolution::getDoubleObjectiveBound(int objectiveIndex)

Returns the bound computed by the solver for the given objective. If the solver 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:

LSExpression::isDouble()

Since:

8.5

lsdouble LSSolution::getObjectiveGap(int objectiveIndex)

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 S_Paused or S_Stopped.

Parameters:

objectiveIndex – Index of the objective.

Returns:

Gap of the given objective.

void LSSolution::clear()

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