LocalSolver logo
is now
Hexaly logo

We're excited to share that we are moving forward. We're leaving behind the LocalSolver brand and transitioning to our new identity: Hexaly. This represents a leap forward in our mission to enable every organization to make better decisions faster when faced with operational and strategic challenges.

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

See:LSSolutionStatus

Summary

Functions
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.
getValue Returns the value of the given expression in this solution.
getDoubleValue Returns the value of the given expression in this solution.
isViolated Returns true if the given expression is violated 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.
getStatus Returns the status of the solution.
clear Clear the solution and set all decisions to zero.

Functions

void setValue(LSExpression expr, lsint value)

Sets the value of the given expression in this solution.

Only decisions can be set. Only allowed in state S_Paused or 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 setIntValue.

See:

LSExpression::isDecision()

LSExpression::isInt()

LSExpression::isBool()

Parameters:
  • expr - Decision.
  • value - Value assigned to the decision in this solution.

void setValue(LSExpression expr, lsdouble value)

Sets the value of the given expression in this solution.

Only decisions can be set. Only allowed in state S_Paused or 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 setDoubleValue.

See:

LSExpression::isDecision()

LSExpression::isDouble()

Parameters:
  • expr - Decision.
  • value - Value assigned to the decision in this solution.

void setIntValue(LSExpression expr, lsint value)

Sets the value of the given expression in this solution.

Only decisions can be set. Only allowed in state S_Paused or 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.

See:

LSExpression::isDecision()

LSExpression::isInt()

Since:

3.0

Parameters:
  • expr - Decision.
  • value - Value assigned to the decision in this solution.

void setDoubleValue(LSExpression expr, lsdouble value)

Sets the value of the given expression in this solution.

Only decisions can be set. Only allowed in state S_Paused or 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.

See:

LSExpression::isDecision()

LSExpression::isDouble()

Since:

3.0

Parameters:
  • expr - Decision.
  • value - Value assigned to the decision in this solution.

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

See:

LSExpression::isInt()

LSExpression::isBool()

Return:

Value of the expression in this solution.

Parameters:

expr - Expression.

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

See:LSExpression::isDouble()
Return:Value of the expression in this solution.
Since:3.0
Parameters:expr - Expression.

bool 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 a double 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). Only allowed in states S_Paused or S_Stopped.

Return:True if this expression is violated in this solution.
Since:5.5
Parameters:expr - Expression.

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

See:

LSExpression::isInt()

LSExpression::isBool()

Return:

Value of the expression in this solution.

Since:

3.0

Parameters:

expr - Expression.

LSCollection 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 an collection (list).

See:LSExpression::isCollection()
Return:Value of the expression in this solution.
Since:5.5
Parameters:expr - Expression.

LSSolutionStatus getStatus()

Returns the status of the solution.

Only allowed in states S_Paused or S_Stopped.

Return:Status of the solution.
See:LSSolutionStatus

void clear()

Clear the solution and set all decisions to zero.

Only allowed in state S_Stopped.