Localsolver  5.5
localsolver.LSExpression Class Reference

Detailed Description

Mathematical modeling expression.

Expressions are used to build the mathematical optimization model associated to LocalSolver. An expression is composed of an operator (which corresponds to its type) and its operands (which are other expressions of the model).

LSModel LSOperator

Public Member Functions

LSOperator GetOperator ()
 Gets the operator of this expression.
int GetIndex ()
 Gets the index of this expression in the model.
bool IsConstant ()
 Returns true if this expression is typed as constant in the model, false otherwise.
bool IsDecision ()
 Returns true if this expression is typed as decision in the model, false otherwise.
bool IsConstraint ()
 Returns true if this expression is tagged as constraint in the model, false otherwise.
bool IsObjective ()
 Returns true if this expression is tagged as objective in the model, false otherwise.
bool IsDouble ()
 Returns true if this expression is a double, false otherwise.
bool IsInt ()
 Returns true if this expression is an integer, false otherwise.
bool IsBool ()
 Returns true if this expression is a boolean (ie 0 or 1), false otherwise.
bool IsArray ()
 Returns true if this expression is an array, false otherwise.
void AddOperand (LSExpression expr)
 Adds the given operand to this expression.
void AddOperand (long constant)
 Add the given constant operand to this expression.
void AddOperand (double constant)
 Add the given constant operand to this expression.
void AddOperands (IEnumerable< LSExpression > operands)
 Add the given operands to the expression.
void AddOperands (IEnumerable< long > operands)
 Add the given constant integer operands to the expression.
void AddOperands (IEnumerable< double > operands)
 Add the given constant double operands to the expression.
void AddOperands (params LSExpression[] operands)
 Add the given operands to the expression.
void AddOperands (params double[] operands)
 Add the given constant double operands to the expression.
void AddOperands (params long[] operands)
 Add the given constant integer operands to the expression.
LSExpression GetOperand (int operandIndex)
 Gets the operand with the given index.
void SetOperand (int operandIndex, LSExpression operand)
 Replaces the operand of the given index.
void SetOperand (int operandIndex, long constant)
 Replaces the operand of the given index.
void SetOperand (int operandIndex, double constant)
 Replaces the operand of the given index.
int GetNbOperands ()
 Gets the number of operands of this expression.
void SetValue (long value)
 Sets the value of this expression in the current solution found by the solver.
void SetValue (double value)
 Sets the value of this expression in the current solution found by the solver.
void SetIntValue (long value)
 Sets the value of this expression in the current solution found by the solver.
void SetDoubleValue (double value)
 Sets the value of this expression in the current solution found by the solver.
long GetValue ()
 Gets the value of this expression in the best solution found by the solver.
long GetIntValue ()
 Gets the value of this expression in the best solution found by the solver.
double GetDoubleValue ()
 Gets the value of this expression in the best solution found by the solver.
LSCollection GetCollectionValue ()
 Gets the value of this expression in the best solution found by the solver.
bool IsViolated ()
 Returns true if the given expression is violated in the best solution found by the solver.
void SetName (string name)
 Sets the name of this expression.
bool IsNamed ()
 Returns true if this expression has a name, and false otherwise.
string GetName ()
 Gets the name of this expression or the empty string if no name has been set.
override string ToString ()
 Returns a string representation of this expression.
string GetInfo ()
 Returns useful info about this expression (according to the state of LocalSolver).

Member Function Documentation

LSOperator localsolver.LSExpression.GetOperator ( )
inline

Gets the operator of this expression.

Returns
Operator.
int localsolver.LSExpression.GetIndex ( )
inline

Gets the index of this expression in the model.

Returns
Index in the model.
bool localsolver.LSExpression.IsConstant ( )
inline

Returns true if this expression is typed as constant in the model, false otherwise.

Returns
True if typed as constant.
bool localsolver.LSExpression.IsDecision ( )
inline

Returns true if this expression is typed as decision in the model, false otherwise.

Returns
True if typed as decision.
bool localsolver.LSExpression.IsConstraint ( )
inline

