# LSSolution Class¶

class

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¶

 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. 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. clear Clear the solution and set all decisions to zero.

## Functions¶

void localsolver::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_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: expr - Decision. value - Value assigned to the decision in this solution.

void localsolver::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_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: expr - Decision. value - Value assigned to the decision in this solution.

void localsolver::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_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: 3.0 expr - Decision. value - Value assigned to the decision in this solution.

void localsolver::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_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: 3.0 expr - Decision. value - Value assigned to the decision in this solution.

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

See: LSExpression::isInt() LSExpression::isBool() Value of the expression in this solution. expr - Expression.

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

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

bool localsolver::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 a double objective and its value is NaN (NotANumber)
3. it is a constraint 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.

Return: True if this expression is violated in this solution. 5.5 isUndefined() expr - Expression.

bool localsolver::LSSolution::isUndefined(const LSExpression &expr)

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

An expression can be undefined in 2 cases:

1. it is a a double and its value is NaN (NotANumber)
2. 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 has an undefined value in this solution. 7.0 expr - Expression.

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

See: LSExpression::isInt() LSExpression::isBool() Value of the expression in this solution. 3.0 expr - Expression.

LSCollection localsolver::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).

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

LSArray localsolver::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.

See: LSExpression::isArray() Value of the expression in this solution. 7.5 expr - Expression.

LSSolutionStatus localsolver::LSSolution::getStatus()

Returns the status of the solution.

Only allowed in states S_Paused or S_Stopped.

Return: Status of the solution. LSSolutionStatus

lsint localsolver::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(int).

Return: Bound of the given objective. LSExpression::isInt() LSExpression::isBool() 8.5 objectiveIndex - Index of the objective.

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

Return: Bound of the given objective. LSExpression::isInt() LSExpression::isBool() 8.5 objectiveIndex - Index of the objective.

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

Return: Bound of the given objective. LSExpression::isDouble() 8.5 objectiveIndex - Index of the objective.

void localsolver::LSSolution::clear()

Clear the solution and set all decisions to zero.

Only allowed in state S_Stopped.