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:HxModel
See:HxOperator

Summary

Methods
GetModel Returns the model object associated to this expression.
GetOptimizer Returns the Hexaly Optimizer object associated to this expression.
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.
AddOperands Add the given operands to the 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 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.
Overloaded operators
operator + Creates a new HxOperator.Sum expression.
operator - Creates a new HxOperator.Sub expression.
operator * Creates a new HxOperator.Prod expression.
operator / Creates a new HxOperator.Div expression.
operator % Creates a new HxOperator.Mod expression.
operator ! Creates a new HxOperator.Not expression.
operator & Creates a new HxOperator.And expression.
operator | Creates a new HxOperator.Or expression.
operator ^ Creates a new HxOperator.Xor expression.
operator == Creates a new HxOperator.Eq expression.
operator != Creates a new HxOperator.Neq expression.
operator >= Creates a new HxOperator.Geq expression.
operator <= Creates a new HxOperator.Leq expression.
operator > Creates a new HxOperator.Gt expression.
operator < Creates a new HxOperator.Lt expression.
this Creates a new HxOperator.At expression.

Instance methods

HxModel GetModel()

Returns the model object associated to this expression.

Returns:HxModel object
Return type:HxModel
HexalyOptimizer GetOptimizer()

Returns the Hexaly Optimizer object associated to this expression.

Returns:Hexaly Optimizer object
Return type:HexalyOptimizer
HxOperator GetOperator()

Gets the operator of this expression.

Returns:Operator.
Return type:HxOperator
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 or Stopped.

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 or Stopped. 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 or Stopped.

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 or Stopped.

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 or Stopped.

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 or Stopped.

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 or Stopped.

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

Arguments:value (long) – Value assigned to this expression.
See:HxSolution.SetIntValue(HxExpression, long)
See:HxExpression.IsInt
See:HxExpression.IsBool
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 as HxExpression.SetDoubleValue(double).

Arguments:value (double) – Value assigned to this expression.
See:HxSolution.SetDoubleValue(HxExpression, double)
See:HxExpression.IsDouble
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 as HxExpression.SetIntervalValue(HxInterval).

Arguments:value (HxInterval) – Value assigned to this expression.
See:HxSolution.SetIntervalValue(HxExpression, HxInterval)
See:HxExpression.IsInterval
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:HxSolution.SetIntValue
See:HxExpression.IsInt
See:HxExpression.IsBool
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:HxSolution.SetDoubleValue
See:HxExpression.IsDouble
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:HxSolution.SetIntervalValue
See:HxExpression.IsInterval
long GetValue()

Gets the value of this expression in the best solution found by the optimizer. Only allowed in states Paused or Stopped. 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 as HxExpression.GetIntValue(HxExpression).

Returns:Value in the best solution.
Return type:long
See:HxSolution.GetValue
See:HxExpression.IsInt
See:HxExpression.IsBool
long GetIntValue()

Gets the value of this expression in the best solution found by the optimizer. Only allowed in states Paused or Stopped. 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:HxSolution.GetIntValue
See:HxExpression.IsInt
See:HxExpression.IsBool
double GetDoubleValue()

Gets the value of this expression in the best solution found by the optimizer. Only allowed in states Paused or Stopped. 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:HxSolution.GetDoubleValue
See:HxExpression.IsDouble
double GetIntervalValue()

Gets the value of this expression in the best solution found by the optimizer. Only allowed in states Paused or Stopped. 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:HxInterval
See:HxSolution.GetIntervalValue
See:HxExpression.IsInterval
HxCollection GetCollectionValue()

Gets the value of this expression in the best solution found by the optimizer. Only allowed in states Paused or Stopped. 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:HxCollection
See:HxSolution.GetCollectionValue
See:HxExpression.IsCollection
HxArray GetArrayValue()

Gets the value of this expression in the best solution found by the optimizer. Only allowed in states Paused or Stopped. 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:HxArray
See:HxSolution.GetCollectionValue
See:HxExpression.IsArray
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:HxExternalContext
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 or Stopped. This method is a shortcut for HxSolution.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 or Stopped. This method is a shortcut for HxSolution.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 for model.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

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 for model.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

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 for model.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

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 for model.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

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 for model.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

HxExpression operator !(HxExpression expr)

Creates a new HxOperator.Not expression. It is a shortcut for model.create_expression(HxOperator.Not, expr).

Returns:A new HxOperator.Not expression
Return type:HxExpression
HxExpression operator &(HxExpression expr1, HxExpression expr2)

Creates a new HxOperator.And expression. It is a shortcut for model.CreateExpression(HxOperator.And, expr1, expr2).

Arguments:
Returns:

A new HxOperator.And expression

Return type:

HxExpression

HxExpression operator |(HxExpression expr1, HxExpression expr2)

Creates a new HxOperator.Or expression. It is a shortcut for model.CreateExpression(HxOperator.Or, expr1, expr2).

Arguments:
Returns:

A new HxOperator.Or expression

Return type:

HxExpression

HxExpression operator ^(HxExpression expr1, HxExpression expr2)

Creates a new HxOperator.Xor expression. It is a shortcut for model.CreateExpression(HxOperator.Xor, expr1, expr2).

Arguments:
Returns:

A new HxOperator.And expression

Return type:

HxExpression

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 for model.CreateExpression(HxOperator.Eq, expr1, expr2).

Arguments:
Returns:

A new HxOperator.Eq expression

Return type:

HxExpression

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 for model.CreateExpression(HxOperator.Neq, expr1, expr2).

Arguments:
Returns:

A new HxOperator.Neq expression

Return type:

HxExpression

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 for model.CreateExpression(HxOperator.Geq, expr1, expr2).

Arguments:
Returns:

A new HxOperator.Geq expression

Return type:

HxExpression

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 for model.CreateExpression(HxOperator.Leq, expr1, expr2).

Arguments:
Returns:

A new HxOperator.Neq expression

Return type:

HxExpression

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 for model.CreateExpression(HxOperator.Gt, expr1, expr2).

Arguments:
Returns:

A new HxOperator.Gt expression

Return type:

HxExpression

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 for model.CreateExpression(HxOperator.Lt, expr1, expr2).

Arguments:
Returns:

A new HxOperator.Lt expression

Return type:

HxExpression

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 for model.CreateExpression(HxOperator.At, index, ...).

Returns:A new HxOperator.At expression
Return type:HxExpression