LSExpression Class¶
-
class
localsolver::
LSExpression
¶ 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:
Summary¶
getOperator |
Gets the operator of this expression. |
getIndex |
Gets the index of this expression in the model. |
isConstant |
Returns true if this expression is typed as constant in the model, false otherwise. |
isDecision |
Returns true if this expression is typed as decision in the model, false otherwise. |
isConstraint |
Returns true if this expression is tagged as constraint in the model, false otherwise. |
isObjective |
Returns true if this expression is tagged as objective in the model, false otherwise. |
isDouble |
Returns true if this expression is a double, false otherwise. |
isInt |
Returns true if this expression is an integer, false otherwise. |
isBool |
Returns true if this expression is a boolean (ie 0 or 1), false otherwise. |
isArray |
Returns true if this expression is an array, false otherwise. |
isCollection |
Returns true if this expression is a collection, false otherwise. |
isFunction |
Returns true if this expression is a function, false otherwise. |
addOperand |
Adds the given operand to this expression. |
addOperands |
Add the given operands to this expression. |
getOperand |
Gets the operand with the given index. |
setOperand |
Replaces the operand of the given index. |
getNbOperands |
Gets the number of operands of this expression. |
setValue |
Sets the value of this expression in the current solution found by the solver. |
setIntValue |
Sets the value of this expression in the current solution found by the solver. |
setDoubleValue |
Sets the value of this expression in the current solution found by the solver. |
getValue |
Gets the value of this expression in the best solution found by the solver. |
getIntValue |
Gets the value of this expression in the best solution found by the solver. |
getDoubleValue |
Gets the value of this expression in the best solution found by the solver. |
isViolated |
Returns true if the given expression is violated in the best solution found by the solver. |
getCollectionValue |
Gets the value of this expression in the best solution found by the solver. |
setName |
Sets the name of this expression. |
isNamed |
Returns true if this expression has a name, and false otherwise. |
getName |
Gets the name of this expression or the empty string if no name has been set. |
toString |
Returns a string representation of this expression. |
getInfo |
Returns useful info about this expression (according to the state of LocalSolver). |
Functions¶
-
LSOperator
getOperator
() const¶ Gets the operator of this expression.
Return: Operator.
-
int
getIndex
() const¶ Gets the index of this expression in the model.
Return: Index in the model.
-
bool
isConstant
() const¶ Returns true if this expression is typed as constant in the model, false otherwise.
Return: True if typed as constant.
-
bool
isDecision
() const¶ Returns true if this expression is typed as decision in the model, false otherwise.
Return: True if typed as decision.
-
bool
isConstraint
() const¶ Returns true if this expression is tagged as constraint in the model, false otherwise.
Return: True if tagged as constraint.
-
bool
isObjective
() const¶ Returns true if this expression is tagged as objective in the model, false otherwise.
Return: True if tagged as objective.
-
bool
isDouble
() const¶ Returns true if this expression is a double, false otherwise.
Only allowed in states S_Paused or S_Stopped.
Return: True if the expression is a double. Since: 3.0
-
bool
isInt
() const¶ 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.
Return: True if the expression is an integer. Since: 3.0
-
bool
isBool
() const¶ Returns true if this expression is a boolean (ie 0 or 1), false otherwise.
Only allowed in states S_Paused or S_Stopped.
Return: True if the expression is a boolean. Since: 3.0
-
bool
isArray
() const¶ Returns true if this expression is an array, false otherwise.
Only allowed in states S_Paused or S_Stopped.
Return: True if the expression is an array. Since: 3.1
-
bool
isCollection
() const¶ Returns true if this expression is a collection, false otherwise.
Only allowed in states S_Paused or S_Stopped.
Return: True if the expression is a collection. Since: 5.5
-
bool
isFunction
() const¶ Returns true if this expression is a function, false otherwise.
Only allowed in states S_Paused or S_Stopped.
Return: True if the expression is a function. Since: 6.0
-
void
addOperand
(const LSExpression &expr)¶ Adds the given operand to this expression.
Only allowed in state S_Modeling.
Parameters: expr - Operand to add.
-
void
addOperand
(int constant)¶ Add the given constant operand to this expression.
Only allowed in state S_Modeling.
Parameters: constant - Constant operand to add.
-
void
addOperand
(lsint constant)¶ Add the given constant operand to this expression.
Only allowed in state S_Modeling.
Parameters: constant - Constant operand to add.
-
void
addOperand
(lsdouble constant)¶ Add the given constant operand to this expression.
Only allowed in state S_Modeling.
Since: 3.0 Parameters: constant - Constant operand to add.
- template <typename T0, typename T1>
-
void
addOperands
(T0 begin, T1 end)¶ Add the given operands to this expression.
Only allowed in state S_Modeling.
Since: 5.5
Parameters: - begin - iterator to the initial position of the operands to add.
- end - iterator to the final position of the operands to add.
-
LSExpression
getOperand
(int operandIndex) const¶ Gets the operand with the given index.
Return: Operand. Parameters: operandIndex - Index of the operand.
-
void
setOperand
(int operandIndex, LSExpression operand)¶ Replaces the operand of the given index.
Parameters: - operandIndex - Index of the operand to change
- operand - New operand
-
void
setOperand
(int operandIndex, lsint constant)¶ Replaces the operand of the given index.
Parameters: - operandIndex - Index of the operand to change.
- constant - New constant operand.
-
void
setOperand
(int operandIndex, lsdouble constant)¶ Replaces the operand of the given index.
Since: 3.0
Parameters: - operandIndex - Index of the operand to change.
- constant - New constant operand.
-
int
getNbOperands
() const¶ Gets the number of operands of this expression.
Return: Number of operands.
-
void
setValue
(lsint value)¶ 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).
See: Parameters: value - Value assigned to this expression.
-
void
setValue
(lsdouble value)¶ 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).
See: Parameters: value - Value assigned to this expression.
-
void
setIntValue
(lsint value)¶ 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).
See: Since: 3.0
Parameters: value - Value assigned to this expression.
-
void
setDoubleValue
(lsdouble value)¶ 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).
See: Since: 3.0
Parameters: value - Value assigned to this expression.
-
lsint
getValue
() const¶ 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).
Return: Value in the best solution.
See:
-
lsint
getIntValue
() const¶ 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).
Return: Value in the best solution.
See: Since: 3.0
-
lsdouble
getDoubleValue
() const¶ 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).
Return: Value in the best solution.
See: Since: 3.0
-
bool
isViolated
() const¶ Returns true if the given expression is violated in the best solution found by the solver.
An expression can be violated in 3 cases:
- it is a constraint and its value is 0
- it is a a double and its value is NaN (NotANumber)
- 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).
Return: True if this expression is violated in the best solution. Since: 5.5
-
LSCollection
getCollectionValue
() const¶ 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).
Return: Value in the best solution. See: LSSolution::getCollectionValue(LSExpression) Since: 5.5
-
void
setName
(const std::string &name)¶ 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: name - Name.
-
bool
isNamed
() const¶ Returns true if this expression has a name, and false otherwise.
Return: True if named.
-
const std::string
getName
() const¶ Gets the name of this expression or the empty string if no name has been set.
Return: Name.
-
std::string
toString
() const¶ 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.
Return: String representation.
-
std::string
getInfo
() const¶ Returns useful info about this expression (according to the state of LocalSolver).
Useful for debugging or logging purposes.
Return: Info about this search during the solving process.