HxExpression Class¶
- class Hexaly.Optimizer.HxExpression¶
Mathematical modeling expression. Expressions are used to build the mathematical optimization model associated to 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:
- See:
Summary¶
Returns the model object associated to this expression. |
|
Returns the Hexaly Optimizer object associated to this expression. |
|
Gets the operator of this expression. |
|
Gets the index of this expression in the model. |
|
Returns true if this expression is typed as constant in the model, false otherwise. |
|
Returns true if this expression is typed as decision in the model, false otherwise. |
|
Returns true if this expression is tagged as constraint in the model, false otherwise. |
|
Returns true if this expression is tagged as objective in the model, false otherwise. |
|
Returns true if this expression is a double, false otherwise. |
|
Returns true if this expression is an integer, false otherwise. |
|
Returns true if this expression is a boolean (ie 0 or 1), false otherwise. |
|
Returns true if this expression is an interval, false otherwise. |
|
Returns true if this expression is an array, false otherwise. |
|
Returns true if this expression is a collection (list or set), false otherwise. |
|
Returns true if this expression is a function, false otherwise. |
|
Adds the given operand to this expression. |
|
Add the given operands to the expression. |
|
Gets the operand with the given index. |
|
Replaces the operand of the given index. |
|
Gets the number of operands of this expression. |
|
Sets the value of this expression in the current solution found by the optimizer. |
|
Sets the value of this expression in the current solution found by the optimizer. |
|
Sets the value of this expression in the current solution found by the optimizer. |
|
Sets the value of this expression in the current solution found by the optimizer. |
|
Gets the value of this expression in the best solution found by the optimizer. |
|
Gets the value of this expression in the best solution found by the optimizer. |
|
Gets the value of this expression in the best solution found by the optimizer. |
|
Gets the value of this expression in the best solution found by the optimizer. |
|
Gets the value of this expression in the best solution found by the optimizer. |
|
Gets the value of this expression in the best solution found by the optimizer. |
|
Gets the external function context of this expression. |
|
Returns true if the given expression is violated in the best solution found by the optimizer. |
|
Returns true if the given expression has an undefined value in the best solution found by the optimizer. |
|
Sets the name of this expression. |
|
Returns true if this expression has a name, and false otherwise. |
|
Gets the name of this expression or the empty string if no name has been set. |
|
Returns a string representation of this expression. |
Creates a new HxOperator.Sum expression. |
|
Creates a new HxOperator.Sub expression. |
|
Creates a new HxOperator.Prod expression. |
|
Creates a new HxOperator.Div expression. |
|
Creates a new HxOperator.Mod expression. |
|
Creates a new HxOperator.Not expression. |
|
Creates a new HxOperator.And expression. |
|
Creates a new HxOperator.Or expression. |
|
Creates a new HxOperator.Xor expression. |
|
Creates a new HxOperator.Eq expression. |
|
Creates a new HxOperator.Neq expression. |
|
Creates a new HxOperator.Geq expression. |
|
Creates a new HxOperator.Leq expression. |
|
Creates a new HxOperator.Gt expression. |
|
Creates a new HxOperator.Lt expression. |
|
Creates a new HxOperator.At expression. |
Instance methods¶
- HxModel GetModel()¶
Returns the model object associated to this expression.
- Returns:
HxModel object
- Return type:
- HexalyOptimizer GetOptimizer()¶
Returns the Hexaly Optimizer object associated to this expression.
- Returns:
Hexaly Optimizer object
- Return type:
- HxOperator GetOperator()¶
Gets the operator of this expression.
- Returns:
Operator.
- Return type:
- int GetIndex()¶
Gets the index of this expression in the model.
- Returns:
Index in the model.
- Return type:
int
- bool IsConstant()¶
Returns true if this expression is typed as constant in the model, false otherwise.
- Returns:
True if typed as constant.
- Return type:
bool
- bool IsDecision()¶
Returns true if this expression is typed as decision in the model, false otherwise.
- Returns:
True if typed as decision.
- Return type:
bool
- bool IsConstraint()¶
Returns true if this expression is tagged as constraint in the model, false otherwise.
- Returns:
True if tagged as constraint.
- Return type:
bool
- bool IsObjective()¶
Returns true if this expression is tagged as objective in the model, false otherwise.
- Returns:
True if tagged as objective.
- Return type:
bool
- bool IsDouble()¶
Returns true if this expression is a double, false otherwise. Only allowed in states
Paused
orStopped
.- Since:
3.0
- Returns:
True if the expression is a double.
- Return type:
bool
- bool IsInt()¶
Returns true if this expression is an integer, false otherwise. Only allowed in states
Paused
orStopped
. Note that a boolean is also an integer.- Since:
3.0
- Returns:
True if the expression is an integer.
- Return type:
bool
- bool IsBool()¶
Returns true if this expression is a boolean (ie 0 or 1), false otherwise. Only allowed in states
Paused
orStopped
.- Since:
3.0
- Returns:
True if the expression is a boolean.
- Return type:
bool
- bool IsInterval()¶
Returns true if this expression is an interval, false otherwise. Only allowed in states
Paused
orStopped
.- Since:
12.0
- Returns:
True if the expression is an interval.
- Return type:
bool
- bool IsArray()¶
Returns true if this expression is an array, false otherwise. Only allowed in states
Paused
orStopped
.- Since:
3.1
- Returns:
True if the expression is an array.
- Return type:
bool
- bool IsCollection()¶
Returns true if this expression is a collection (list or set), false otherwise. Only allowed in states
Paused
orStopped
.- Since:
5.5
- Returns:
True if the expression is a collection.
- Return type:
bool
- bool IsFunction()¶
Returns true if this expression is a function, false otherwise. Only allowed in states
Paused
orStopped
.- Since:
6.0
- Returns:
True if the expression is a function.
- void AddOperand(HxExpression expr)¶
- void AddOperand(long constant)
- void AddOperand(double constant)
Adds the given operand to this expression. Only allowed in state
Modeling
.- Arguments:
expr – Operand to add.
- void AddOperands(IEnumerable<HxExpression> operands)¶
- void AddOperands(IEnumerable<long> operands)
- void AddOperands(IEnumerable<double> operands)
- void AddOperands(params HxExpression[] operands)
- void AddOperands(params long[] operands)
- void AddOperands(params double[] operands)
Add the given operands to the expression.
- Arguments:
operands – The operands to be added.
- HxExpression GetOperand(int operandIndex)¶
Gets the operand with the given index.
- Arguments:
operandIndex – Index of the operand.
- Returns:
Operand.
- Return type:
- void SetOperand(int operandIndex, HxExpression operand)¶
- void SetOperand(int operandIndex, long constant)
- void SetOperand(int operandIndex, double constant)
Replaces the operand of the given index.
- Arguments:
operandIndex (int) – Index of the operand to change
operand – New operand
- int GetNbOperands()¶
Gets the number of operands of this expression.
- Returns:
Number of operands.
- Return type:
int
- void SetValue(long value)¶
Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in state
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 for
HxSolution.SetIntValue(HxExpression, long)
and has the same behavior asHxExpression.SetIntValue(long)
.- Arguments:
value (long) – Value assigned to this expression.
- See:
- See:
- See:
- void SetValue(double value)
Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in state :field`~HxState.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 for
HxSolution.SetDoubleValue(HxExpression, double)
and has the same behavior asHxExpression.SetDoubleValue(double)
.- Arguments:
value (double) – Value assigned to this expression.
- See:
- See:
- void 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 :field`~HxState.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 for
HxSolution.SetIntervalValue(HxExpression, HxInterval)
and has the same behavior asHxExpression.SetIntervalValue(HxInterval)
.- Arguments:
value (HxInterval) – Value assigned to this expression.
- See:
- See:
- void SetIntValue(long value)¶
Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in state
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 for
HxSolution.SetIntValue(HxExpression, long)
.- Since:
3.0
- Arguments:
value (long) – Value assigned to this expression.
- See:
- See:
- See:
- void SetDoubleValue(double value)¶
Sets the value of this expression in the current solution found by the optimizer. Only allowed for decisions. Only allowed in state
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 for
HxSolution.SetDoubleValue(HxExpression, double)
.- Since:
3.0
- Arguments:
value (double) – Value assigned to this expression.
- See:
- See:
- void 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
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 for
HxSolution.SetIntervalValue(HxExpression, HxInterval)
.- Since:
12.0
- Arguments:
value (HxInterval) – Value assigned to this expression.
- See:
- See:
- long GetValue()¶
Gets the value of this expression in the best solution found by the optimizer. Only allowed in states
Paused
orStopped
. Only allowed if this expression is an integer or a boolean.This method is a shortcut for
HxSolution.GetIntValue(HxExpression)
and has the same behavior asHxExpression.GetIntValue(HxExpression)
.- Returns:
Value in the best solution.
- Return type:
long
- See:
- See:
- See:
- long GetIntValue()¶
Gets the value of this expression in the best solution found by the optimizer. Only allowed in states
Paused
orStopped
. Only allowed if this expression is an integer or a boolean.This method is a shortcut for
HxSolution.GetIntValue(HxExpression)
.- Since:
3.0
- Returns:
Value in the best solution.
- Return type:
long
- See:
- See:
- See:
- double GetDoubleValue()¶
Gets the value of this expression in the best solution found by the optimizer. Only allowed in states
Paused
orStopped
. Only allowed if this expression is a double.This method is a shortcut for
HxSolution.GetDoubleValue(HxExpression)
.- Since:
3.0
- Returns:
Value in the best solution.
- Return type:
double
- See:
- See:
- double GetIntervalValue()¶
Gets the value of this expression in the best solution found by the optimizer. Only allowed in states
Paused
orStopped
. Only allowed if this expression is an interval.This method is a shortcut for
HxSolution.GetIntervalValue(HxExpression)
.- Since:
12.0
- Returns:
Value in the best solution.
- Return type:
- See:
- See:
- HxCollection GetCollectionValue()¶
Gets the value of this expression in the best solution found by the optimizer. Only allowed in states
Paused
orStopped
. Only allowed if this expression is a collection.This method is a shortcut for
HxSolution.GetCollectionValue(HxExpression)
.- Since:
5.5
- Returns:
Value in the best solution.
- Return type:
- See:
- See:
- HxArray GetArrayValue()¶
Gets the value of this expression in the best solution found by the optimizer. Only allowed in states
Paused
orStopped
. Only allowed if this expression is an array.This method is a shortcut for
HxSolution.GetArrayValue(HxExpression)
.- Since:
7.5
- Returns:
Value in the best solution.
- Return type:
- See:
- See:
- HxExternalContext GetExternalContext()¶
Gets the external function context of this expression. Only allowed if this expression is an external function.
- Since:
9.5
- Returns:
Context of the external function
- Return type:
- bool IsViolated()¶
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 and its value is NaN (Not A Number).
It is an integer or boolean with no valid value (arithmetic or out of bounds exception).
Only allowed in states
Paused
orStopped
. This method is a shortcut forHxSolution.IsViolated(HxExpression)
.- Since:
5.5
- Returns:
True if this expression is violated in the best solution.
- Return type:
bool
- bool IsUndefined()¶
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
Paused
orStopped
. This method is a shortcut forHxSolution.IsUndefined(HxExpression)
.- Since:
7.0
- Returns:
True if this expression has an undefined value in the best solution.
- Return type:
bool
- void SetName(string name)¶
Sets the name of this expression. Only allowed in state
Modeling
. The name cannot be empty. Two operators of the model cannot share the same name. Useful for debugging or logging purposes.- Arguments:
name (string) – Name.
- bool IsNamed()¶
Returns true if this expression has a name, and false otherwise.
- Returns:
True if named.
- Return type:
bool
- string GetName()¶
Gets the name of this expression or the empty string if no name has been set.
- Returns:
Name.
- Return type:
string
- string 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.
- Return type:
string
Overloaded operators and indexers¶
- HxExpression operator +(HxExpression expr1, HxExpression expr2)¶
- HxExpression operator +(HxExpression expr1, long expr2)
- HxExpression operator +(HxExpression expr1, double expr2)
- HxExpression operator +(long expr1, HxExpression expr2)
- HxExpression operator +(double expr1, HxExpression expr2)
Creates a new
HxOperator.Sum
expression. It is a shortcut formodel.CreateExpression(HxOperator.Sum, expr1, expr2)
.- Arguments:
expr1 – First operand. Can be an HxExpression, an integer or a double.
expr2 – Second operand. Can be an HxExpression, an integer or a double.
- Returns:
A new
HxOperator.Sum
expression- Return type:
- HxExpression operator -(HxExpression expr1, HxExpression expr2)¶
- HxExpression operator -(HxExpression expr1, long expr2)
- HxExpression operator -(HxExpression expr1, double expr2)
- HxExpression operator -(long expr1, HxExpression expr2)
- HxExpression operator -(double expr1, HxExpression expr2)
Creates a new
HxOperator.Sub
expression. It is a shortcut formodel.CreateExpression(HxOperator.Sub, expr1, expr2)
.- Arguments:
expr1 – First operand. Can be an HxExpression, an integer or a double.
expr2 – Second operand. Can be an HxExpression, an integer or a double.
- Returns:
A new
HxOperator.Sub
expression- Return type:
- HxExpression operator *(HxExpression expr1, HxExpression expr2)¶
- HxExpression operator *(HxExpression expr1, long expr2)
- HxExpression operator *(HxExpression expr1, double expr2)
- HxExpression operator *(long expr1, HxExpression expr2)
- HxExpression operator *(double expr1, HxExpression expr2)
Creates a new
HxOperator.Prod
expression. It is a shortcut formodel.CreateExpression(HxOperator.Prod, expr1, expr2)
.- Arguments:
expr1 – First operand. Can be an HxExpression, an integer or a double.
expr2 – Second operand. Can be an HxExpression, an integer or a double.
- Returns:
A new
HxOperator.Prod
expression- Return type:
- HxExpression operator /(HxExpression expr1, HxExpression expr2)¶
- HxExpression operator /(HxExpression expr1, long expr2)
- HxExpression operator /(HxExpression expr1, double expr2)
- HxExpression operator /(long expr1, HxExpression expr2)
- HxExpression operator /(double expr1, HxExpression expr2)
Creates a new
HxOperator.Div
expression. It is a shortcut formodel.CreateExpression(HxOperator.Div, expr1, expr2)
.- Arguments:
expr1 – First operand. Can be an HxExpression, an integer or a double.
expr2 – Second operand. Can be an HxExpression, an integer or a double.
- Returns:
A new
HxOperator.Div
expression- Return type:
- HxExpression operator %(HxExpression expr1, HxExpression expr2)¶
- HxExpression operator %(HxExpression expr1, long expr2)
- HxExpression operator %(long expr1, HxExpression expr2)
Creates a new
HxOperator.Mod
expression. It is a shortcut formodel.CreateExpression(HxOperator.Mod, expr1, expr2)
.- Arguments:
expr1 – First operand. Can be an HxExpression or an integer.
expr2 – Second operand. Can be an HxExpression or an integer.
- Returns:
A new
HxOperator.Mod
expression- Return type:
- HxExpression operator !(HxExpression expr)¶
Creates a new
HxOperator.Not
expression. It is a shortcut formodel.create_expression(HxOperator.Not, expr)
.- Returns:
A new
HxOperator.Not
expression- Return type:
- HxExpression operator &(HxExpression expr1, HxExpression expr2)¶
Creates a new
HxOperator.And
expression. It is a shortcut formodel.CreateExpression(HxOperator.And, expr1, expr2)
.- Arguments:
expr1 (HxExpression) – First operand.
expr2 (HxExpression) – Second operand.
- Returns:
A new
HxOperator.And
expression- Return type:
- HxExpression operator |(HxExpression expr1, HxExpression expr2)¶
Creates a new
HxOperator.Or
expression. It is a shortcut formodel.CreateExpression(HxOperator.Or, expr1, expr2)
.- Arguments:
expr1 (HxExpression) – First operand.
expr2 (HxExpression) – Second operand.
- Returns:
A new
HxOperator.Or
expression- Return type:
- HxExpression operator ^(HxExpression expr1, HxExpression expr2)¶
Creates a new
HxOperator.Xor
expression. It is a shortcut formodel.CreateExpression(HxOperator.Xor, expr1, expr2)
.- Arguments:
expr1 (HxExpression) – First operand.
expr2 (HxExpression) – Second operand.
- Returns:
A new
HxOperator.And
expression- Return type:
- HxExpression operator ==(HxExpression expr1, HxExpression expr2)¶
- HxExpression operator ==(HxExpression expr1, long expr2)
- HxExpression operator ==(HxExpression expr1, double expr2)
- HxExpression operator ==(long expr1, HxExpression expr2)
- HxExpression operator ==(double expr1, HxExpression expr2)
Creates a new
HxOperator.Eq
expression. It is a shortcut formodel.CreateExpression(HxOperator.Eq, expr1, expr2)
.- Arguments:
expr1 (HxExpression) – First operand.
expr2 (HxExpression) – Second operand.
- Returns:
A new
HxOperator.Eq
expression- Return type:
- HxExpression operator !=(HxExpression expr1, HxExpression expr2)¶
- HxExpression operator !=(HxExpression expr1, long expr2)
- HxExpression operator !=(HxExpression expr1, double expr2)
- HxExpression operator !=(long expr1, HxExpression expr2)
- HxExpression operator !=(double expr1, HxExpression expr2)
Creates a new
HxOperator.Neq
expression. It is a shortcut formodel.CreateExpression(HxOperator.Neq, expr1, expr2)
.- Arguments:
expr1 (HxExpression) – First operand.
expr2 (HxExpression) – Second operand.
- Returns:
A new
HxOperator.Neq
expression- Return type:
- HxExpression operator >=(HxExpression expr1, HxExpression expr2)¶
- HxExpression operator >=(HxExpression expr1, long expr2)
- HxExpression operator >=(HxExpression expr1, double expr2)
- HxExpression operator >=(long expr1, HxExpression expr2)
- HxExpression operator >=(double expr1, HxExpression expr2)
Creates a new
HxOperator.Geq
expression. It is a shortcut formodel.CreateExpression(HxOperator.Geq, expr1, expr2)
.- Arguments:
expr1 (HxExpression) – First operand.
expr2 (HxExpression) – Second operand.
- Returns:
A new
HxOperator.Geq
expression- Return type:
- HxExpression operator <=(HxExpression expr1, HxExpression expr2)¶
- HxExpression operator <=(HxExpression expr1, long expr2)
- HxExpression operator <=(HxExpression expr1, double expr2)
- HxExpression operator <=(long expr1, HxExpression expr2)
- HxExpression operator <=(double expr1, HxExpression expr2)
Creates a new
HxOperator.Leq
expression. It is a shortcut formodel.CreateExpression(HxOperator.Leq, expr1, expr2)
.- Arguments:
expr1 (HxExpression) – First operand.
expr2 (HxExpression) – Second operand.
- Returns:
A new
HxOperator.Neq
expression- Return type:
- HxExpression operator >(HxExpression expr1, HxExpression expr2)¶
- HxExpression operator >(HxExpression expr1, long expr2)
- HxExpression operator >(HxExpression expr1, double expr2)
- HxExpression operator >(long expr1, HxExpression expr2)
- HxExpression operator >(double expr1, HxExpression expr2)
Creates a new
HxOperator.Gt
expression. It is a shortcut formodel.CreateExpression(HxOperator.Gt, expr1, expr2)
.- Arguments:
expr1 (HxExpression) – First operand.
expr2 (HxExpression) – Second operand.
- Returns:
A new
HxOperator.Gt
expression- Return type:
- HxExpression operator <(HxExpression expr1, HxExpression expr2)¶
- HxExpression operator <(HxExpression expr1, long expr2)
- HxExpression operator <(HxExpression expr1, double expr2)
- HxExpression operator <(long expr1, HxExpression expr2)
- HxExpression operator <(double expr1, HxExpression expr2)
Creates a new
HxOperator.Lt
expression. It is a shortcut formodel.CreateExpression(HxOperator.Lt, expr1, expr2)
.- Arguments:
expr1 (HxExpression) – First operand.
expr2 (HxExpression) – Second operand.
- Returns:
A new
HxOperator.Lt
expression- Return type:
- HxExpression this(long index)¶
- HxExpression this(HxExpression index)
- HxExpression this(HxExpression index1, HxExpression index2)
- HxExpression this(HxExpression index1, long index2)
- HxExpression this(long index1, HxExpression index2)
- HxExpression this(long index1, long index2)
Creates a new
HxOperator.At
expression. It is a shortcut formodel.CreateExpression(HxOperator.At, index, ...)
.- Returns:
A new
HxOperator.At
expression- Return type: