HxExpression Class

class 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

Summary

Methods

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.

isConstant

Returns true if this expression is typed as constant in the model, 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.

isDouble

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

isCollection

Returns true if this expression is a collection (list or set), false otherwise.

isArray

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

isFunction

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

isRange

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

isViolated

Returns true if the given expression is violated in the best solution found by the solver.

isUndefined

Returns true if the given expression has an undefined value in the best solution found by the solver.

isNamed

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

Overloaded operators

pos

Returns the same expression without change.

neg

Returns a new expression that is the opposite of the current expression.

add

Returns a new expression that is the sum of the current expression and the argument other.

sub

Returns a new expression that is the substraction of the current expression and the argument other.

mul

Returns a new expression that is the product of the current expression and the argument other.

div

Returns a new expression that is the division of the current expression and the argument other.

mod

Returns a new expression that is the remainder of the integer division of the current expression and the argument other.

not

Returns a new expression that is the negative of the current expression.

and

Returns a new expression that is the logical and of the current expression and the argument other.

or

Returns a new expression that is the logical or of the current expression and the argument other.

lt

Returns a new strictly lower expression between the current expression and the argument other.

leq

Returns a new lower or equal expression between the current expression and the argument other.

gt

Returns a new strictly greater expression between the current expression and the argument other.

geq

Returns a new greater or equal expression between the current expression and the argument other.

eq

Returns a new equal expression between the current expression and the argument other.

neq

Returns a new not equal expression between the current expression and the argument other.

range

Returns a new range expression between the current expression and the argument other.

ternary

Returns a new if-then-else expression (also called the ternary operator).

linkable

This operator is applied when the <- sign is used on an HxExpression.

assignable

This operator is applied when the = sign is used on an HxExpression.

modify

This operator is called when an expression is used with one of the three special modifiers : MINIMIZE, MAXIMIZE or CONSTRAINT.

Fields

HxExpression.operator

Operator of this expression returned as a string.

Return type:

string

HxExpression.index

Index of this expression in the model.

Return type:

int

HxExpression.operands

This field returns a readonly map-like structure containing all the operands of this expression. The returned structure has the following features:

  • A count field to get the number of operands, e.g. operands.count().

  • An overloaded index [] operator to get a specific operand, e.g. operands[0]. The index must be between 0 and operands.count() - 1. Accessing a value outside these bounds throws an exception.

  • An overloaded iterator operator to iterate over the operands with a for statement.

Return type:

map-like structure containing objects of type HxExpression.

HxExpression.nbOperands

Number of operands of this expression.

Return type:

int

HxExpression.name

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

This attribute is read-write but it can only be changed in state MODELING.

Return type:

String

HxExpression.value

Value of this expression in the best solution found by the solver. This method is a shortcut for HxSolution.getValue() and HxSolution.setValue().

The type of the returned value depends on the type of the expression. It can be a number if the expression has an integer or double value, an array if the expression is an array, or a collection if the expression is a list or a set decision.

This attribute is read-write but it can only be changed in state STOPPED and queried in states PAUSED or STOPPED.

Return type:

a number, an array or a collection depending on the type of the expression.

HxExpression.context

External function context of this expression. Only set and allowed if this expression is an external function.

Return type:

HxExternalContext

Methods

HxExpression.isDecision()

Returns true if this expression is typed as decision in the model, false otherwise.

Return type:

bool

HxExpression.isConstraint()

Returns true if this expression is tagged as constraint in the model, false otherwise.

Return type:

bool

HxExpression.isObjective()

Returns true if this expression is tagged as objective in the model, false otherwise.

Return type:

bool

HxExpression.isConstant()

Returns true if this expression is typed as constant in the model, false otherwise.

Return type:

bool

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

Return type:

bool

HxExpression.isBool()

Returns true if this expression is a boolean (ie 0 or 1), false otherwise. Only allowed in states PAUSED or STOPPED.

Return type:

bool

HxExpression.isDouble()

Returns true if this expression is a double, false otherwise. Only allowed in states PAUSED or STOPPED.

Return type:

bool

HxExpression.isCollection()

Returns true if this expression is a collection (list or set), false otherwise. Only allowed in states PAUSED or STOPPED.

Return type:

bool

HxExpression.isArray()

Returns true if this expression is an array, false otherwise. Only allowed in states PAUSED or STOPPED.

Return type:

bool

HxExpression.isFunction()

Returns true if this expression is a function, false otherwise. Only allowed in states PAUSED or STOPPED.

Return type:

bool

HxExpression.isRange()

Returns true if this expression is a range, false otherwise. Only allowed in states PAUSED or STOPPED.

Return type:

bool

HxExpression.isViolated()

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

Return type:

bool

HxExpression.isUndefined()

Returns true if the given expression has an undefined value in the best solution found by the solver. 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().

Return type:

bool

HxExpression.isNamed()

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

Return type:

bool

Overloaded operators

HxExpression.pos()

Returns the same expression without change.

Return type:

HxExpression

HxExpression.neg()

Returns a new expression that is the opposite of the current expression.

Return type:

HxExpression

HxExpression.add(other)
HxExpression.radd(other)

Returns a new expression that is the sum of the current expression and the argument other. This operator exists in two versions depending on the position of the current expression in the addition (left or right).

Note that in some cases, this operator can return one of the two operands rather than creating a new expression (sum with constant 0).

Parameters:

other – Can be a bool, an integer, a double or another HxExpression

Return type:

HxExpression

HxExpression.sub(other)
HxExpression.rsub(other)

Returns a new expression that is the substraction of the current expression and the argument other. This operator exists in two versions depending on the position of the current expression in the substraction (left or right).

