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

Methods

GetLocalSolver

Returns the LocalSolver object associated to 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.

GetIntValue

Returns the value of the given expression in this solution.

GetIntervalValue

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.

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.

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.

Instance methods

LocalSolver GetLocalSolver()

Returns the LocalSolver object associated to this solution.

Returns:

LocalSolver object

Return type:

LocalSolver

void SetValue(LSExpression expr, long value)

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

Arguments:
  • expr (LSExpression) – Decision.

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

See:

LSExpression.IsDecision

See:

LSExpression.IsInt

See:

LSExpression.IsBool

void SetValue(LSExpression expr, double value)

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

Arguments:
  • expr (LSExpression) – Decision.

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

See:

LSExpression.IsDecision

See:

LSExpression.IsDouble

void SetValue(LSExpression expr, LSInterval value)

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

Arguments:
See:

LSExpression.IsDecision

See:

LSExpression.IsInterval

void SetIntValue(LSExpression expr, long value)

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

Since:

3.0

Arguments:
  • expr (LSExpression) – Decision.

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

See:

LSExpression.IsDecision

See:

LSExpression.IsInt

See:

LSExpression.IsBool

void SetDoubleValue(LSExpression expr, long value)

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

Since:

3.0

Arguments:
  • expr (LSExpression) – Decision.

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

See:

LSExpression.IsDecision

See:

LSExpression.IsDouble

void SetIntervalValue(LSExpression expr, LSInterval value)

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

Since:

12.0

Arguments:
See:

LSExpression.IsDecision

See:

LSExpression.IsInterval

long GetValue(LSExpression expr)

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

This method has the same behavior as LSSolution.GetIntValue.

Arguments:

expr (LSExpression) – Expression.

Returns:

Value of the expression in this solution.

Return type:

long

See:

LSExpression.IsInt

See:

LSExpression.IsBool

double GetDoubleValue(LSExpression expr)

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

Since:

3.0

Arguments:

expr (LSExpression) – Expression.

Returns:

Value of the expression in this solution.

Return type:

double

See:

LSExpression.IsDouble

long GetIntValue(LSExpression expr)

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

Since:

3.0

Arguments:

expr (LSExpression) – Expression.

Returns:

Value of the expression in this solution.

Return type:

long

See:

LSExpression.IsInt

See:

LSExpression.IsBool

long GetIntervalValue(LSExpression expr)

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

Since:

3.0

Arguments:

expr (LSExpression) – Expression.

Returns:

Value of the expression in this solution.

Return type:

LSInterval

See:

LSExpression.IsInterval

LSCollection GetCollectionValue(LSExpression expr)

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

Since:

5.5

Arguments:

expr (LSExpression) – Expression.

Returns:

Value of the expression in this solution.

Return type:

LSCollection

See:

LSExpression.IsCollection

LSCollection GetArrayValue(LSExpression expr)

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

Since:

7.5

Arguments:

expr (LSExpression) – Expression.

Returns:

Value of the expression in this solution.

Return type:

LSArray

See:

LSExpression.IsArray

bool IsViolated(LSExpression expr)

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

  • It is a constraint and its value is 0.

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

Only allowed in states Paused or Stopped.

Since:

5.5

Arguments:

expr (LSExpression) – Expression.

Returns:

True if the expression is violated in this solution.

Return type:

bool

bool IsUndefined(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 Paused or Stopped.

Since:

7.0

Arguments:

expr (LSExpression) – Expression.

Returns:

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

LSSolutionStatus GetStatus()

Returns the status of the solution. Only allowed in states Paused or Stopped.

Returns:

Status of the solution

Return type:

LSSolutionStatus

long GetObjectiveBound(int objectiveIndex)

Returns the bound computed by the solver for the given objective. If the solver has never been launched, this method returns Int64.MaxValue or Int64.MinValue depending on the optimization direction of the objective. Only allowed in states Paused or Stopped. Only allowed if this expression is a boolean or an integer. This method has the same behavior as LSSolution.GetIntObjectiveBound.

Since:

8.5

Arguments:

objectiveIndex (int) – Index of the objective.

Returns:

Bound of the given objective.

Return type:

long

See:

LSExpression.IsInt

See:

LSExpression.IsBool

long GetIntObjectiveBound(int objectiveIndex)

Returns the bound computed by the solver for the given objective. If the solver has never been launched, this method returns Int64.MaxValue or Int64.MinValue depending on the optimization direction of the objective. Only allowed in states Paused or Stopped. Only allowed if this expression is a boolean or an integer.

Since:

8.5

Arguments:

objectiveIndex (int) – Index of the objective.

Returns:

Bound of the given objective.

Return type:

long

See:

LSExpression.IsInt

See:

LSExpression.IsBool

double GetDoubleObjectiveBound(int objectiveIndex)

Returns the bound computed by the solver for the given objective. If the solver has never been launched, this method returns Double.PositiveInfinity or Double.NegativeInfinity depending on the optimization direction of the objective. Only allowed in states Paused or Stopped. Only allowed if this expression is a double.

Since:

8.5

Arguments:

objectiveIndex (int) – Index of the objective.

Returns:

Bound of the given objective.

Return type:

double

See:

LSExpression.IsDouble

double 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 Paused or Stopped.

Arguments:

objectiveIndex (int) – Index of the objective.

Returns:

Gap of the given objective.

Return type:

double

void Clear()

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