HxExpression Class¶
-
class
HxExpression¶ Mathematical modeling expression. Expressions are used to build the mathematical optimization model associated to a Hexaly Optimizer. An expression is composed of an operator (which corresponds to its type) and its operands (which are other expressions of the model).
See: HxModelSee: HxOperator
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. |
isInterval |
Returns true if this expression is an interval, false otherwise. |
isArray |
Returns true if this expression is an array, false otherwise. |
isCollection |
Returns true if this expression is a collection (list or set), false otherwise. |
isFunction |
Returns true if this expression is a function, false otherwise. |
addOperand |
Adds the given operand to this expression. |
addOperand |
Add the given constant operand to this expression. |
addOperand |
Add the given constant operand to this expression. |
addOperand |
Add the given constant operand to this expression. |
addOperands |
Add the given operands 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. |
setOperand |
Replaces the operand of the given index. |
setOperand |
Replaces the operand of 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 optimizer. |
setValue |
Sets the value of this expression in the current solution found by the optimizer. |
setValue |
Sets the value of this expression in the current solution found by the optimizer. |
setIntValue |
Sets the value of this expression in the current solution found by the optimizer. |
setDoubleValue |
Sets the value of this expression in the current solution found by the optimizer. |
setIntervalValue |
Sets the value of this expression in the current solution found by the optimizer. |
getValue |
Gets the value of this expression in the best solution found by the optimizer. |
getIntValue |
Gets the value of this expression in the best solution found by the optimizer. |
getDoubleValue |
Gets the value of this expression in the best solution found by the optimizer. |
getIntervalValue |
Gets the value of this expression in the best solution found by the optimizer. |
getCollectionValue |
Gets the value of this expression in the best solution found by the optimizer. |
getArrayValue |
Gets the value of this expression in the best solution found by the optimizer. |
getExternalContext |
Gets the external function context of this expression. |
isViolated |
Returns true if the given expression is violated in the best solution found by the optimizer. |
isUndefined |
Returns true if the given expression has an undefined value in the best solution found by the optimizer. |
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. |
operator+ |
Creates a new O_Sum expression. |
operator- |
Creates a new O_Sub expression. |
operator* |
Creates a new O_Prod expression. |
operator% |
Creates a new O_Mod expression. |
operator/ |
Creates a new O_Div expression. |
operator! |
Creates a new O_Not expression. |
operator&& |
Creates a new O_And expression. |
operator|| |
Creates a new O_Or expression. |
operator^ |
Creates a new O_Xor expression. |
operator== |
Creates a new O_Eq expression. |
operator!= |
Creates a new O_Neq expression. |
operator>= |
Creates a new O_Geq expression. |
operator<= |
Creates a new O_Leq expression. |
operator> |
Creates a new O_Gt expression. |
operator< |
Creates a new O_Lt expression. |
operator[] |
Creates a new O_At expression. |
operator() |
Creates a O_Call expression with the given operands as arguments. |
Functions¶
-
HxOperator
HxExpression::getOperator() const¶ Gets the operator of this expression.
Returns: Operator.
-
int
HxExpression::getIndex() const¶ Gets the index of this expression in the model.
Returns: Index in the model.
-
bool
HxExpression::isConstant() const¶ Returns true if this expression is typed as constant in the model, false otherwise.
Returns: True if typed as constant.
-
bool
HxExpression::isDecision() const¶ Returns true if this expression is typed as decision in the model, false otherwise.
Returns: True if typed as decision.
-
bool
HxExpression::isConstraint() const¶ Returns true if this expression is tagged as constraint in the model, false otherwise.
Returns: True if tagged as constraint.
-
bool
HxExpression::isObjective() const¶ Returns true if this expression is tagged as objective in the model, false otherwise.
Returns: True if tagged as objective.
-
bool
HxExpression::isDouble() const¶ Returns true if this expression is a double, false otherwise. Only allowed in states
S_PausedorS_Stopped.Returns: True if the expression is a double. Since: 3.0
-
bool
HxExpression::isInt() const¶ Returns true if this expression is an integer, false otherwise. Only allowed in states
S_PausedorS_Stopped. Note that a boolean is also an integer.Returns: True if the expression is an integer. Since: 3.0
-
bool
HxExpression::isBool() const¶ Returns true if this expression is a boolean (ie 0 or 1), false otherwise. Only allowed in states
S_PausedorS_Stopped.Returns: True if the expression is a boolean. Since: 3.0
-
bool
HxExpression::isInterval() const¶ Returns true if this expression is an interval, false otherwise. Only allowed in states
S_PausedorS_Stopped.Returns: True if the expression is an interval. Since: 12.0
-
bool
HxExpression::isArray() const¶ Returns true if this expression is an array, false otherwise. Only allowed in states
S_PausedorS_Stopped.Returns: True if the expression is an array. Since: 3.1
-
bool
HxExpression::isCollection() const¶ Returns true if this expression is a collection (list or set), false otherwise. Only allowed in states
S_PausedorS_Stopped.Returns: True if the expression is a collection. Since: 5.5
-
bool
HxExpression::isFunction() const¶ Returns true if this expression is a function, false otherwise. Only allowed in states
S_PausedorS_Stopped.Returns: True if the expression is a function. Since: 6.0
-
void
HxExpression::addOperand(const HxExpression &operand)¶ Adds the given operand to this expression. Only allowed in state
S_Modeling.Parameters: operand – Operand to add.
-
void
HxExpression::addOperand(int constant)¶ Add the given constant operand to this expression. Only allowed in state
S_Modeling.Parameters: constant – Constant operand to add.
-
void
HxExpression::addOperand(hxint constant)¶ Add the given constant operand to this expression. Only allowed in state
S_Modeling.Parameters: constant – Constant operand to add.
-
void
HxExpression::addOperand(hxdouble constant)¶ Add the given constant operand to this expression. Only allowed in state
S_Modeling.Parameters: constant – Constant operand to add. Since: 3.0
-
template<typename ...
TN>
voidHxExpression::addOperands(TN... operands)¶ Add the given operands to this expression. Only allowed in state
S_Modeling.The operands can be doubles, integers or previously declared HxExpressions. It is also possible to use this method with iterators. In that case, you have to call this method with 2 arguments exactly that must be iterators of the same type, pointing respectively to the initial and final positions of the operands.
Parameters: - TN – types of the operands to add. Types allowed: constant types, HxExpression or iterators.
- operands – operands.
-
template<typename
T0, typenameT1>
voidHxExpression::addOperands(T0 begin, T1 end)¶ Add the given operands to this expression. Only allowed in state
S_Modeling.Parameters: - begin – iterator to the initial position of the operands to add.
- end – iterator to the final position of the operands to add.
Since: 5.5
-
HxExpression
HxExpression::getOperand(int operandIndex) const¶ Gets the operand with the given index.
Parameters: operandIndex – Index of the operand. Returns: Operand.
-
void
HxExpression::setOperand(int operandIndex, const HxExpression &operand)¶ Replaces the operand of the given index.
Parameters: - operandIndex – Index of the operand to change
- operand – New operand
-
void
HxExpression::setOperand(int operandIndex, int constant)¶ Replaces the operand of the given index.
Parameters: - operandIndex – Index of the operand to change.
- constant – New constant operand.
-
void
HxExpression::setOperand(int operandIndex, hxint constant)¶ Replaces the operand of the given index.
Parameters: - operandIndex – Index of the operand to change.
- constant – New constant operand.
-
void
HxExpression::setOperand(int operandIndex, hxdouble constant)¶ Replaces the operand of the given index.
Parameters: - operandIndex – Index of the operand to change.
- constant – New constant operand.
Since: 3.0
-
int
HxExpression::getNbOperands() const¶ Gets the number of operands of this expression.
Returns: Number of operands.
-
void
HxExpression::setValue(hxint value)¶ Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in state
S_Stopped. Only allowed if this expression is an integer or a boolean. If the optimizer was not launched, this value will be used as an initial value for the decision. This method is a shortcut forHxSolution::setValue()and has the same behavior assetIntValue().Parameters: value – Value assigned to this expression. See: HxSolution::setValue()See: HxExpression::isInt()See: HxExpression::isBool()
-
void
HxExpression::setValue(hxdouble value)¶ Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in state
S_Stopped. Only allowed if this expression is an integer or a boolean. If the optimizer was not launched, this value will be used as an initial value for the decision. This method is a shortcut forHxSolution::setDoubleValue()and has the same behavior assetDoubleValue().Parameters: value – Value assigned to this expression. See: HxSolution::setValue()See: HxExpression::isDouble()
-
void
HxExpression::setValue(hxinterval value)¶ Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in state
S_Stopped. Only allowed if this expression is an interval If the optimizer was not launched, this value will be used as an initial value for the decision. This method is a shortcut forHxSolution::setIntervalValue()and has the same behavior assetIntervalValue().Parameters: value – Value assigned to this expression. See: HxSolution::setValue()See: HxExpression::isInterval()
-
void
HxExpression::setIntValue(hxint value)¶ Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in state
S_Stopped. Only allowed if this expression is an integer or a boolean. If the optimizer was not launched, this value will be used as an initial value for the decision. This method is a shortcut forHxSolution::setIntValue().Parameters: value – Value assigned to this expression. See: HxSolution::setIntValue()See: HxExpression::isInt()See: HxExpression::isBool()Since: 3.0
-
void
HxExpression::setDoubleValue(hxdouble value)¶ Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in state
S_Stopped. Only allowed if this expression is a double. If the optimizer was not launched, this value will be used as an initial value for the decision. This method is a shortcut forHxSolution::setDoubleValue().Parameters: value – Value assigned to this expression. See: HxSolution::setDoubleValue()See: HxExpression::isDouble()Since: 3.0
-
void
HxExpression::setIntervalValue(hxinterval value)¶ Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in state
S_Stopped. Only allowed if this expression is an interval. If the optimizer was not launched, this value will be used as an initial value for the decision. This method is a shortcut forHxSolution::setIntervalValue().Parameters: value – Value assigned to this expression. See: HxSolution::setIntervalValue()See: HxExpression::isInterval()Since: 12.0
-
hxint
HxExpression::getValue() const¶ Gets the value of this expression in the best solution found by the optimizer. Only allowed in states
S_PausedorS_Stopped. Only allowed if this expression is an integer or a boolean. This method is a shortcut forHxSolution::getValue().Returns: Value in the best solution. See: HxSolution::getValue()See: HxExpression::isInt()See: HxExpression::isBool()
-
hxint
HxExpression::getIntValue() const¶ Gets the value of this expression in the best solution found by the optimizer. Only allowed in states
S_PausedorS_Stopped. Only allowed if this expression is an integer or a boolean. This method is a shortcut forHxSolution::getIntValue().Returns: Value in the best solution. See: HxSolution::getIntValue()See: HxExpression::isInt()See: HxExpression::isBool()Since: 3.0
-
hxdouble
HxExpression::getDoubleValue() const¶ Gets the value of this expression in the best solution found by the optimizer. Only allowed in states
S_PausedorS_Stopped. Only allowed if this expression is a double. This method is a shortcut forHxSolution::getDoubleValue().Returns: Value in the best solution. See: HxSolution::getDoubleValue()See: HxExpression::isDouble()Since: 3.0
-
hxinterval
HxExpression::getIntervalValue() const¶ Gets the value of this expression in the best solution found by the optimizer. Only allowed in states
S_PausedorS_Stopped. Only allowed if this expression is an interval. This method is a shortcut forHxSolution::getIntervalValue().Returns: Value in the best solution. See: HxSolution::getIntervalValue()See: HxExpression::isInterval()Since: 12.0
-
HxCollection
HxExpression::getCollectionValue() const¶ Gets the value of this expression in the best solution found by the optimizer. Only allowed in states
S_PausedorS_Stopped. Only allowed if this expression is a collection (list or set). This method is a shortcut forHxSolution::getCollectionValue().Returns: Value in the best solution. See: HxExpression::isCollection()See: HxSolution::getCollectionValue()Since: 5.5
-
HxArray
HxExpression::getArrayValue() const¶ Gets the value of this expression in the best solution found by the optimizer. Only allowed in states
S_PausedorS_Stopped. Only allowed if this expression is an array. This method is a shortcut forHxSolution::getArrayValue().Returns: Value in the best solution. See: HxExpression::isArray()See: HxSolution::getArrayValue()Since: 7.5
-
HxExternalContext
HxExpression::getExternalContext() const¶ Gets the external function context of this expression. Only allowed if this expression is an external function.
Returns: Context of the external function. See: HxExternalContextSince: 9.5
-
bool
HxExpression::isViolated() const¶ Returns true if the given expression is violated in the best solution found by the optimizer. An expression can be violated in 3 cases:
- it is a constraint and its value is 0
- it is a double objective and its value is NaN (Not a Number)
- it is an integer or boolean with no valid value (arithmetic or out of bounds exception).
Note that only constraints and objectives can be violated. Other expression can have undefined value provided that it does not impact a constraint or objective.
Only allowed in states
S_PausedorS_Stopped. This method is a shortcut forHxSolution::isViolated().Returns: True if this expression is violated in the best solution. Since: 5.5 See: HxExpression::isUndefined()
-
bool
HxExpression::isUndefined() const¶ Returns true if the given expression has an undefined value in the best solution found by the optimizer. An expression can be undefined in 4 cases:
- It is a double and its value is NaN (Not a Number).
- It is an integer or boolean with no valid value (arithmetic or out of bounds exception).
- It is an interval with at least one undefined bound.
- It is the result of any ill-defined operation (at with out of bounds index or operations on undefined values for instance).
Only allowed in states
S_PausedorS_Stopped. This method is a shortcut forHxSolution::isUndefined().Returns: True if this expression has an undefined value in the best solution. Since: 7.0
-
void
HxExpression::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
HxExpression::isNamed() const¶ Returns true if this expression has a name, and false otherwise.
Returns: True if named.
-
std::string
HxExpression::getName() const¶ Gets the name of this expression or the empty string if no name has been set.
Returns: Name.
-
std::string
HxExpression::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.
Returns: String representation.
Overloaded operators¶
-
template<typename
T>
HxExpressionHxExpression::operator+(T operand)¶ Creates a new
O_Sumexpression. It is a shortcut formodel.createExpression(O_Sum, this, operand).Parameters: operand – Operand. Can be an HxExpression, an integer or a double. Returns: A new O_Sumexpression.
-
template<typename
T>
HxExpressionHxExpression::operator-(T operand)¶ Creates a new
O_Subexpression. It is a shortcut formodel.createExpression(O_Sub, this, operand).Parameters: operand – Operand. Can be an HxExpression, an integer or a double. Returns: A new O_Subexpression.
-
template<typename
T>
HxExpressionHxExpression::operator*(T operand)¶ Creates a new
O_Prodexpression. It is a shortcut formodel.createExpression(O_Prod, this, operand).Parameters: operand – Operand. Can be an HxExpression, an integer or a double. Returns: A new O_Prodexpression.
-
template<typename
T>
HxExpressionHxExpression::operator%(T operand)¶ Creates a new
O_Modexpression. It is a shortcut formodel.createExpression(O_Mod, this, operand).Parameters: operand – Operand. Can be an HxExpression or an integer. Returns: A new O_Modexpression.
-
template<typename
T>
HxExpressionHxExpression::operator/(T operand)¶ Creates a new
O_Divexpression. It is a shortcut formodel.createExpression(O_Div, this, operand).Parameters: operand – Operand. Can be an HxExpression, an integer or a double. Returns: A new O_Divexpression.
-
HxExpression
HxExpression::operator!()¶ Creates a new
O_Notexpression. It is a shortcut formodel.createExpression(O_Not, this).Returns: A new O_Notexpression.
-
template<typename
T>
HxExpressionHxExpression::operator&&(T operand)¶ Creates a new
O_Andexpression. It is a shortcut formodel.createExpression(O_And, this, operand).Parameters: operand – Operand. Can be an HxExpression or a boolean. Returns: A new O_Andexpression.
-
template<typename
T>
HxExpressionHxExpression::operator||(T operand)¶ Creates a new
O_Orexpression. It is a shortcut formodel.createExpression(O_Or, this, operand).Parameters: operand – Operand. Can be an HxExpression or a boolean. Returns: A new O_Orexpression.
-
template<typename
T>
HxExpressionHxExpression::operator^(T operand)¶ Creates a new
O_Xorexpression. It is a shortcut formodel.createExpression(O_Xor, this, operand).Parameters: operand – Operand. Can be an HxExpression or a boolean. Returns: A new O_Xorexpression.
-
template<typename
T>
HxExpressionHxExpression::operator==(T operand)¶ Creates a new
O_Eqexpression. It is a shortcut formodel.createExpression(O_Eq, this, operand).Parameters: operand – Operand. Can be an HxExpression, an integer or a double. Returns: A new O_Eqexpression.
-
template<typename
T>
HxExpressionHxExpression::operator!=(T operand)¶ Creates a new
O_Neqexpression. It is a shortcut formodel.createExpression(O_Neq, this, operand).Parameters: operand – Operand. Can be an HxExpression, an integer or a double. Returns: A new O_Neqexpression.
-
template<typename
T>
HxExpressionHxExpression::operator>=(T operand)¶ Creates a new
O_Geqexpression. It is a shortcut formodel.createExpression(O_Geq, this, operand).Parameters: operand – Operand. Can be an HxExpression, an integer or a double. Returns: A new O_Geqexpression.
-
template<typename
T>
HxExpressionHxExpression::operator<=(T operand)¶ Creates a new
O_Leqexpression. It is a shortcut formodel.createExpression(O_Leq, this, operand).Parameters: operand – Operand. Can be an HxExpression, an integer or a double. Returns: A new O_Leqexpression.
-
template<typename
T>
HxExpressionHxExpression::operator>(T operand)¶ Creates a new
O_Gtexpression. It is a shortcut formodel.createExpression(O_Gt, this, operand).Parameters: operand – Operand. Can be an HxExpression, an integer or a double. Returns: A new O_Gtexpression.
-
template<typename
T>
HxExpressionHxExpression::operator<(T operand)¶ Creates a new
O_Ltexpression. It is a shortcut formodel.createExpression(O_Lt, this, operand).Parameters: operand – Operand. Can be an HxExpression, an integer or a double. Returns: A new O_Ltexpression.
-
template<typename
T>
HxExpressionHxExpression::operator[](T operand)¶ Creates a new
O_Atexpression. It is a shortcut formodel.createExpression(O_At, this, operand).Parameters: operand – Operand. Can be an HxExpression, an integer or a double. Returns: A new O_Atexpression.
-
template<typename ...
TN>
HxExpressionHxExpression::operator()(TN... operands)¶ Creates a
O_Callexpression with the given operands as arguments. It is a shortcut formodel.createExpression(O_Call, this, operands).Parameters: - TN – types of the operands to add. Types allowed: constant types, HxExpression or iterators.
- operands – operands.