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

See Also
LSModel
LSOperator

Public Member Functions

LSOperator getOperator () const
 Gets the operator of this expression.
int getIndex () const
 Gets the index of this expression in the model.
bool isConstant () const
 Returns true if this expression is typed as constant in the model, false otherwise.
bool isDecision () const
 Returns true if this expression is typed as decision in the model, false otherwise.
bool isConstraint () const
 Returns true if this expression is tagged as constraint in the model, false otherwise.
bool isObjective () const
 Returns true if this expression is tagged as objective in the model, false otherwise.
bool isDouble () const
 Returns true if this expression is a double, false otherwise.
bool isInt () const
 Returns true if this expression is an integer, false otherwise.
bool isBool () const
 Returns true if this expression is a boolean (ie 0 or 1), false otherwise.
bool isArray () const
 Returns true if this expression is an array, false otherwise.
bool isCollection () const
 Returns true if this expression is a collection, false otherwise.
void addOperand (const LSExpression &expr)
 Adds the given operand to this expression.
void addOperand (int constant)
 Add the given constant operand to this expression.
void addOperand (lsint constant)
 Add the given constant operand to this expression.
void addOperand (lsdouble constant)
 Add the given constant operand to this expression.
template<typename T0 , typename T1 >
void addOperands (T0 begin, T1 end)
 Add the given operands to this expression.
LSExpression getOperand (int operandIndex) const
 Gets the operand with the given index.
void setOperand (int operandIndex, LSExpression operand)
 Replaces the operand of the given index.
void setOperand (int operandIndex, lsint constant)
 Replaces the operand of the given index.
void setOperand (int operandIndex, lsdouble constant)
 Replaces the operand of the given index.
int getNbOperands () const
 Gets the number of operands of this expression.
void setValue (lsint value)
 Sets the value of this expression in the current solution found by the solver.
void setValue (lsdouble value)
 Sets the value of this expression in the current solution found by the solver.
void setIntValue (lsint value)
 Sets the value of this expression in the current solution found by the solver.
void setDoubleValue (lsdouble value)
 Sets the value of this expression in the current solution found by the solver.
lsint getValue () const
 Gets the value of this expression in the best solution found by the solver.
lsint getIntValue () const
 Gets the value of this expression in the best solution found by the solver.
lsdouble getDoubleValue () const
 Gets the value of this expression in the best solution found by the solver.
bool isViolated () const
 Returns true if the given expression is violated in the best solution found by the solver.
LSCollection getCollectionValue () const
 Gets the value of this expression in the best solution found by the solver.
void setName (const std::string &name)
 Sets the name of this expression.
bool isNamed () const
 Returns true if this expression has a name, and false otherwise.
const std::string getName () const
 Gets the name of this expression or the empty string if no name has been set.
std::string toString () const
 Returns a string representation of this expression.
std::string getInfo () const
 Returns useful info about this expression (according to the state of LocalSolver).
template<typename T >
LSExpression operator+= (T operand)
template<typename T >
LSExpression operator*= (T operand)
template<typename T >
LSExpression operator&= (T operand)
template<typename T >
LSExpression operator^= (T operand)
template<typename T >
LSExpression operator|= (T operand)
template<typename T >
LSExpression operator+ (T operand)
template<typename T >
LSExpression operator- (T operand)
template<typename T >
LSExpression operator* (T operand)
template<typename T >
LSExpression operator% (T operand)
template<typename T >
LSExpression operator/ (T operand)
LSExpression operator! ()
template<typename T >
LSExpression operator&& (T operand)
template<typename T >
LSExpression operator|| (T operand)
template<typename T >
LSExpression operator^ (T operand)
template<typename T >
LSExpression operator== (T operand)
template<typename T >
LSExpression operator!= (T operand)
template<typename T >
LSExpression operator>= (T operand)
template<typename T >
LSExpression operator<= (T operand)
template<typename T >
LSExpression operator> (T operand)
template<typename T >
LSExpression operator< (T operand)
template<typename T >
LSExpression operator[] (T operand)
 ~LSExpression ()
 LSExpression ()
 LSExpression (const LSExpression &other)
LSExpression operator= (const LSExpression &other)

Friends