Returns true if this expression is tagged as constraint in the model, false otherwise.

Returns
True if tagged as constraint.
bool localsolver.LSExpression.IsObjective ( )
inline

Returns true if this expression is tagged as objective in the model, false otherwise.

Returns
True if tagged as objective.
bool localsolver.LSExpression.IsDouble ( )
inline

Returns true if this expression is a double, false otherwise.

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

Returns
True if the expression is a double.

Since version 3.0

bool localsolver.LSExpression.IsInt ( )
inline

Returns true if this expression is an integer, false otherwise.

Only allowed in states LSState.Paused or LSState.Stopped. Note that a boolean is also an integer.

Returns
True if the expression is a double.

Since version 3.0

bool localsolver.LSExpression.IsBool ( )
inline

Returns true if this expression is a boolean (ie 0 or 1), false otherwise.

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

Returns
True if the expression is a boolean.

Since version 3.0

bool localsolver.LSExpression.IsArray ( )
inline

Returns true if this expression is an array, false otherwise.

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

Returns
True if the expression is an array.

Since version 3.1

void localsolver.LSExpression.AddOperand ( LSExpression  expr)
inline

Adds the given operand to this expression.

Only allowed in state LSState.Modeling.

Parameters
exprOperand to add.
void localsolver.LSExpression.AddOperand ( long  constant)
inline

Add the given constant operand to this expression.

Only allowed in state LSState.Modeling.

Parameters
constantConstant operand to add.
void localsolver.LSExpression.AddOperand ( double  constant)
inline

Add the given constant operand to this expression.

Only allowed in state LSState.Modeling.

Parameters
constantConstant operand to add.
void localsolver.LSExpression.AddOperands ( IEnumerable< LSExpression operands)
inline

Add the given operands to the expression.

Parameters
operandsThe operands to be added.
void localsolver.LSExpression.AddOperands ( IEnumerable< long >  operands)
inline

Add the given constant integer operands to the expression.

Parameters
operandsThe operands to be added.
void localsolver.LSExpression.AddOperands ( IEnumerable< double >  operands)
inline

Add the given constant double operands to the expression.

Parameters
operandsThe operands to be added.
void localsolver.LSExpression.AddOperands ( params LSExpression[]  operands)
inline

Add the given operands to the expression.

Parameters
operandsThe operands to be added.
void localsolver.LSExpression.AddOperands ( params double[]  operands)
inline

Add the given constant double operands to the expression.

Parameters
operandsThe operands to be added.
void localsolver.LSExpression.AddOperands ( params long[]  operands)
inline

Add the given constant integer operands to the expression.

Parameters
operandsThe operands to be added.
LSExpression localsolver.LSExpression.GetOperand ( int  operandIndex)
inline

Gets the operand with the given index.

Parameters
operandIndexIndex of the operand.
Returns
Operand.
void localsolver.LSExpression.SetOperand ( int  operandIndex,
LSExpression  operand 
)
inline

Replaces the operand of the given index.

Parameters
operandIndexIndex of the operand to change
operandNew operand
void localsolver.LSExpression.SetOperand ( int  operandIndex,
long  constant 
)
inline

Replaces the operand of the given index.

Parameters
operandIndexIndex of the operand to change.
constantNew constant operand.
void localsolver.LSExpression.SetOperand ( int  operandIndex,
double  constant 
)
inline

Replaces the operand of the given index.

Parameters
operandIndexIndex of the operand to change.
constantNew constant operand.

Since version 3.0

int localsolver.LSExpression.GetNbOperands ( )
inline

Gets the number of operands of this expression.

Returns
Number of operands.
void localsolver.LSExpression.SetValue ( long  value)
inline

Sets the value of this expression in the current solution found by the solver.

Only allowed for decisions. Only allowed in state 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 is a shortcut for LSSolution#SetValue(LSExpression, long) and has the same behavior as SetIntValue(long).

Parameters
valueValue assigned to this expression.

LSSolution.SetValue LSExpression.IsInt LSExpression.IsBool

