HxModel Class¶
- class hexaly.optimizer.HxModel¶
Mathematical optimization model. A model is composed of expressions (some of which are decisions), organized as a Directed Acyclic Graph (DAG). Then, some expressions of the model can be constrained or optimized. Once your optimization model is created and closed, the optimizer can be launched to solve it. Note that you cannot modify a model which has been closed: you must reopen it (with
open()
) or instantiate another Hexaly Optimizer environment to optimize another model.
Summary¶
Number of expressions in this model. |
|
Number of operands in this model. |
|
Number of objectives in this model. |
|
Number of constraints in this model. |
|
Number of decisions in this model. |
|
List of the expressions of the model. |
|
List of the decisions of the model. |
|
List of the objectives of the model. |
|
List of the objective directions of the model. |
|
List of the constraints of the model. |
Creates a constant expression representing the given value. |
|
Creates a new expression of the given type with the given operands. |
|
Creates a lambda function with arguments. |
|
Shortcut for create_lambda_function(). |
|
Creates an integer external function. |
|
Shortcut for create_int_external_function(). |
|
Creates a double external function. |
|
Shortcut for create_double_external_function(). |
|
Creates an integer array external function. |
|
Shortcut for create_int_array_external_function(). |
|
Creates a double array external function. |
|
Shortcut for create_double_array_external_function(). |
|
Returns the number of expressions added to this model. |
|
Gets the expression with the given index or the given name in this model. |
|
Gets the number of decisions in the model. |
|
Gets the decision with the given index. |
|
Adds the given expression to the list of constraints. |
|
Shortcut for add_constraint(). |
|
Removes the given expression from the list of constraints. |
|
Gets the number of constraints added to this model. |
|
Gets the constraint with the given index. |
|
Adds the given expression to the list of objectives to optimize. |
|
Shortcut for add_objective(expr, HxObjectiveDirection.MINIMIZE). |
|
Shortcut for add_objective(expr, HxObjectiveDirection.MAXIMIZE). |
|
Removes the objective at the given position in the list of objectives. |
|
Gets the number of objectives added to this model. |
|
Gets the objective with the given index. |
|
Gets the direction of the objective with the given index. |
|
Gets the number of operands in the model. |
|
Closes the model. |
|
Reopens the model. |
|
Returns true if the model is closed, false otherwise. |
|
Creates a boolean decision. |
|
Creates a float decision. |
|
Creates an integer decision. |
|
Creates an interval decision included in [minStart, maxEnd). |
|
Creates a hull expression. |
|
Creates a sum expression. |
|
Creates a substraction expression. |
|
Creates a product expression. |
|
Creates a max expression. |
|
Creates a min expression. |
|
Creates a boolean or expression. |
|
Creates a boolean and expression. |
|
Creates a boolean xor expression. |
|
Creates a boolean not expression. |
|
Creates an equality expression. |
|
Creates a disequality expression. |
|
Creates an inequality ‘greater than or equal to’. |
|
Creates an inequality ‘lower than or equal to’. |
|
Creates an inequality ‘strictly greater than’. |
|
Creates an inequality ‘strictly lower than’. |
|
Creates a ternary conditional operator. |
|
Creates an absolute value expression. |
|
Creates a distance expression. |
|
Creates a division expression. |
|
Creates a modulo expression. |
|
Creates a new array. |
|
Creates a new step array. |
|
Creates a “at” expression. |
|
Creates a scalar product between two arrays. |
|
Creates a ceil expression. |
|
Creates a floor expression. |
|
Creates a round expression. |
|
Creates a square root expression. |
|
Creates a natural log expression. |
|
Creates an exponential expression. |
|
Creates a power expression. |
|
Creates a cosine expression. |
|
Creates a sine expression. |
|
Creates a tangent expression. |
|
Creates a piecewise linear expression. |
|
Creates a list decision with the given length. |
|
Creates a set decision with the given length. |
|
Creates a start expression. |
|
Creates an end expression. |
|
Creates a length expression. |
|
Creates a count expression. |
|
Creates an indexOf expression. |
|
Creates a distinct expression. |
|
Creates an intersection expression. |
|
Creates a contains expression. |
|
Creates a partition expression. |
|
Creates a disjoint expression. |
|
Creates a cover expression. |
|
Creates a find expression. |
|
Creates a sort expression. |
|
Creates a call expression. |
|
Creates a range expression. |
Returns a string representation of this model. |
Instance methods¶
- HxModel.create_constant(value)¶
Creates a constant expression representing the given value. The given value can be a boolean, an integer or a double. Only allowed in state
HxState.MODELING
. Note that if a constant has been already created with the same value, this method can return the same expression, but it is not guaranteed. The exact behavior is implementation defined.- Parameters:
value – Value of the constant (can be a boolean, integer or double).
- Returns:
Created constant expression
- Return type:
- HxModel.create_expression(operator)¶
- hexaly.optimizer.create_expression(operator, operands)¶
- hexaly.optimizer.create_expression(operator, *operands)
Creates a new expression of the given type with the given operands. Only allowed in state
HxState.MODELING
. This method cannot be used to create constants: useHxModel.create_constant()
instead.The operands parameter accept any object that implements the
__iter__
method. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments.Each operand can be an HxExpression, a boolean, an integer or a double.
- Since:
5.5
- Parameters:
operator (HxOperator) – Type of the expression to create.
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Created expression
- Return type:
- HxModel.create_lambda_function(function)¶
Creates a lambda function with arguments. A lambda function is a particular expression composed of two parts:
The arguments of the function (which are also HxExpressions of type
HxOperator.ARGUMENT
).The body of the function. The body is an HxExpression that will be used to evaluate the result of the function. The body can be any HxExpression composed of any operands and operators supported by Hexaly Optimizer. Thus, the body expression can use the arguments of the function but can also capture and refer to expressions declared outside of the function.
The function you provide will not be used directly during the solving process, but will be evaluated once by the API, with a number of HxExpression of type
HxOperator.ARGUMENT
that corresponds to the number of arguments you want and your function expects. At the end of the evaluation of your function, the returned HxExpression will be used as the body of the Hexaly Optimizer function.- Since:
9.5
- Parameters:
function – A python function that accepts
HxExpression
as arguments and returns anHxExpression
that will be used as the body of the new Hexaly Optimizer function you want to create.- Returns:
Expression of type
HxOperator.LAMBDA_FUNCTION
- Return type:
- HxModel.lambda_function(function)¶
Shortcut for
create_lambda_function()
.- Since:
9.5
- Parameters:
function – A python function that accepts
HxExpression
as arguments and returns anHxExpression
that will be used as the body of the new Hexaly Optimizer function you want to create.- Returns:
Expression of type
HxOperator.LAMBDA_FUNCTION
- Return type:
- HxModel.create_int_external_function(function)¶
Creates an integer external function. The provided function must take the external argument values (
HxExternalArgumentValues
) associated with the function as single argument and must return an integer value. When the external function is called, the argument values will be made accessible to your function through theHxExternalArgumentValues
.Once you have instantiated it, you have to use
call()
to call it in your model.Note 1: Most of the time your external function will be called when the optimizer is in state
HxState.RUNNING
. Do not attempt to call any method of the optimizer (to retrieve statistics, values of HxExpressions or whatever) in that state or an exception will be thrown. The only accessible function isHexalyOptimizer.stop()
.Note 2: Your functions must be thread-safe. According to the
nb_threads
parameter, Hexaly Optimizer can be multi-threaded. In that case, your external functions must be thread safe. If you cannot guarantee the thread-safety of your code, we strongly recommend you to limit the search of Hexaly Optimizer to one thread withHxParam.nb_threads
.Note 3: You can provide additional data concerning your function (such as lower and upper bounds) with the help of the
HxExternalContext
associated with your function (seeHxExpression.get_external_context()
.- Since:
9.5
- Parameters:
function – A python function that accepts a
HxExternalArgumentValues
as first argument and returns an integer value.- Returns:
Expression of type
HxOperator.EXTERNAL_FUNCTION
.- Return type:
- HxModel.int_external_function(function)¶
Shortcut for
create_int_external_function()
.- Since:
9.5
- Parameters:
function – A python function that accepts a
HxExternalArgumentValues
as first argument and returns an integer value.- Returns:
Expression of type
HxOperator.EXTERNAL_FUNCTION
.- Return type:
- HxModel.create_double_external_function(function)¶
Creates a double external function. The provided function must take the external argument values (
HxExternalArgumentValues
) associated with the function as single argument and must return a double value. When the external function is called, the argument values will be made accessible to your function through theHxExternalArgumentValues
.Once you have instantiated it, you have to use
call()
to call it in your model.Note 1: Most of the time your external function will be called when the optimizer is in state
HxState.RUNNING
. Do not attempt to call any method of the optimizer (to retrieve statistics, values of HxExpressions or whatever) in that state or an exception will be thrown. The only accessible function isHexalyOptimizer.stop()
.Note 2: Your functions must be thread-safe. According to the
nb_threads
parameter, Hexaly Optimizer can be multi-threaded. In that case, your external functions must be thread safe. If you cannot guarantee the thread-safety of your code, we strongly recommend you to limit the search of Hexaly Optimizer to one thread withHxParam.nb_threads
.Note 3: You can provide additional data concerning your function (such as lower and upper bounds) with the help of the
HxExternalContext
associated with your function (seeHxExpression.get_external_context()
.- Since:
9.5
- Parameters:
function – A python function that accepts a
HxExternalArgumentValues
as first argument and returns a double value.- Returns:
Expression of type
HxOperator.EXTERNAL_FUNCTION
.- Return type:
- HxModel.double_external_function(function)¶
Shortcut for
create_double_external_function()
.- Since:
9.5
- Parameters:
function – A python function that accepts a
HxExternalArgumentValues
as first argument and returns a double value.- Returns:
Expression of type
HxOperator.EXTERNAL_FUNCTION
.- Return type:
- HxModel.create_int_array_external_function(function)¶
Creates an integer array external function. The provided function must take a (
HxExternalArgumentValues
) as single argument and must return an iterable of integer values (such as list, set or tuple ofint
). When the external function is called, the argument values will be made accessible to your function through theHxExternalArgumentValues
.Once you have instantiated it, you have to use
call()
to call it in your model.- Since:
11.0
- Parameters:
function – A python function that accepts a
HxExternalArgumentValues
as first argument and returns an integer array value.- Returns:
Expression of type
HxOperator.EXTERNAL_FUNCTION
.- Return type:
- HxModel.int_array_external_function(function)¶
Shortcut for
create_int_array_external_function()
.- Since:
11.0
- Parameters:
function – A python function that accepts a
HxExternalArgumentValues
as first argument and returns an integer array value- Returns:
Expression of type
HxOperator.EXTERNAL_FUNCTION
.- Return type:
- HxModel.create_double_array_external_function(function)¶
Creates a double array external function. The provided function must take a (
HxExternalArgumentValues
) as single argument and must return an iterable of double values (such as list, set or tuple ofdouble
). When the external function is called, the argument values will be made accessible to your function through theHxExternalArgumentValues
.Once you have instantiated it, you have to use
call()
to call it in your model.- Since:
11.0
- Parameters:
function – A python function that accepts a
HxExternalArgumentValues
as first argument and returns a double array value.- Returns:
Expression of type
HxOperator.EXTERNAL_FUNCTION
.- Return type:
- HxModel.double_array_external_function(function)¶
Shortcut for
create_double_array_external_function()
.- Since:
11.0
- Parameters:
function – A python function that accepts a
HxExternalArgumentValues
as first argument and returns a double array value- Returns:
Expression of type
HxOperator.EXTERNAL_FUNCTION
.- Return type:
- HxModel.get_nb_expressions()¶
Returns the number of expressions added to this model.
You can also use the shortcut member
nb_expressions
- Returns:
Number of expressions.
- Return type:
int
- HxModel.get_expression(expr_index)¶
- hexaly.optimizer.get_expression(expr_name)¶
Gets the expression with the given index or the given name in this model. Throws an exception if no expression with the given name or the given index exists.
You can also use the shortcut member
expressions
- Parameters:
expr_index (
int
) – Index of the expressionexpr_name (
str
) – Name of the expression.
- Returns:
Expression with the given index
- Return type:
- HxModel.get_nb_decisions()¶
Gets the number of decisions in the model. This corresponds to the number of decision variables declared in the model.
You can also use the shortcut member
nb_decisions
- Returns:
Number of decisions in the model.
- Return type:
int
- HxModel.get_decision(decision_index)¶
Gets the decision with the given index.
You can also use the shortcut member
decisions
- Parameters:
decision_index (
int
) – Index of the decision- Returns:
Decision with the given index
- Return type:
- HxModel.add_constraint(expr)¶
Adds the given expression to the list of constraints. It means that the value of this expression must be constrained to be equal to 1 in any solution found by the optimizer. Hence, only boolean expressions (that is, expressions whose value is boolean) can be constrained. Only allowed in state
HxState.MODELING
. If the expression is already a constraint, this method does nothing and returns immediately.- Parameters:
expr (HxExpression) – Expression
- HxModel.constraint(expr)¶
Shortcut for
add_constraint()
.You can also use the shortcut member
constraints
- Parameters:
expr (HxExpression) – Expression
- Since:
5.5
- HxModel.remove_constraint(expr)¶
- HxModel.remove_constraint(constraint_index)
Removes the given expression from the list of constraints. If the expression was not constrained, this method does nothing and returns immediately. Only allowed in state
HxState.MODELING
.- Parameters:
expr (HxExpression) – Expression.
constraint_index (
int
) – Index of the constraint to remove.
- Since:
5.0
- HxModel.get_nb_constraints()¶
Gets the number of constraints added to this model.
You can also use the shortcut member
nb_constraints
- Returns:
Number of constraints
- Return type:
int
- HxModel.get_constraint(index)¶
Gets the constraint with the given index.
- Parameters:
index (
int
) – Index of the constraint- Returns:
Constraint with the given index.
- Return type:
- HxModel.add_objective(expr, direction)¶
Adds the given expression to the list of objectives to optimize. A same expression can be added more than once. Only allowed in state
HxState.MODELING
. Note that the objectives will be optimized in the order in which they have been added to the model. It is useful for lexicographic multiobjective optimization, and more particularly for goal programming.- Parameters:
expr (HxExpression) – Expression
direction (HxObjectiveDirection) – Optimization direction of this objective
- HxModel.minimize(expr)¶
Shortcut for
add_objective(expr, HxObjectiveDirection.MINIMIZE)
.- Parameters:
expr (HxExpression) – Expression
- HxModel.maximize(expr)¶
Shortcut for
add_objective(expr, HxObjectiveDirection.MAXIMIZE)
.- Parameters:
expr (HxExpression) – Expression
- HxModel.remove_objective(obj_index)¶
Removes the objective at the given position in the list of objectives. Note that the objectives created after the removed one have their index decreased by 1. Phases are not modified when an objective is removed. It is the user’s responsibility to change the objective index of each phase to keep it coherent (with
HxPhase.set_optimized_objective()
or to disable it (withHxPhase.enabled
). Only allowed in stateHxState.MODELING
.- Parameters:
obj_index (
int
) – Position of the objective to remove.- Since:
5.0
- HxModel.get_nb_objectives()¶
Gets the number of objectives added to this model.
You can also use the shortcut member
nb_objectives
- Returns:
Number of objectives
- Return type:
int
- HxModel.get_objective(obj_index)¶
Gets the objective with the given index.
You can also use the shortcut member
objectives
- Parameters:
obj_index (
int
) – Index of the objective- Returns:
Objective with the given index
- Return type:
- HxModel.get_objective_direction(obj_index)¶
Gets the direction of the objective with the given index.
You can also use the shortcut member
objective_directions
- Parameters:
obj_index (
int
) – Index of the objective- Returns:
Objective direction
- Return type:
- HxModel.get_nb_operands()¶
Gets the number of operands in the model. This corresponds to the number of operands for all expressions declared in the model. It is an analog of the number of non zeros in matrix model encountered in mathematical programming: it gives an hint about the size and the density of your model.
You can also use the shortcut member
nb_operands
- Returns:
Number of operands.
- Return type:
int
- HxModel.close()¶
Closes the model. Only allowed in state
HxState.MODELING
. When this method is called, the optimizer is placed in stateHxState.STOPPED
.Once the model is closed, no expressions, constraints or objectives can be added or removed unless the model is reopened. The model must be closed before starting its resolution.
- HxModel.open()¶
Reopens the model. Only allowed in state
HxState.STOPPED
. When this method is called, the optimizer is placed in stateHxState.MODELING
.In this state, the model can be modified: it is possible to add new expressions, constraints or objectives, modify expression operands, and remove existing constraints and objectives. However, existing expressions cannot be deleted.
- HxModel.is_closed()¶
Returns true if the model is closed, false otherwise.
- Returns:
True if the model is closed.
- Return type:
bool
- HxModel.bool()¶
Creates a boolean decision. Binary decision variable with domain [0.1]. This method is a shortcut for
create_expression(HxOperator.BOOL)
.- Since:
5.5
- Returns:
Expression of type
HxOperator.BOOL
- Return type:
- HxModel.float(min, max)¶
Creates a float decision. Decision variable with domain
[min,max]
. This method is a shortcut forcreate_expression(HxOperator.FLOAT, min, max)
.- Since:
5.5
- Parameters:
min (
int
orfloat
) – Lower bound of the decision variable.max (
int
orfloat
) – Upper bound of the decision variable.
- Returns:
Expression of type
HxOperator.FLOAT
- Return type:
- HxModel.int(min, max)¶
Creates an integer decision. Decision variable with domain
[min,max]
. This method is a shortcut forcreate_expression(HxOperator.INT, min, max)
.- Since:
5.5
- Parameters:
min (
int
) – Lower bound of the decision variable.max (
int
) – Upper bound of the decision variable.
- Returns:
Expression of type
HxOperator.INT
- Return type:
- HxModel.interval(minStart, maxEnd)¶
Creates an interval decision included in
[minStart, maxEnd)
. Start is inclusive and end is exclusive. This method is a shortcut forcreate_expression(HxOperator.INTERVAL, minStart, maxEnd)
.- Since:
12.0
- Parameters:
minStart (
int
) – Min start of the decision variable.maxEnd (
int
) – Max end of the decision variable.
- Returns:
Expression of type
HxOperator.INTERVAL
- Return type:
- HxModel.hull(operands)¶
- HxModel.hull(*operands)
Creates a hull expression. This method is a shortcut for
create_expression(HxOperator.HULL, operands)
.Any object that implements the
__iter__
method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. Each operand must be an HxExpression with interval value.- Since:
13.0
- Parameters:
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.INTERVAL
- Return type:
- HxModel.sum(operands)¶
- HxModel.sum(*operands)
Creates a sum expression. This method is a shortcut for
create_expression(HxOperator.SUM, operands)
.Any object that implements the
__iter__
method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. Each operand can be an HxExpression, a boolean, an integer or a double.- Since:
5.5
- Parameters:
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.SUM
- Return type:
- HxModel.sub(op1, op2)¶
Creates a substraction expression. This method is a shortcut for
create_expression(HxOperator.SUB, op1, op2)
.Each operand can be an HxExpression, a boolean, an integer or a double.
- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression, boolean, integer or double.
op2 – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.SUB
- Return type:
- HxModel.prod(operands)¶
- HxModel.prod(*operands)
Creates a product expression. This method is a shortcut for
create_expression(HxOperator.PROD, operands)
.Any object that implements the
__iter__
method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. Each operand can be an HxExpression, a boolean, an integer or a double.- Since:
5.5
- Parameters:
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.PROD
- Return type:
- HxModel.max(operands)¶
- HxModel.max(*operands)
Creates a max expression. This method is a shortcut for
create_expression(HxOperator.MAX, operands)
.Any object that implements the
__iter__
method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. Each operand can be an HxExpression, a boolean, an integer or a double.- Since:
5.5
- Parameters:
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.MAX
- Return type:
- HxModel.min(operands)¶
- HxModel.min(*operands)
Creates a min expression. This method is a shortcut for
create_expression(HxOperator.MIN, operands)
.Any object that implements the
__iter__
method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. Each operand can be an HxExpression, a boolean, an integer or a double.- Since:
5.5
- Parameters:
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.MIN
- Return type:
- HxModel.or_(operands)¶
- HxModel.or_(*operands)
Creates a boolean or expression. This method is a shortcut for
create_expression(HxOperator.OR, operands)
.Any object that implements the
__iter__
method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. Each operand can be an HxExpression or a boolean.- Since:
5.5
- Parameters:
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.OR
- Return type:
- HxModel.and_(operands)¶
- HxModel.and_(*operands)
Creates a boolean and expression. This method is a shortcut for
create_expression(HxOperator.AND, operands)
.Any object that implements the
__iter__
method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. Each operand can be an HxExpression or a boolean.- Since:
5.5
- Parameters:
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.AND
- Return type:
- HxModel.xor(operands)¶
- HxModel.xor(*operands)
Creates a boolean xor expression. This method is a shortcut for
create_expression(HxOperator.XOR, operands)
.Any object that implements the
__iter__
method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. Each operand can be an HxExpression or a boolean.- Since:
5.5
- Parameters:
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.XOR
- Return type:
- HxModel.not_(op)¶
Creates a boolean not expression. This method is a shortcut for
create_expression(HxOperator.NOT, operands)
.The operand can be an HxExpression or a boolean.
- Since:
5.5
- Parameters:
op – Operand. Accepted types: HxExpression or boolean.
- Returns:
Expression of type
HxOperator.NOT
- Return type:
- HxModel.eq(op1, op2)¶
Creates an equality expression. This method is a shortcut for
create_expression(HxOperator.EQ, op1, op2)
.Accepted operands are: HxExpressions, booleans, integers or doubles.
- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression, boolean, integer or double.
op2 – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.EQ
- Return type:
- HxModel.neq(op1, op2)¶
Creates a disequality expression. This method is a shortcut for
create_expression(HxOperator.NEQ, op1, op2)
.Accepted operands are: HxExpressions, booleans, integers or doubles.
- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression, boolean, integer or double.
op2 – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.NEQ
- Return type:
- HxModel.geq(op1, op2)¶
Creates an inequality ‘greater than or equal to’. This method is a shortcut for
create_expression(HxOperator.GEQ, op1, op2)
.Accepted operands are: HxExpressions, booleans, integers or doubles.
- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression, boolean, integer or double.
op2 – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.GEQ
- Return type:
- HxModel.leq(op1, op2)¶
Creates an inequality ‘lower than or equal to’. This method is a shortcut for
create_expression(HxOperator.LEQ, op1, op2)
.Accepted operands are: HxExpressions, booleans, integers or doubles.
- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression, boolean, integer or double.
op2 – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.LEQ
- Return type:
- HxModel.gt(op1, op2)¶
Creates an inequality ‘strictly greater than’. This method is a shortcut for
create_expression(HxOperator.GT, op1, op2)
.Accepted operands are: HxExpressions, booleans, integers or doubles.
- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression, boolean, integer or double.
op2 – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.GT
- Return type:
- HxModel.lt(op1, op2)¶
Creates an inequality ‘strictly lower than’. This method is a shortcut for
create_expression(HxOperator.LT, op1, op2)
.Accepted operands are: HxExpressions, booleans, integers or doubles.
- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression, boolean, integer or double.
op2 – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.LT
- Return type:
- HxModel.iif(op1, op2, op3)¶
Creates a ternary conditional operator. This method is a shortcut for
create_expression(HxOperator.IF, op1, op2, op3)
.The first operand must be an HxExpression with a boolean value or a boolean. The other operands can be HxExpressions, booleans, integers or doubles.
- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression with boolean value or boolean.
op2 – Operand. Accepted types: HxExpression, boolean, integer or double.
op3 – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.IF
- Return type:
- HxModel.abs(op)¶
Creates an absolute value expression. This method is a shortcut for
create_expression(HxOperator.ABS, op)
.The operand can be an HxExpression, a boolean, an integer or a double.
- Since:
5.5
- Parameters:
op – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.ABS
- Return type:
- HxModel.dist(op1, op2)¶
Creates a distance expression. This method is a shortcut for
create_expression(HxOperator.DIST, op1, op2)
.Accepted operands are: HxExpressions, booleans, integers or doubles.
- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression, boolean, integer or double.
op2 – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.DIST
- Return type:
- HxModel.div(op1, op2)¶
Creates a division expression. This method is a shortcut for
create_expression(HxOperator.DIV, op1, op2)
.Accepted operands are: HxExpressions, booleans, integers or doubles.
- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression, boolean, integer or double.
op2 – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.DIV
- Return type:
- HxModel.mod(op1, op2)¶
Creates a modulo expression. This method is a shortcut for
create_expression(HxOperator.MOD, op1, op2)
.Accepted operands are: HxExpressions with integer values, booleans, integers.
- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression with integer value, boolean or integer.
op2 – Operand. Accepted types: HxExpression with integer value, boolean or integer.
- Returns:
Expression of type
HxOperator.MOD
- Return type:
- HxModel.array(operands)¶
- HxModel.array(*operands)
Creates a new array. This method behaves as a shortcut for
create_expression(HxOperator.ARRAY, operands)
, but attempts to create an N-dimensional array in a recursive way: if an operand is iterable, it will be turned into an array too, and so on.Any object that implements the
__iter__
method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. Each operand can be an HxExpression, a boolean, an integer or a double.- Since:
5.5
- Parameters:
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.ARRAY
- Return type:
- LSModel.stepArray(op1, op2)¶
Creates a new step array. This method is a shortcut for
create_expression(HxOperator.STEP_ARRAY, op1, op2)
.The first operand must be an HxExpression with constant array value. The second operand must be an HxExpression with constant array value.
- Since:
13.0
- Parameters:
op1 – Operand. Accepted type:
HxExpression
with array value.op2 – Operand. Accepted type:
HxExpression
with array value.
- Returns:
Expression of type
HxOperator.STEPARRAY
- Return type:
- HxModel.at(array_expr, indices_expr)¶
- HxModel.at(array_expr, *indices_expr)
Creates a “at” expression. This method is a shortcut for
create_expression(HxOperator.AT, array_expr, indices_expr)
.The first operand must be an HxExpression with array or collection value. The second operand accepts any object that implements the
__iter__
method. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. These operands must be HxExpressions with integer value, booleans or integers.- Since:
5.5
- Parameters:
array_expr – Operand. Accepted types: HxExpression with array or collection value.
indices_expr – Operands for the indices. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.AT
- Return type:
- HxModel.scalar(op1, op2)¶
Creates a scalar product between two arrays. This method is a shortcut for
create_expression(HxOperator.SCALAR, op1, op2)
.The operands must be HxExpressions of type
HxOperator.ARRAY
.- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression with array value.
op2 – Operand. Accepted types: HxExpression with array value.
- Returns:
Expression of type
HxOperator.SCALAR
- Return type:
- HxModel.ceil(op)¶
Creates a ceil expression. This method is a shortcut for
create_expression(HxOperator.CEIL, op)
.The operand can be an HxExpression, a boolean, an integer or a double.
- Since:
5.5
- Parameters:
op – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.CEIL
- Return type:
- HxModel.floor(op)¶
Creates a floor expression. This method is a shortcut for
create_expression(HxOperator.FLOOR, op)
.The operand can be an HxExpression, a boolean, an integer or a double.
- Since:
5.5
- Parameters:
op – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.FLOOR
- Return type:
- HxModel.round(op)¶
Creates a round expression. This method is a shortcut for
create_expression(HxOperator.ROUND, op)
.The operand can be an HxExpression, a boolean, an integer or a double.
- Since:
5.5
- Parameters:
op – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.ROUND
- Return type:
- HxModel.sqrt(op)¶
Creates a square root expression. This method is a shortcut for
create_expression(HxOperator.SQRT, op)
.The operand can be an HxExpression, a boolean, an integer or a double.
- Since:
5.5
- Parameters:
op – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.SQRT
- Return type:
- HxModel.log(op)¶
Creates a natural log expression. This method is a shortcut for
create_expression(HxOperator.LOG, op)
.The operand can be an HxExpression, a boolean, an integer or a double.
- Since:
5.5
- Parameters:
op – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.LOG
- Return type:
- HxModel.exp(op)¶
Creates an exponential expression. This method is a shortcut for
create_expression(HxOperator.EXP, op)
.The operand can be an HxExpression, a boolean, an integer or a double.
- Since:
5.5
- Parameters:
op – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.EXP
- Return type:
- HxModel.pow(op1, op2)¶
Creates a power expression. This method is a shortcut for
create_expression(HxOperator.POW, op1, op2)
.Accepted operands are: HxExpressions, booleans, integers or doubles.
- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression, boolean, integer or double.
op2 – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.POW
- Return type:
- HxModel.cos(op)¶
Creates a cosine expression. This method is a shortcut for
create_expression(HxOperator.COS, op)
.The operand can be an HxExpression, a boolean, an integer or a double.
- Since:
5.5
- Parameters:
op – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.COS
- Return type:
- HxModel.sin(op)¶
Creates a sine expression. This method is a shortcut for
create_expression(HxOperator.SIN, op)
.The operand can be an HxExpression, a boolean, an integer or a double.
- Since:
5.5
- Parameters:
op – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.SIN
- Return type:
- HxModel.tan(op)¶
Creates a tangent expression. This method is a shortcut for
create_expression(HxOperator.TAN, op)
.The operand can be an HxExpression, a boolean, an integer or a double.
- Since:
5.5
- Parameters:
op – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.TAN
- Return type:
- HxModel.piecewise(op1, op2, op3)¶
Creates a piecewise linear expression. This method is a shortcut for
create_expression(HxOperator.PIECEWISE, op1, op2, op3)
.The first and the second operands must be HxExpressions of type
HxOperator.ARRAY
. The third argument must be an HxExpression, a boolean, an integer or a double.- Since:
5.5
- Parameters:
op1 – Operand. Accepted types: HxExpression of type
HxOperator.ARRAY
op2 – Operand. Accepted types: HxExpression of type
HxOperator.ARRAY
op3 – Operand. Accepted types: HxExpression, boolean, integer or double.
- Returns:
Expression of type
HxOperator.PIECEWISE
- Return type:
- HxModel.list(n)¶
Creates a list decision with the given length. A list is an ordered collection of integers within a domain [0, n-1]. This method is a shortcut for
create_expression(HxOperator.LIST, n)
.- Since:
5.5
- Parameters:
n (
bool
orint
) – Collection size.
- HxModel.set(n)¶
Creates a set decision with the given length. A set is an unordered collection of integers within a domain [0, n-1]. This method is a shortcut for
create_expression(HxOperator.SET, n)
.- Since:
8.0
- Parameters:
n (
bool
orint
) – Collection size. Accepted types:bool
orint
.
- HxModel.start(op)¶
Creates a start expression. This method is a shortcut for
create_expression(HxOperator.START, op)
.The operand must be an HxExpression with interval value.
- Since:
12.0
- Parameters:
op – Operand. Accepted type:
HxExpression
with interval value.- Returns:
Expression of type
HxOperator.START
- Return type:
- HxModel.end(op)¶
Creates an end expression. This method is a shortcut for
create_expression(HxOperator.END, op)
.The operand must be an HxExpression with interval value.
- Since:
12.0
- Parameters:
op – Operand. Accepted type:
HxExpression
with interval value.- Returns:
Expression of type
HxOperator.END
- Return type:
- HxModel.length(op)¶
Creates a length expression. This method is a shortcut for
create_expression(HxOperator.LENGTH, op)
.The operand must be an HxExpression with interval value.
- Since:
12.0
- Parameters:
op – Operand. Accepted type:
HxExpression
with interval value.- Returns:
Expression of type
HxOperator.LENGTH
- Return type:
- HxModel.count(op)¶
Creates a count expression. This method is a shortcut for
create_expression(HxOperator.COUNT, op)
.The operand must be an HxExpression with array, collection or interval value.
- Since:
5.5
- Parameters:
op – Operand. Accepted type:
HxExpression
with array, collection or interval value.- Returns:
Expression of type
HxOperator.COUNT
- Return type:
- HxModel.index(op1, op2)¶
Creates an indexOf expression. This method is a shortcut for
create_expression(HxOperator.INDEXOF, op1, op2)
.The first operand must be an HxExpression with list value. The second operand must be an HxExpression with integer value, an integer or a boolean.
- Since:
5.5
- Parameters:
op1 – Operand. Accepted type:
HxExpression
with list value.op2 – Operand. Accepted type:
HxExpression
or integer.
- Returns:
Expression of type
HxOperator.INDEXOF
- Return type:
- HxModel.distinct(operands)¶
Creates a distinct expression. This method is a shortcut for
create_expression(HxOperator.DISTINCT, operands)
.This operator accepts one or two operands. If one operand is passed, the operand must be an HxExpression with one-dimensional array value. If two operands are passed, the first one must be an HxExpression with collection (list or set), interval or range value, and the second must be an HxExpression with lambda function value.
- Since:
12.5
- Parameters:
operands – Operands (1 or 2). Accepted type:
HxExpression
.- Returns:
Expression of type
HxOperator.DISTINCT
- Return type:
- HxModel.intersection(op1, op2)¶
Creates an intersection expression. This method is a shortcut for
create_expression(HxOperator.INTERSECTION, op1, op2)
.The first operand must be an HxExpression with collection or array value. The second operand must be an HxExpression with collection or array value.
- Since:
12.5
- Parameters:
op1 – Operand. Accepted type:
HxExpression
with collection or array value.op2 – Operand. Accepted type:
HxExpression
with collection or array value.
- Returns:
Expression of type
HxOperator.INTERSECTION
- Return type:
- HxModel.contains(op1, op2)¶
Creates a contains expression. This method is a shortcut for
create_expression(HxOperator.CONTAINS, op1, op2)
.The first operand must be an HxExpression with collection, interval or array value. The second operand must be an HxExpression with integer or double value, an integer, a boolean or a double.
- Since:
7.5
- Parameters:
op1 – Operand. Accepted type:
HxExpression
with collection, interval or array value.op2 – Operand. Accepted type:
HxExpression
, integer or double.
- Returns:
Expression of type
HxOperator.CONTAINS
- Return type:
- HxModel.partition(operands)¶
- HxModel.partition(*operands)
Creates a partition expression. This method is a shortcut for
create_expression(HxOperator.PARTITION, operands)
.Any object that implements the
__iter__
method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. Each operand must be an HxExpression with collection value.- Since:
5.5
- Parameters:
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.PARTITION
- Return type:
- HxModel.disjoint(operands)¶
- HxModel.disjoint(*operands)
Creates a disjoint expression. This method is a shortcut for
create_expression(HxOperator.DISJOINT, operands)
.Any object that implements the
__iter__
method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. Each operand must be an HxExpression with collection value.- Since:
5.5
- Parameters:
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.DISJOINT
- Return type:
- HxModel.cover(operands)¶
- HxModel.cover(*operands)
Creates a cover expression. This method is a shortcut for
create_expression(HxOperator.COVER, operands)
.Any object that implements the
__iter__
method is accepted. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. Each operand must be an HxExpression with collection value.- Since:
10.5
- Parameters:
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.COVER
- Return type:
- HxModel.find(op1, op2)¶
Creates a find expression. This method is a shortcut for
create_expression(HxOperator.FIND, op1, op2)
.The first operand must be an HxExpression with array value. The second operand must be an HxExpression with integer value, an integer or a boolean.
- Since:
10.5
- Parameters:
op1 – Operand. Accepted type:
HxExpression
with array value.op2 – Operand. Accepted type:
HxExpression
or integer.
- Returns:
Expression of type
HxOperator.FIND
- Return type:
- HxModel.sort(op1[, op2])¶
Creates a sort expression. This method is a shortcut for
create_expression(HxOperator.SORT, op1 [, op2])
.The first operand must be an HxExpression representing a one-dimensional array containing integers or doubles. The second argument is optional and, if specified, must be an HxExpression with lambda function value.
- Since:
11.0
- Parameters:
op1 – Operand. Accepted type:
HxExpression
with array value.op2 – Operand. Accepted type:
HxExpression
with lambda function value.
- Returns:
Expression of type
HxOperator.SORT
- Return type:
- HxModel.call(operands)¶
- HxModel.call(*operands)
Creates a call expression. This method is a shortcut for
create_expression(HxOperator.CALL, operands)
.The first operand must be an HxExpression of type
HxOperator.LAMBDA_FUNCTION
orHxOperator.EXTERNAL_FUNCTION
. The second operand accepts any object that implements the__iter__
method. Thus, lists, tuples, sets and their comprehensions counterpart are accepted. It is also possible to use this method with a variadic number of arguments. These operands may be HxExpressions, booleans, integers, and doubles. They are passed to the function as arguments.- Since:
6.0
- Parameters:
operands – Operands to add. An iterable or any number of arguments.
- Returns:
Expression of type
HxOperator.CALL
- Return type:
- HxModel.range([op1, ]op2)¶
Creates a range expression. op1 is the lower bound (inclusive) and op2 is the upper bound (exclusive). When only one operand is used, the lower bound is 0. This method is a shortcut for
create_expression(HxOperator.RANGE, op1, op2)
.- Since:
7.0
- Parameters:
op1 – Operand. Accepted types: HxExpression with integer value, boolean or integer.
op2 – Operand. Accepted types: HxExpression with integer value, boolean or integer.
- Returns:
Expression of type
HxOperator.RANGE
- Return type:
Instance attributes¶
All get/set
methods have their attribute counterpart. You can use them as
shortcuts to improve the readability or your models and codes.
- HxModel.nb_expressions¶
Number of expressions in this model. This attribute is read-only. It is a shortcut for
get_nb_expressions()
.
- HxModel.nb_operands¶
Number of operands in this model. This attribute is read-only. It is a shortcut for
get_nb_operands()
.
- HxModel.nb_objectives¶
Number of objectives in this model. This attribute is read-only. It is a shortcut for
get_nb_objectives()
.
- HxModel.nb_constraints¶
Number of constraints in this model. This attribute is read-only. It is a shortcut for
get_nb_constraints()
.
- HxModel.nb_decisions¶
Number of decisions in this model. This attribute is read-only. It is a shortcut for
get_nb_decisions()
.
- HxModel.expressions¶
List of the expressions of the model. This attribute is read-only. The returned object is iterable, supports the
len
function and can be indexed with integers. It is a shortcut forget_expression()
andget_nb_expressions()
methods.
- HxModel.decisions¶
List of the decisions of the model. This attribute is read-only. The returned object is iterable, supports the
len
function and can be indexed with integers. It is a shortcut forget_decision()
andget_nb_decisions()
methods.
- HxModel.objectives¶
List of the objectives of the model. This attribute is read-only. The returned object is iterable, supports the
len
function and can be indexed with integers. It is a shortcut forget_objective()
andget_nb_objectives()
methods.
- HxModel.objective_directions¶
List of the objective directions of the model. This attribute is read-only. The returned object is iterable, supports the
len
function and can be indexed with integers. It is a shortcut forget_objective_direction()
andget_nb_objectives()
methods.
- HxModel.constraints¶
List of the constraints of the model. This attribute is read-only. The returned object is iterable, supports the
len
function and can be indexed with integers. It is a shortcut forget_constraint()
andget_nb_constraints()
methods.
Special operators and methods¶
- HxModel.__str__()¶
Returns a string representation of this model. This representation provides:
The number of expressions, decisions, constraints, and objectives.
The density of the model.
Useful for debugging or logging purposes.
- Returns:
String representation of this model.
- Return type:
str