LSExpression operator+ (lsint expr0, LSExpression expr1)
LSExpression operator+ (lsdouble expr0, LSExpression expr1)
LSExpression operator+ (int expr0, LSExpression expr1)
LSExpression operator- (lsint expr0, LSExpression expr1)
LSExpression operator- (lsdouble expr0, LSExpression expr1)
LSExpression operator- (int expr0, LSExpression expr1)
LSExpression operator* (lsint expr0, LSExpression expr1)
LSExpression operator* (lsdouble expr0, LSExpression expr1)
LSExpression operator* (int expr0, LSExpression expr1)
LSExpression operator/ (lsint expr0, LSExpression expr1)
LSExpression operator/ (lsdouble expr0, LSExpression expr1)
LSExpression operator/ (int expr0, LSExpression expr1)
LSExpression operator% (lsint expr0, LSExpression expr1)
LSExpression operator% (int expr0, LSExpression expr1)
LSExpression operator== (lsint expr0, LSExpression expr1)
LSExpression operator== (lsdouble expr0, LSExpression expr1)
LSExpression operator== (int expr0, LSExpression expr1)
LSExpression operator!= (lsint expr0, LSExpression expr1)
LSExpression operator!= (lsdouble expr0, LSExpression expr1)
LSExpression operator!= (int expr0, LSExpression expr1)
LSExpression operator>= (lsint expr0, LSExpression expr1)
LSExpression operator>= (lsdouble expr0, LSExpression expr1)
LSExpression operator>= (int expr0, LSExpression expr1)
LSExpression operator<= (lsint expr0, LSExpression expr1)
LSExpression operator<= (lsdouble expr0, LSExpression expr1)
LSExpression operator<= (int expr0, LSExpression expr1)
LSExpression operator> (lsint expr0, LSExpression expr1)
LSExpression operator> (lsdouble expr0, LSExpression expr1)
LSExpression operator> (int expr0, LSExpression expr1)
LSExpression operator< (lsint expr0, LSExpression expr1)
LSExpression operator< (lsdouble expr0, LSExpression expr1)
LSExpression operator< (int expr0, LSExpression expr1)

Constructor & Destructor Documentation

localsolver::LSExpression::~LSExpression ( )
inline
localsolver::LSExpression::LSExpression ( )
inline
localsolver::LSExpression::LSExpression ( const LSExpression other)
inline

Member Function Documentation

LSOperator localsolver::LSExpression::getOperator ( ) const
inline

Gets the operator of this expression.

Returns
Operator.
int localsolver::LSExpression::getIndex ( ) const
inline

Gets the index of this expression in the model.

Returns
Index in the model.
bool localsolver::LSExpression::isConstant ( ) const
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 ( ) const
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 ( ) const
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 ( ) const
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 ( ) const
inline

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

Only allowed in states S_Paused or S_Stopped.

Returns
True if the expression is a double.
Since
3.0
bool localsolver::LSExpression::isInt ( ) const
inline

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

Only allowed in states S_Paused or S_Stopped. Note that a boolean is also an integer.

Returns
True if the expression is a double.
Since
3.0
bool localsolver::LSExpression::isBool ( ) const
inline

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

Only allowed in states S_Paused or S_Stopped.

Returns
True if the expression is a boolean.
Since
3.0
bool localsolver::LSExpression::isArray ( ) const
inline

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

Only allowed in states S_Paused or S_Stopped.

Returns
True if the expression is an array.
Since
3.1
bool localsolver::LSExpression::isCollection ( ) const
inline

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

Only allowed in states S_Paused or S_Stopped.

Returns
True if the expression is a collection.
Since
5.5
void localsolver::LSExpression::addOperand ( const LSExpression expr)
inline

Adds the given operand to this expression.

Only allowed in state S_Modeling.

Parameters
exprOperand to add.
void localsolver::LSExpression::addOperand ( int  constant)
inline

Add the given constant operand to this expression.

Only allowed in state S_Modeling.

Parameters
constantConstant operand to add.
void localsolver::LSExpression::addOperand ( lsint  constant)
inline

Add the given constant operand to this expression.

Only allowed in state S_Modeling.

Parameters
constantConstant operand to add.
void localsolver::LSExpression::addOperand ( lsdouble  constant)
inline

Add the given constant operand to this expression.

Only allowed in state S_Modeling.

Parameters
constantConstant operand to add.
Since
3.0
template<typename T0 , typename T1 >
void localsolver::LSExpression::addOperands ( T0  begin,
T1  end 
)
inline

Add the given operands to this expression.

Only allowed in state S_Modeling.

Parameters
beginiterator to the initial position of the operands to add.
enditerator to the final position of the operands to add.
Since
5.5
LSExpression localsolver::LSExpression::getOperand ( int  operandIndex) const
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,
lsint  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,
lsdouble  constant 
)
inline

Replaces the operand of the given index.

Parameters
operandIndexIndex of the operand to change.
constantNew constant operand.
Since
3.0
int localsolver::LSExpression::getNbOperands ( ) const
inline

Gets the number of operands of this expression.

Returns
Number of operands.
void localsolver::LSExpression::setValue ( lsint  value)
inline

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

Only allowed for decisions. Only allowed in state S_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, lsint) and has the same behavior as setIntValue(lsint).

Parameters
valueValue assigned to this expression.
See Also
LSSolution::setValue(LSExpression, lsint)
isInt()
isBool()
void localsolver::LSExpression::setValue ( lsdouble  value)
inline

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

Only allowed for decisions. Only allowed in state S_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, lsdouble) and has the same behavior as setDoubleValue(lsdouble).

Parameters
valueValue assigned to this expression.
See Also
LSSolution::setValue(LSExpression expr, lsdouble value)
isDouble()
void localsolver::LSExpression::setIntValue ( lsint  value)
inline

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

Only allowed for decisions. Only allowed in state S_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, lsint).

Parameters
valueValue assigned to this expression.
See Also
LSSolution::setIntValue(LSExpression, lsint)
isInt()
isBool()
Since
3.0
void localsolver::LSExpression::setDoubleValue ( lsdouble  value)
inline

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

