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

See Also
LSModel, LSOperator

Public Member Functions

LSModel GetModel ()
 Returns the model object associated to this expression.
LocalSolver GetLocalSolver ()
 Returns the LocalSolver object associated to this expression.
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.
bool IsCollection ()
 Returns true if this expression is a collection, false otherwise.
bool IsFunction ()
 Returns true if this expression is a function, 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

LSModel localsolver.LSExpression.GetModel ( )

Returns the model object associated to this expression.

Returns
LSModel object
LocalSolver localsolver.LSExpression.GetLocalSolver ( )

Returns the LocalSolver object associated to this expression.

Returns
LocalSolver object
LSOperator localsolver.LSExpression.GetOperator ( )

Gets the operator of this expression.

Returns
Operator.
int localsolver.LSExpression.GetIndex ( )

Gets the index of this expression in the model.

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

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

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

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

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

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

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

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

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

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

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 an integer.

Since version 3.0

bool localsolver.LSExpression.IsBool ( )

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

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

bool localsolver.LSExpression.IsCollection ( )

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

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

Returns
True if the expression is a collection.

Since version 5.5

bool localsolver.LSExpression.IsFunction ( )

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

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

Returns
True if the expression is a function.

Since version 6.0

void localsolver.LSExpression.AddOperand ( LSExpression  expr)

Adds the given operand to this expression.

Only allowed in state LSState::Modeling.

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

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)

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)

Add the given operands to the expression.

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

Add the given constant integer operands to the expression.

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

Add the given constant double operands to the expression.

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

Add the given operands to the expression.

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

Add the given constant double operands to the expression.

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

Add the given constant integer operands to the expression.

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

Gets the operand with the given index.

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

Replaces the operand of the given index.

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

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 
)

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

Gets the number of operands of this expression.

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

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 LSExpression::SetIntValue(long).

Parameters
valueValue assigned to this expression.
See Also
LSSolution.SetValue(LSExpression, long), LSExpression.IsInt, LSExpression.IsBool
void localsolver.LSExpression.SetValue ( double  value)

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 LSExpression::SetDoubleValue(double).

Parameters
valueValue assigned to this expression.
See Also
LSSolution.SetValue(LSExpression, double), LSExpression.IsDouble
void localsolver.LSExpression.SetIntValue ( long  value)

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.
See Also
LSSolution.SetIntValue, LSExpression.IsInt, LSExpression.IsBool

Since version 3.0

void localsolver.LSExpression.SetDoubleValue ( double  value)

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.
See Also
LSSolution.SetDoubleValue, LSExpression.IsDouble

Since version 3.0

long localsolver.LSExpression.GetValue ( )

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.
See Also
LSSolution.GetValue, LSExpression.IsInt, LSExpression.IsBool
long localsolver.LSExpression.GetIntValue ( )

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.
See Also
LSSolution.GetIntValue, LSExpression.IsInt, LSExpression.IsBool

Since version 3.0

double localsolver.LSExpression.GetDoubleValue ( )

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.
See Also
LSSolution.GetDoubleValue, LSExpression.IsDouble

Since version 3.0

LSCollection localsolver.LSExpression.GetCollectionValue ( )

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.
See Also
LSSolution.GetCollectionValue

Since version 5.5

bool localsolver.LSExpression.IsViolated ( )

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

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

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

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

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

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

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

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.