void localsolver.LSExpression.SetValue ( double  value)
inline

Sets the value of this expression in the current solution found by the solver.

Only allowed for decisions. Only allowed in state 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 is a shortcut for LSSolution#SetValue(LSExpression, double) and has the same behavior as SetDoubleValue(double).

Parameters
valueValue assigned to this expression.

LSSolution.SetValue LSExpression.IsDouble

void localsolver.LSExpression.SetIntValue ( long  value)
inline

Sets the value of this expression in the current solution found by the solver.

Only allowed for decisions. Only allowed in state 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 is a shortcut for LSSolution#SetValue(LSExpression, long).

Parameters
valueValue assigned to this expression.

LSSolution.SetIntValue LSExpression.IsInt LSExpression.IsBool Since version 3.0

void localsolver.LSExpression.SetDoubleValue ( double  value)
inline

Sets the value of this expression in the current solution found by the solver.

Only allowed for decisions. Only allowed in state 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 is a shortcut for LSSolution#SetValue(LSExpression, double).

Parameters
valueValue assigned to this expression.

LSSolution.SetDoubleValue LSExpression.IsDouble Since version 3.0

long localsolver.LSExpression.GetValue ( )
inline

Gets the value of this expression in the best solution found by the solver.

Only allowed in states LSState.Paused or LSState.Stopped. Only allowed if this expression is an integer or a boolean. This method is a shortcut for LSSolution#GetValue(LSExpression).

Returns
Value in the best solution.

LSSolution.GetValue LSExpression.IsInt LSExpression.IsBool

long localsolver.LSExpression.GetIntValue ( )
inline

Gets the value of this expression in the best solution found by the solver.

Only allowed in states LSState.Paused or LSState.Stopped. Only allowed if this expression is an integer or a boolean. This method is a shortcut for LSSolution#GetIntValue(LSExpression).

Returns
Value in the best solution.

LSSolution.GetIntValue LSExpression.IsInt LSExpression.IsBool Since version 3.0

double localsolver.LSExpression.GetDoubleValue ( )
inline

Gets the value of this expression in the best solution found by the solver.

Only allowed in states LSState.Paused or LSState.Stopped. Only allowed if this expression is a double. This method is a shortcut for LSSolution#GetDoubleValue(LSExpression).

Returns
Value in the best solution.

LSSolution.GetDoubleValue LSExpression.IsDouble Since version 3.0

LSCollection localsolver.LSExpression.GetCollectionValue ( )
inline

Gets the value of this expression in the best solution found by the solver.

Only allowed in states LSState.Paused or LSState.Stopped. Only allowed if this expression is a collection (list). This method is a shortcut for LSSolution#GetCollectionValue(LSExpression).

Returns
Value in the best solution.

LSSolution.GetCollectionValue Since version 5.5

bool localsolver.LSExpression.IsViolated ( )
inline

Returns true if the given expression is violated in the best solution found by the solver.

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. This method is a shortcut for LSSolution#IsViolated(LSExpression).
Returns
True if this expression is violated in the best solution.

Since version 5.5

void localsolver.LSExpression.SetName ( string  name)
inline

Sets the name of this expression.

Only allowed in state LSState.Modeling. The name cannot be empty. Two operators of the model cannot share the same name. Useful for debugging or logging purposes.

Parameters
nameName.
bool localsolver.LSExpression.IsNamed ( )
inline

Returns true if this expression has a name, and false otherwise.

Returns
True if named.
string localsolver.LSExpression.GetName ( )
inline

Gets the name of this expression or the empty string if no name has been set.

Returns
Name.
override string localsolver.LSExpression.ToString ( )
inline

Returns a string representation of this expression.

This representation provides the index of the expression, its type, and its name (if any). Useful for debugging or logging purposes.

Returns
String representation.
string localsolver.LSExpression.GetInfo ( )
inline

Returns useful info about this expression (according to the state of LocalSolver).

Useful for debugging or logging purposes.

Returns
Info about this search during the solving process.