Only allowed for decisions. Only allowed in state S_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, lsdouble).

Parameters
valueValue assigned to this expression.
See Also
LSSolution::setDoubleValue(LSExpression, lsdouble)
isDouble()
Since
3.0
lsint localsolver::LSExpression::getValue ( ) const
inline

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

Only allowed in states S_Paused or S_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()
isBool()
lsint localsolver::LSExpression::getIntValue ( ) const
inline

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

Only allowed in states S_Paused or S_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()
isBool()
Since
3.0
lsdouble localsolver::LSExpression::getDoubleValue ( ) const
inline

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

Only allowed in states S_Paused or S_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
3.0
bool localsolver::LSExpression::isViolated ( ) const
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 S_Paused or S_Stopped. This method is a shortcut for LSSolution#isViolated(LSExpression).
Returns
True if this expression is violated in the best solution.
Since
5.5
LSCollection localsolver::LSExpression::getCollectionValue ( ) const
inline

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

Only allowed in states S_Paused or S_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(LSExpression)
Since
5.5
void localsolver::LSExpression::setName ( const std::string &  name)
inline

Sets the name of this expression.

Only allowed in state S_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 ( ) const
inline

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

Returns
True if named.
const std::string localsolver::LSExpression::getName ( ) const
inline

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

Returns
Name.
std::string localsolver::LSExpression::toString ( ) const
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.
std::string localsolver::LSExpression::getInfo ( ) const
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.
template<typename T >
LSExpression localsolver::LSExpression::operator+= ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator*= ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator&= ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator^= ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator|= ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator+ ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator- ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator* ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator% ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator/ ( operand)
inline
LSExpression localsolver::LSExpression::operator! ( )
inline
template<typename T >
LSExpression localsolver::LSExpression::operator&& ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator|| ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator^ ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator== ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator!= ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator>= ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator<= ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator> ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator< ( operand)
inline
template<typename T >
LSExpression localsolver::LSExpression::operator[] ( operand)
inline
LSExpression localsolver::LSExpression::operator= ( const LSExpression other)
inline

Friends And Related Function Documentation

LSExpression operator+ ( lsint  expr0,
LSExpression  expr1 
)
friend
LSExpression operator+ ( lsdouble  expr0,
LSExpression  expr1 
)
friend
LSExpression operator+ ( int  expr0,
LSExpression  expr1 
)
friend
LSExpression operator- ( lsint  expr0,
LSExpression  expr1 
)
friend
LSExpression operator- ( lsdouble  expr0,
LSExpression  expr1 
)
friend
LSExpression operator- ( int  expr0,
LSExpression  expr1 
)
friend
LSExpression operator* ( lsint  expr0,
LSExpression  expr1 
)
friend
LSExpression operator* ( lsdouble  expr0,
LSExpression  expr1 
)
friend
LSExpression operator* ( int  expr0,
LSExpression  expr1 
)
friend
LSExpression operator/ ( lsint  expr0,
LSExpression  expr1 
)
friend
LSExpression operator/ ( lsdouble  expr0,
LSExpression  expr1 
)
friend
LSExpression operator/ ( int  expr0,
LSExpression  expr1 
)
friend
LSExpression operator% ( lsint  expr0,
LSExpression  expr1 
)
friend
LSExpression operator% ( int  expr0,
LSExpression  expr1 
)
friend
LSExpression operator== ( lsint  expr0,
LSExpression  expr1 
)
friend
LSExpression operator== ( lsdouble  expr0,
LSExpression  expr1 
)
friend
LSExpression operator== ( int  expr0,
LSExpression  expr1 
)
friend
LSExpression operator!= ( lsint  expr0,
LSExpression  expr1 
)
friend
LSExpression operator!= ( lsdouble  expr0,
LSExpression  expr1 
)
friend
LSExpression operator!= ( int  expr0,
LSExpression  expr1 
)
friend
LSExpression operator>= ( lsint  expr0,
LSExpression  expr1 
)
friend
LSExpression operator>= ( lsdouble  expr0,
LSExpression  expr1 
)
friend
LSExpression operator>= ( int  expr0,
LSExpression  expr1 
)
friend
LSExpression operator<= ( lsint  expr0,
LSExpression  expr1 
)
friend
LSExpression operator<= ( lsdouble  expr0,
LSExpression  expr1 
)
friend
LSExpression operator<= ( int  expr0,
LSExpression  expr1 
)
friend
LSExpression operator> ( lsint  expr0,
LSExpression  expr1 
)
friend
LSExpression operator> ( lsdouble  expr0,
LSExpression  expr1 
)
friend
LSExpression operator> ( int  expr0,
LSExpression  expr1 
)
friend
LSExpression operator< ( lsint  expr0,
LSExpression  expr1 
)
friend
LSExpression operator< ( lsdouble  expr0,
LSExpression  expr1 
)
friend
LSExpression operator< ( int  expr0,
LSExpression  expr1 
)
friend