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

LSSolutionStatus

Public Member Functions

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.
LSSolutionStatus GetStatus ()
 Returns the status of the solution.
void Clear ()
 Clear the solution and set all decisions to zero.

Properties

IEnumerable< LSExpressionViolatedExpressions [get]
 Returns the collection of violated expressions in this solution.

Member Function Documentation

void localsolver.LSSolution.SetValue ( LSExpression  expr,
long  value 
)
inline

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

Parameters
exprDecision.
valueValue assigned to the decision in this solution.

LSExpression.IsDecision LSExpression.IsInt LSExpression.IsBool

void localsolver.LSSolution.SetValue ( LSExpression  expr,
double  value 
)
inline

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

Parameters
exprDecision.
valueValue assigned to the decision in this solution.

LSExpression.IsDecision LSExpression.IsDouble

void localsolver.LSSolution.SetIntValue ( LSExpression  expr,
long  value 
)
inline

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.

LSExpression.IsDecision LSExpression.IsInt Since version 3.0

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

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.

LSExpression.IsDecision LSExpression.IsDouble Since version 3.0

long localsolver.LSSolution.GetValue ( LSExpression  expr)
inline

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.

LSExpression.IsInt LSExpression.IsBool

double localsolver.LSSolution.GetDoubleValue ( LSExpression  expr)
inline

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.

LSExpression.IsDouble Since version 3.0

long localsolver.LSSolution.GetIntValue ( LSExpression  expr)
inline

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.

LSExpression.IsInt LSExpression.IsBool Since version 3.0

LSCollection localsolver.LSSolution.GetCollectionValue ( LSExpression  expr)
inline

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.

LSExpression.IsCollection Since version 5.5

bool localsolver.LSSolution.IsViolated ( LSExpression  expr)
inline

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 (NotANumber)
  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

LSSolutionStatus localsolver.LSSolution.GetStatus ( )
inline

Returns the status of the solution.

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

Returns
Status of the solution.

LSSolutionStatus

void localsolver.LSSolution.Clear ( )
inline

Clear the solution and set all decisions to zero.

Only allowed in state LSState.Stopped.

Property Documentation

IEnumerable<LSExpression> localsolver.LSSolution.ViolatedExpressions
get

Returns the collection of violated expressions in this solution.