Note that in some cases, this operator can return the left operand instead of creating a new expression if the right operand is the constant 0.

Parameters:

other – Can be a bool, an integer, a double or another HxExpression

Return type:

HxExpression

HxExpression.mul(other)
HxExpression.rmul(other)

Returns a new expression that is the product of the current expression and the argument other. This operator exists in two versions depending on the position of the current expression in the product (left or right).

Note that in some cases, this operator can return one of the two operands rather than creating a new expression (product with constant 1) or returns the HxExpression representing the constant 0 (product with constant 0).

Parameters:

other – Can be a bool, an integer, a double or another HxExpression

Return type:

HxExpression

HxExpression.div(other)
HxExpression.rdiv(other)

Returns a new expression that is the division of the current expression and the argument other. This operator exists in two versions depending on the position of the current expression in the division (left or right).

Note that in some cases, this operator can return the left operand instead of creating a new expression if the right operand is the constant 1.

Parameters:

other – Can be a bool, an integer, a double or another HxExpression

Return type:

HxExpression

HxExpression.mod(other)
HxExpression.rmod(other)

Returns a new expression that is the remainder of the integer division of the current expression and the argument other. This operator exists in two versions depending on the position of the current expression in the modulo (left or right).

Note that in some cases, this operator can return the HxExpression representing the constant 0 if the right operand is the constant 1.

Parameters:

other – Can be a bool, an integer or another HxExpression

Return type:

HxExpression

HxExpression.not(other)

Returns a new expression that is the negative of the current expression. NOT(a) = 1 - a.

Return type:

HxExpression

HxExpression.and(other)
HxExpression.rand(other)

Returns a new expression that is the logical and of the current expression and the argument other. This operator exists in two versions depending on the position of the current expression in the product (left or right).

Note that in some cases, this operator can return one of the two operands rather than creating a new expression (logical and with constant 1 or true) or returns the HxExpression representing the constant 0 (logical and with constant 0 or false).

Parameters:

other – Can be a bool or another HxExpression

Return type:

HxExpression

HxExpression.or(other)
HxExpression.ror(other)

Returns a new expression that is the logical or of the current expression and the argument other. This operator exists in two versions depending on the position of the current expression in the product (left or right).

Note that in some cases, this operator can return one of the two operands rather than creating a new expression (logical or with constant 0 or false) or returns the HxExpression representing the constant 1 (logical or with constant 1 or true).

Parameters:

other – Can be a bool or another HxExpression

Return type:

HxExpression

HxExpression.lt(other)
HxExpressionr.rlt(other)

Returns a new strictly lower expression between the current expression and the argument other. This operator exists in two versions depdending on the position of the current expression (left or right).

Parameters:

other – Can be a bool, an integer, a double or another HxExpression

Return type:

HxExpression

HxExpression.leq(other)
HxExpression.rleq(other)

Returns a new lower or equal expression between the current expression and the argument other. This operator exists in two versions depdending on the position of the current expression (left or right).

Parameters:

other – Can be a bool, an integer, a double or another HxExpression

Return type:

HxExpression

HxExpression.gt(other)
HxExpressionr.rgt(other)

Returns a new strictly greater expression between the current expression and the argument other. This operator exists in two versions depdending on the position of the current expression (left or right).

Parameters:

other – Can be a bool, an integer, a double or another HxExpression

Return type:

HxExpression

HxExpression.geq(other)
HxExpression.rgeq(other)

Returns a new greater or equal expression between the current expression and the argument other. This operator exists in two versions depdending on the position of the current expression (left or right).

Parameters:

other – Can be a bool, an integer, a double or another HxExpression

Return type:

HxExpression

HxExpression.eq(other)
HxExpressionr.req(other)

Returns a new equal expression between the current expression and the argument other. This operator exists in two versions depdending on the position of the current expression (left or right).

Parameters:

other – Can be a bool, an integer, a double or another HxExpression

Return type:

HxExpression

HxExpression.neq(other)
HxExpression.rneq(other)

Returns a new not equal expression between the current expression and the argument other. This operator exists in two versions depdending on the position of the current expression (left or right).

Parameters:

other – Can be a bool, an integer, a double or another HxExpression

Return type:

HxExpression

HxExpression.range(other)
HxExpression.rrange(other)

Returns a new range expression between the current expression and the argument other. This operator exists in two versions depdending on the position of the current expression (left or right).

Parameters:

other – Can be a bool, an integer, a double or another HxExpression

Return type:

HxExpression

HxExpression.ternary(trueValue, falseValue)

Returns a new if-then-else expression (also called the ternary operator). The current expression is used as the condition and the arguments as true and false values respectively.

Parameters:
  • trueValue – Can be a bool, an integer, a double or an HxExpression

  • falseValue – Can be a bool, an integer, a double or an HxExpression

Return type:

HxExpression

HxExpression.index(index)

Returns a new at expression. The current expression is used as the array and the argument as the index.

Parameters:

index – Can be a bool, an integer or another expression

Return type:

HxExpression

HxExpression.linkable()

This operator is applied when the <- sign is used on an HxExpression. It only returns the current HxExpression, without changing anything

HxExpression.assignable()

This operator is applied when the = sign is used on an HxExpression. The implemented behavior is to throw an exception. HxExpressions can only be manipulated with the <- operator.

HxExpression.modify({MINIMIZE, MAXIMIZE, CONSTRAINT})

This operator is called when an expression is used with one of the three special modifiers : MINIMIZE, MAXIMIZE or CONSTRAINT. It adds the expression to the list of objectives or constraints of the current model.