Localsolver  6.5
localsolver.LSSolution Class Reference

Detailed Description

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 Also
LSSolutionStatus

Public Member Functions

LocalSolver GetLocalSolver ()
 Returns the LocalSolver object associated to this solution.
void SetValue (LSExpression expr, long value)
 Sets the value of the given expression in this solution.
void SetValue (LSExpression expr, double value)
 Sets the value of the given expression in this solution.
void SetIntValue (LSExpression expr, long value)
 Sets the value of the given expression in this solution.
void SetDoubleValue (LSExpression expr, double value)
 Sets the value of the given expression in this solution.
long GetValue (LSExpression expr)
 Returns the value of the given expression in this solution.
double GetDoubleValue (LSExpression expr)
 Returns the value of the given expression in this solution.
long GetIntValue (LSExpression expr)
 Returns the value of the given expression in this solution.
LSCollection GetCollectionValue (LSExpression expr)
 Returns the value of the given expression in this solution.
bool IsViolated (LSExpression expr)
 Returns true if the given expression is violated in this solution.
IEnumerable< LSExpressionGetViolatedExpressions ()
 Returns the collection of violated expressions in this solution.
LSSolutionStatus GetStatus ()
 Returns the status of the solution.
void Clear ()
 Clear the solution and set all decisions to zero.

Member Function Documentation

LocalSolver localsolver.LSSolution.GetLocalSolver ( )

Returns the LocalSolver object associated to this solution.

Returns
LocalSolver object
void localsolver.LSSolution.SetValue ( LSExpression  expr,
long  value 
)

Sets the value of the given expression in this solution.

Only decisions can be set. Only allowed in state LSState::Paused or LSState::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
exprDecision.
valueValue assigned to the decision in this solution.
See Also
LSExpression.IsDecision, LSExpression.IsInt, LSExpression.IsBool
void localsolver.LSSolution.SetValue ( LSExpression  expr,
double  value 
)

Sets the value of the given expression in this solution.

Only decisions can be set. Only allowed in state LSState::Paused or LSState::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
exprDecision.
valueValue assigned to the decision in this solution.
See Also
LSExpression.IsDecision, LSExpression.IsDouble
void localsolver.LSSolution.SetIntValue ( LSExpression  expr,
long  value 
)

Sets the value of the given expression in this solution.

Only decisions can be set. Only allowed in state LSState::Paused or LSState::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
exprDecision.
valueValue assigned to the decision in this solution.
See Also
LSExpression.IsDecision, LSExpression.IsInt

Since version 3.0

void localsolver.LSSolution.SetDoubleValue ( LSExpression  expr,
double  value 
)

Sets the value of the given expression in this solution.

Only decisions can be set. Only allowed in state LSState::Paused or LSState::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
exprDecision.
valueValue assigned to the decision in this solution.
See Also
LSExpression.IsDecision, LSExpression.IsDouble

Since version 3.0

long localsolver.LSSolution.GetValue ( LSExpression  expr)

Returns the value of the given expression in this solution.

Only allowed in states LSState::Paused or LSState::Stopped. Only allowed if this expression is an integer or a boolean.

Parameters
exprExpression.
Returns
Value of the expression in this solution.
See Also
LSExpression.IsInt, LSExpression.IsBool
double localsolver.LSSolution.GetDoubleValue ( LSExpression  expr)

Returns the value of the given expression in this solution.

Only allowed in states LSState::Paused or LSState::Stopped. Only allowed if this expression is a double.

Parameters
exprExpression.
Returns
Value of the expression in this solution.
See Also
LSExpression.IsDouble

Since version 3.0

long localsolver.LSSolution.GetIntValue ( LSExpression  expr)

Returns the value of the given expression in this solution.

Only allowed in states LSState::Paused or LSState::Stopped. Only allowed if this expression is an integer or a boolean.

Parameters
exprExpression.
Returns
Value of the expression in this solution.
See Also
LSExpression.IsInt, LSExpression.IsBool

Since version 3.0

LSCollection localsolver.LSSolution.GetCollectionValue ( LSExpression  expr)

Returns the value of the given expression in this solution.

Only allowed in states LSState::Paused or LSState::Stopped. Only allowed if this expression is an collection (list).

Parameters
exprExpression.
Returns
Value of the expression in this solution.
See Also
LSExpression.IsCollection

Since version 5.5

bool localsolver.LSSolution.IsViolated ( 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 LSState::Paused or LSState::Stopped.

Parameters
exprExpression.
Returns
True if this expression is violated in this solution.

Since version 5.5

IEnumerable<LSExpression> localsolver.LSSolution.GetViolatedExpressions ( )

Returns the collection of violated expressions in this solution.

LSSolutionStatus localsolver.LSSolution.GetStatus ( )

Returns the status of the solution.

Only allowed in states LSState::Paused or LSState::Stopped.

Returns
Status of the solution.
See Also
LSSolutionStatus
void localsolver.LSSolution.Clear ( )

Clear the solution and set all decisions to zero.

Only allowed in state LSState::Stopped.