HxModel Class

class HxModel

Mathematical optimization model. A model is composed of expressions (some of which are decisions), organized as a tree. 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 resolve 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.

See:HxExpression
See:HxOperator

Summary

Functions
createConstant Creates a constant expression representing the given value.
createConstant Creates a constant expression representing the given value.
createExpression Creates an expression of the given type, with the given ordered operands.
createConstArray Creates a constant array expression containing the given values.
createConstArray Creates a constant array expression containing the given values.
createExternalFunction Creates an integer external function.
createExternalFunction Creates a double external function.
createExternalFunction Creates an integer array external function.
createExternalFunction Creates a double array external function.
createExternalFunction Creates an external function.
createExternalFunction Creates an external function.
createLambdaFunction Creates a lambda function.
boolVar Creates a boolean decision.
floatVar Creates a float decision.
intVar Creates an integer decision.
intervalVar Creates an interval decision included in [minStart, maxEnd).
optionalIntervalVar Creates an optional interval decision, which can either be absent (void) or included in [minStart, maxEnd).
hull Creates a hull expression.
hull Creates a hull expression.
hull Creates a hull expression.
start Creates a start expression.
end Creates an end expression.
length Creates a length expression.
presence Creates a presence expression.
sum Creates a sum expression.
sub Creates a substraction expression.
call Creates a call expression.
prod Creates a product expression.
max Creates a maximum expression.
min Creates a minimum expression.
or_ Creates a OR expression.
and_ Creates an AND expression.
xor_ Creates a XOR expression.
not_ Creates a NOT expression.
eq Creates an equality expression.
neq Creates a disequality expression.
geq Creates an inequality expression greater than or equal to.
leq Creates an inequality expression less than or equal to.
gt Creates an inequality expression greater than.
lt Creates an inequality expression less than.
iif Creates a ternary conditional expression.
abs Creates an absolute value expression.
dist Creates a distance expression.
div Creates a division expression.
mod Creates a modulo expression.
array Creates an array expression.
stepArray Creates an step array expression.
at Creates an AT expression for N-dimensional array.
scalar Creates an expression for the scalar product between two arrays.
ceil Creates a ceil expression.
floor Creates a floor expression.
round Creates a rounding expression.
sqrt Creates a square root expression.
log Creates a log expression.
exp Creates an exponential expression.
pow Creates a power expression.
cos Creates a cosine expression.
sin Creates a sine expression.
tan Creates a tangent expression.
piecewise Creates a piecewise linear expression.
listVar Creates a list decision with the given length.
setVar Creates a set decision with the given length.
count Creates a count expression.
indexOf Creates an indexOf expression.
distinct Creates a distinct expression.
distinct Creates a distinct expression.
intersection Creates an intersection expression of intervals.
intersection Creates an intersection expression.
union_ Creates an union expression.
contains Creates a contains expression.
partition Creates a partition expression.
partition Creates a partition expression.
disjoint Creates a disjoint expression.
disjoint Creates a disjoint expression.
cover Creates a cover expression.
cover Creates a cover expression.
find Creates a find expression.
sort Creates a sort expression.
sort Creates a sort expression.
externalFunction Creates an external function expression.
externalFunction Creates an external function expression.
externalFunction Creates an external function expression.
lambdaFunction Creates a lambda function expression.
range Creates a range expression, where expr0 is the lower bound (inclusive) and expr1 is the upper bound (exclusive).
getNbExpressions Gets the number of expressions added to this model.
getExpression Gets the expression with the given index in this model.
getExpression Gets the expression with the given name.
getNbDecisions Gets the number of decisions in the model.
getDecision Gets the decision with the given index.
addConstraint Adds the given expression to the list of constraints.
constraint Shortcut for addConstraint(expr).
removeConstraint Removes the given expression from the list of constraints.
removeConstraint Removes the constraint at the given position in the list of constraints.
getNbConstraints Gets the number of constraints added to this model.
getConstraint Gets the constraint with the given index.
addObjective Adds the given expression to the list of objectives to optimize.
minimize Shortcut for addObjective(expr, OD_Minimize).
maximize Shortcut for addObjective(expr, OD_Maximize).
removeObjective Removes the objective at the given position in the list of objectives.
getNbObjectives Gets the number of objectives added to this model.
getObjective Gets the objective with the given index.
getObjectiveDirection Gets the direction of the objective with the given index.
getNbOperands Gets the number of operands in the model.
close Closes the model.
open Reopens the model.
isClosed Returns true if the model is closed, false otherwise.
toString Returns a string representation of this model.

Functions

HxExpression HxModel::createConstant(hxint value)

Creates a constant expression representing the given value. Only allowed in state S_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.
Returns:Created constant expression.
HxExpression HxModel::createConstant(hxdouble value)

Creates a constant expression representing the given value. Only allowed in state S_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
Returns:Created constant expression.
template<typename ...TN>
HxExpression createExpression(HxOperator op, TN... operands)

Creates an expression of the given type, with the given ordered operands. Only allowed in state S_Modeling. The operands can be doubles, integers or previously declared HxExpressions. It is also possible to use this method with iterators. In that case, you have to call this method with 2 operands exactly that must be iterators of the same type, pointing respectively to the initial and final positions of the operands.

Parameters:
  • TN – types of the operands to add. Types allowed: constant types, HxExpression or iterators.
  • op – Type of expression to create.
  • operands – Operands.
Returns:

Created expression.

HxExpression HxModel::createConstArray(hxint *values, int nbValues)

Creates a constant array expression containing the given values. Only allowed in state S_Modeling. Note that the constant array created does not have operands.

Parameters:values – Array of constant values.
Returns:Created constant array expression.
Since:13.5
HxExpression HxModel::createConstArray(hxdouble *values, int nbValues)

Creates a constant array expression containing the given values. Only allowed in state S_Modeling. Note that the constant array created does not have operands.

Parameters:values – Array of constant values.
Returns:Created constant array expression.
Since:13.5
HxExpression HxModel::createExternalFunction(HxExternalFunction<hxint> *func)

Creates an integer external function. The argument must be derived from HxExternalFunction. When the external function is called, the argument values will be made accessible to your function through the HxExternalArgumentValues.

Once you have instantiated it, you have to use call() to call it in your model.

Parameters:func – External function to call.
Returns:The expression associated to the function.
See:HxExternalFunction
See:O_ExternalFunction
Since:9.5
HxExpression HxModel::createExternalFunction(HxExternalFunction<hxdouble> *func)

Creates a double external function. The argument must be derived from HxExternalFunction. When the external function is called, the argument values will be made accessible to your function through the HxExternalArgumentValues.

Once you have instantiated it, you have to use call() to call it in your model.

Parameters:func – External function to call.
Returns:The expression associated to the function.
See:HxExternalFunction
See:O_ExternalFunction
Since:9.5
HxExpression HxModel::createExternalFunction(HxArrayExternalFunction<hxint> *func)

Creates an integer array external function. The argument must be derived from HxArrayExternalFunction. When the external function is called, the argument values will be made accessible to your function through the HxExternalArgumentValues.

Once you have instantiated it, you have to use call() to call it in your model.

Parameters:func – External function to call.
Returns:The expression associated to the function.
See:HxExternalFunction
See:O_ExternalFunction
Since:11.0
HxExpression HxModel::createExternalFunction(HxArrayExternalFunction<hxdouble> *func)

Creates a double array external function. The argument must be derived from HxArrayExternalFunction. When the external function is called, the argument values will be made accessible to your function through the HxExternalArgumentValues.

Once you have instantiated it, you have to use call() to call it in your model.

Parameters:func – External function to call.
Returns:The expression associated to the function.
See:HxExternalFunction
See:O_ExternalFunction
Since:11.0
template<typename T, typename ...ARGS>
HxExpression HxModel::createExternalFunction(const std::function<T(ARGS...)> &func)

Creates an external function. The argument must be a std::function taking any combination of hxint and hxdouble arguments. When the external function is called, the argument values will be passed to your function as its arguments.

Once you have instantiated it, you have to use call() to call it in your model.

Parameters:func – std::function to call. It must only accept hxint and hxdouble arguments.
Returns:The expression associated to the function.
See:HxExternalFunction
See:O_ExternalFunction
Since:9.5
template<typename T>
HxExpression HxModel::createExternalFunction(const std::function<T(const HxExternalArgumentValues&)> &func)

Creates an external function. The argument must be a std::function taking a HxExternalArgumentValues as its argument. When the external function is called, the argument values will be made accessible to your function through this object.

Once you have instantiated it, you have to use call() to call it in your model.

Parameters:func – External function to call.
Returns:The expression associated to the function.
See:HxExternalFunction
See:O_ExternalFunction
Since:9.5
template<typename A>
HxExpression HxModel::createLambdaFunction(const A &functor)

Creates a lambda function. A lambda function is a particular expression composed of two parts:

  • The arguments of the function (which are also HxExpressions of type O_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.

You have to provide the body of the function as a std::function (C++ function or lambda). Please note that the provided std::function will not be used directly during the solving process, but will be evaluated once by the API with a number of HxExpression of type O_Argument that corresponds to the number of arguments your std::function expects. The returned HxExpression resulting of this evaluation will be used as the body of the Hexaly Optimizer function O_LambdaFunction.

Parameters:functor – Functor called to create the function.
Returns:The expression associated to the function.
Since:9.5
HxExpression HxModel::boolVar()

Creates a boolean decision. Binary decision variable with domain { 0, 1 }. This method is a shortcut for createExpression(O_Bool).

See:O_Bool
See:HxModel::createExpression()
Since:5.5
HxExpression HxModel::floatVar(hxdouble lb, hxdouble ub)

Creates a float decision. Decision variable with domain [lb, ub]. This method is a shortcut for createExpression(O_Float, lb, ub).

Parameters:
  • lb – Lower bound of the decision variable.
  • ub – Upper bound of the decision variable.
See:

O_Float

See:

HxModel::createExpression()

Since:

5.5

HxExpression HxModel::intVar(hxint lb, hxint ub)

Creates an integer decision. Decision variable with domain [lb, ub]. This method is a shortcut for createExpression(O_Int, lb, ub).

Parameters:
  • lb – Lower bound of the decision variable.
  • ub – Upper bound of the decision variable.
See:

O_Int

See:

HxModel::createExpression()

Since:

5.5

HxExpression HxModel::intervalVar(hxint minStart, hxint maxEnd)

Creates an interval decision included in [minStart, maxEnd). Start is inclusive and end is exclusive. This method is a shortcut for createExpression(O_Interval, minStart, maxEnd).

Parameters:
  • minStart – Min start of the decision variable.
  • maxEnd – Max end of the decision variable.
See:

O_Interval

See:

HxModel::createExpression()

Since:

12.0

HxExpression HxModel::optionalIntervalVar(hxint minStart, hxint maxEnd)

Creates an optional interval decision, which can either be absent (void) or included in [minStart, maxEnd). When present, start is inclusive and end is exclusive. When absent, start and end are undefined. This method is a shortcut for createExpression(O_OptionalInterval, minStart, maxEnd).

Parameters:
  • minStart – Min start of the decision variable.
  • maxEnd – Max end of the decision variable.
See:

O_OptionalInterval

See:

HxModel::createExpression()

Since:

14.0

template<typename ...TN>
HxExpression HxModel::hull(TN... operands)

Creates a hull expression. This method is a shortcut for createExpression(O_Hull, operands).

See:O_Hull
See:HxModel::createExpression()
Since:13.0
template<typename T0>
HxExpression HxModel::hull(T0 array)

Creates a hull expression. This method is a shortcut for createExpression(O_Hull, array).

See:O_Hull
See:HxModel::createExpression()
Since:13.0
template<typename T0>
HxExpression HxModel::hull(T0 it, T1 func)

Creates a hull expression. This method is a shortcut for createExpression(O_Hull, it, func).

See:O_Hull
See:HxModel::createExpression()
Since:14.5
template<typename T0>
HxExpression HxModel::start(T0 expr0)

Creates a start expression. This method is a shortcut for createExpression(O_Start, expr0).

See:O_Start
See:HxModel::createExpression()
Since:12.0
template<typename T0>
HxExpression HxModel::end(T0 expr0)

Creates an end expression. This method is a shortcut for createExpression(O_End, expr0).

See:O_End
See:HxModel::createExpression()
Since:12.0
template<typename T0>
HxExpression HxModel::length(T0 expr0)

Creates a length expression. This method is a shortcut for createExpression(O_Length, expr0).

See:O_Length
See:HxModel::createExpression()
Since:12.0
template<typename T0>
HxExpression HxModel::presence(T0 expr0)

Creates a presence expression. This method is a shortcut for createExpression(O_Presence, expr0).

See:O_Presence
See:HxModel::createExpression()
Since:14.0
template<typename ...TN>
HxExpression HxModel::sum(TN... operands)

Creates a sum expression. This method is a shortcut for createExpression(O_Sum, operands).

See:O_Sum
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1>
HxExpression HxModel::sub(T0 expr0, T1 expr1)

Creates a substraction expression. This method is a shortcut for createExpression(O_Sub, expr0, expr1).

See:O_Sub
See:HxModel::createExpression()
Since:5.5
template<typename ...TN>
HxExpression HxModel::call(TN... operands)

Creates a call expression. The first operand must be an HxExpression of type O_LambdaFunction or O_ExternalFunction. The other operands may be HxExpressions, booleans, integers, and doubles. They are passed to the function as arguments.

This method is a shortcut for createExpression(O_Call, operands).

See:O_Call
See:HxModel::createExpression()
Since:6.0
template<typename ...TN>
HxExpression HxModel::prod(TN... operands)

Creates a product expression. This method is a shortcut for createExpression(O_Prod, operands).

See:O_Prod
See:HxModel::createExpression()
Since:5.5
template<typename ...TN>
HxExpression HxModel::max(TN... operands)

Creates a maximum expression. This method is a shortcut for createExpression(O_Max, operands).

See:O_Max
See:HxModel::createExpression()
Since:5.5
template<typename ...TN>
HxExpression HxModel::min(TN... operands)

Creates a minimum expression. This method is a shortcut for createExpression(O_Min, operands).

See:O_Min
See:HxModel::createExpression()
Since:5.5
template<typename ...TN>
HxExpression HxModel::or_(TN... operands)

Creates a OR expression. This method is a shortcut for createExpression(O_Or, operands).

See:O_Or
See:HxModel::createExpression()
Since:5.5
template<typename ...TN>
HxExpression HxModel::and_(TN... operands)

Creates an AND expression. This method is a shortcut for createExpression(O_And, operands).

See:O_And
See:HxModel::createExpression()
Since:5.5
template<typename ...TN>
HxExpression HxModel::xor_(TN... operands)

Creates a XOR expression. This method is a shortcut for createExpression(O_Xor, operands).

See:O_Xor
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxModel::HxExpression not_(T0 expr0)

Creates a NOT expression. This method is a shortcut for createExpression(O_Not, expr0).

See:O_Not
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1>
HxExpression HxModel::eq(T0 expr0, T1 expr1)

Creates an equality expression. This method is a shortcut for createExpression(O_Eq, expr0, expr1).

See:O_Eq
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1>
HxExpression HxModel::neq(T0 expr0, T1 expr1)

Creates a disequality expression. This method is a shortcut for createExpression(O_Neq, expr0, expr1).

See:O_Neq
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1>
HxExpression HxModel::geq(T0 expr0, T1 expr1)

Creates an inequality expression greater than or equal to. This method is a shortcut for createExpression(O_Geq, expr0, expr1).

See:O_Geq
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1>
HxExpression HxModel::leq(T0 expr0, T1 expr1)

Creates an inequality expression less than or equal to. This method is a shortcut for createExpression(O_Leq, expr0, expr1).

See:O_Leq
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1>
HxExpression HxModel::gt(T0 expr0, T1 expr1)

Creates an inequality expression greater than. This method is a shortcut for createExpression(O_Gt, expr0, expr1).

See:O_Gt
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1>
HxExpression HxModel::lt(T0 expr0, T1 expr1)

Creates an inequality expression less than. This method is a shortcut for createExpression(O_Lt, expr0, expr1).

See:O_Lt
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1, typename T2>
HxExpression HxModel::iif(T0 condExpr, T1 trueExpr, T2 falseExpr)

Creates a ternary conditional expression. This method is a shortcut for createExpression(O_If, condExpr, trueExpr, falseExpr).

See:O_If
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxExpression HxModel::abs(T0 expr0)

Creates an absolute value expression. This method is a shortcut for createExpression(O_Abs, expr0).

See:O_Abs
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1>
HxExpression HxModel::dist(T0 expr0, T1 expr1)

Creates a distance expression. This method is a shortcut for createExpression(O_Dist, expr0, expr1).

See:O_Dist
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1>
HxExpression HxModel::div(T0 expr0, T1 expr1)

Creates a division expression. This method is a shortcut for createExpression(O_Div, expr0, expr1).

See:O_Div
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1>
HxExpression HxModel::mod(T0 expr0, T1 expr1)

Creates a modulo expression. This method is a shortcut for createExpression(O_Mod, expr0, expr1).

See:O_Mod
See:HxModel::createExpression()
Since:5.5
template<typename ...TN>
HxExpression HxModel::array(TN... operands)

Creates an array expression. This method is a shortcut for createExpression(O_Array, operands).

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.

When defining a variadic array (with a range or a list decision as the first operand and a lambda function as the second operand), we allow a recursive definition of the elements in this array by using a second argument in the function, containing the evaluation of the function on the previous element of the range. In this case, a third operand can be added, representing the value of the element before the first element in the array.

See:O_Array
See:HxModel::createExpression()
Since:5.5
template<typename ...TN>
HxExpression HxModel::stepArray(TN... operands)

Creates an step array expression. This method is a shortcut for createExpression(O_StepArray, operands).

See:O_StepArray
See:HxModel::createExpression()
Since:13.0
template<typename T0, typename ...TN>
HxExpression HxModel::at(T0 arrayExpr, TN... operands)

Creates an AT expression for N-dimensional array. This method is a shortcut for createExpression(O_At, arrayExpr, operands).

See:O_At
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1>
HxExpression HxModel::scalar(T0 expr0, T1 expr1)

Creates an expression for the scalar product between two arrays. This method is a shortcut for createExpression(O_Scalar, expr0, expr1).

See:O_Scalar
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxExpression HxModel::ceil(T0 expr0)

Creates a ceil expression. This method is a shortcut for createExpression(O_Ceil, expr0).

See:O_Ceil
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxExpression HxModel::floor(T0 expr0)

Creates a floor expression. This method is a shortcut for createExpression(O_Floor, expr0).

See:O_Floor
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxExpression HxModel::round(T0 expr0)

Creates a rounding expression. This method is a shortcut for createExpression(O_Round, expr0).

See:O_Round
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxExpression HxModel::sqrt(T0 expr0)

Creates a square root expression. This method is a shortcut for createExpression(O_Sqrt, expr0).

See:O_Sqrt
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxExpression HxModel::log(T0 expr0)

Creates a log expression. This method is a shortcut for createExpression(O_Log, expr0).

See:O_Log
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxExpression HxModel::exp(T0 expr0)

Creates an exponential expression. This method is a shortcut for createExpression(O_Exp, expr0).

See:O_Exp
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1>
HxExpression HxModel::pow(T0 expr0, T1 expr1)

Creates a power expression. This method is a shortcut for createExpression(O_Pow, expr0, expr1).

See:O_Pow
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxExpression HxModel::cos(T0 expr0)

Creates a cosine expression. This method is a shortcut for createExpression(O_Cos, expr0).

See:O_Cos
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxExpression HxModel::sin(T0 expr0)

Creates a sine expression. This method is a shortcut for createExpression(O_Sin, expr0).

See:O_Sin
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxExpression HxModel::tan(T0 expr0)

Creates a tangent expression. This method is a shortcut for createExpression(O_Tan, expr0).

See:O_Tan
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1, typename T2>
HxExpression HxModel::piecewise(T0 expr0, T1 expr1, T2 expr2)

Creates a piecewise linear expression. This method is a shortcut for createExpression(O_Piecewise, expr, expr1, expr2).

See:O_Piecewise
See:HxModel::createExpression()
Since:5.5
HxExpression HxModel::listVar(hxint n)

Creates a list decision with the given length. A list is a ordered collection of integers within a domain [0, n-1]. This method is a shortcut for createExpression(O_List, n).

Parameters:n – Collection size.
See:O_List
See:HxModel::createExpression()
Since:5.5
HxExpression HxModel::setVar(hxint n)

Creates a set decision with the given length. A set is a unordered collection of integers within a domain [0, n-1]. This method is a shortcut for createExpression(O_Set, n).

Parameters:n – Collection size.
See:O_Set
See:HxModel::createExpression()
Since:8.0
template<typename T0>
HxExpression HxModel::count(T0 expr0)

Creates a count expression. This method is a shortcut for createExpression(O_Count, expr0).

See:O_Count
See:HxModel::createExpression()
Since:5.5
template<typename T0, typename T1>
HxExpression HxModel::indexOf(T0 expr0, T1 expr1)

Creates an indexOf expression. This method is a shortcut for createExpression(O_IndexOf, expr0, expr1).

See:O_IndexOf
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxExpression HxModel::distinct(T0 array)

Creates a distinct expression. This method is a shortcut for createExpression(O_Distinct, array).

See:O_Distinct
See:HxModel::createExpression()
Since:12.5
template<typename T0, typename T1>
HxExpression HxModel::distinct(T0 it, T1 func)

Creates a distinct expression. This method is a shortcut for createExpression(O_Distinct, it, func).

See:O_Distinct
See:HxModel::createExpression()
Since:12.5
template<typename TN>
HxExpression HxModel::intersection(TN... operands)

Creates an intersection expression of intervals. There must be at least one operand. This method is a shortcut for createExpression(O_Intersection, operands).

See:O_Intersection
See:HxModel::createExpression()
Since:13.5
template<typename T0, typename T1>
HxExpression HxModel::intersection(T0 expr0, T1 expr1)

Creates an intersection expression. This method is a shortcut for createExpression(O_Intersection, expr0, expr1).

See:O_Intersection
See:HxModel::createExpression()
Since:12.5
template<typename TN>
HxExpression HxModel::union_(TN... operands)

Creates an union expression. This method is a shortcut for createExpression(O_Union).

See:HxModel::createExpression()
Since:13.5
template<typename T0, typename T1>
HxExpression HxModel::contains(T0 e1, T1 e2)

Creates a contains expression. This method is a shortcut for createExpression(O_Contains, e1, e2).

See:O_Contains
See:HxModel::createExpression()
Since:7.5
template<typename ...TN>
HxExpression HxModel::partition(TN... operands)

Creates a partition expression. This method is a shortcut for createExpression(O_Partition, operands).

See:O_Partition
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxExpression HxModel::partition(T0 array)

Creates a partition expression. This method is a shortcut for createExpression(O_Partition, array).

See:O_Partition
See:HxModel::createExpression()
Since:10.5
template<typename ...TN>
HxExpression HxModel::disjoint(TN... operands)

Creates a disjoint expression. This method is a shortcut for createExpression(O_Disjoint, operands).

See:O_Disjoint
See:HxModel::createExpression()
Since:5.5
template<typename T0>
HxExpression HxModel::disjoint(T0 array)

Creates a disjoint expression. This method is a shortcut for createExpression(O_Disjoint, array).

See:O_Disjoint
See:HxModel::createExpression()
Since:10.5
template<typename ...TN>
HxExpression HxModel::cover(TN... operands)

Creates a cover expression. This method is a shortcut for createExpression(O_Cover, operands).

See:O_Cover
See:HxModel::createExpression()
Since:10.5
template<typename T0>
HxExpression HxModel::cover(T0 array)

Creates a cover expression. This method is a shortcut for createExpression(O_Cover, array).

See:O_Cover
See:HxModel::createExpression()
Since:10.5
template<typename T0, typename T1>
HxExpression HxModel::find(T0 expr0, T1 expr1)

Creates a find expression. This method is a shortcut for createExpression(O_Find, expr0, expr1).

See:O_Find
See:HxModel::createExpression()
Since:10.5
template<typename T0>
HxExpression HxModel::sort(T0 expr0)

Creates a sort expression. This method is a shortcut for createExpression(O_Sort, expr0).

See:O_Sort
See:HxModel::createExpression()
Since:11.0
template<typename T0>
HxExpression HxModel::sort(T0 expr0, expr1)

Creates a sort expression. This method is a shortcut for createExpression(O_Sort, expr0, expr1).

See:O_Sort
See:HxModel::createExpression()
Since:12.5
template<typename T>
HxExpression HxModel::externalFunction(HxExternalFunction<T> *func)

Creates an external function expression. This method is a shortcut for createExternalFunction(func).

See:O_ExternalFunction
See:HxModel::createExternalFunction()
Since:9.5
template<typename T, typename ...ARGS>
HxExpression HxModel::externalFunction(const std::function<T(ARGS...)> &func)

Creates an external function expression. This method is a shortcut for createExternalFunction(func).

See:O_ExternalFunction
See:HxModel::createExternalFunction()
Since:9.5
template<typename T>
HxExpression HxModel::externalFunction(const std::function<T(const HxExternalArgumentValues&)> &func)

Creates an external function expression. This method is a shortcut for createExternalFunction(func).

See:O_ExternalFunction
See:HxModel::createExternalFunction()
Since:9.5
template<typename T>
HxExpression HxModel::lambdaFunction(T functor)

Creates a lambda function expression. This method is a shortcut for createLambdaFunction(functor).

See:O_LambdaFunction
See:HxModel::createLambdaFunction()
Since:9.5
template<typename T0, typename T1>
HxExpression HxModel::range(T0 expr0, T1 expr1)

Creates a range expression, where expr0 is the lower bound (inclusive) and expr1 is the upper bound (exclusive). This method is a shortcut for createExpression(O_Range, expr0, expr1).

See:O_Range
See:HxModel::createExpression()
Since:7.0
int HxModel::getNbExpressions() const

Gets the number of expressions added to this model.

Returns:Number of expressions.
HxExpression HxModel::getExpression(int exprIndex) const

Gets the expression with the given index in this model.

Parameters:exprIndex – Index of the expression.
Returns:Expression with the given index.
HxExpression HxModel::getExpression(const std::string &name) const

Gets the expression with the given name. Throws an exception if no expression with the given name exists.

Parameters:name – Name.
Returns:Expression with the given name.
int HxModel::getNbDecisions() const

Gets the number of decisions in the model. This corresponds to the number of decision variables declared in the model.

Returns:Number of decisions.
HxExpression HxModel::getDecision(int decisionIndex) const

Gets the decision with the given index.

Parameters:decisionIndex – Index of the decision.
Returns:Decision with the given index.
void HxModel::addConstraint(const HxExpression &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 S_Modeling. If the expression is already a constraint, this method does nothing and returns immediately.

param expr:Expression.
void HxModel::constraint(const HxExpression &expr)

Shortcut for addConstraint(expr).

See:HxModel::addConstraint()
Parameters:expr – Expression.
Since:5.5
void HxModel::removeConstraint(const HxExpression &expr)

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

Since:5.0
Parameters:expr – Expression.
void HxModel::removeConstraint(int constraintIndex)

Removes the constraint at the given position in the list of constraints. Only allowed in state S_Modeling.

Since:5.0
Parameters:constraintIndex – position of the constraint to remove.
int HxModel::getNbConstraints() const

Gets the number of constraints added to this model.

Returns:Number of constraints.
HxExpression HxModel::getConstraint(int constraintIndex) const

Gets the constraint with the given index.

Parameters:constraintIndex – Index of the constraint.
Returns:Constraint with the given index.
void HxModel::addObjective(const HxExpression &expr, HxObjectiveDirection direction)

Adds the given expression to the list of objectives to optimize. The same expression can be added more than once. Only allowed in state S_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 – Expression.
  • direction – Optimization direction of this objective.
void HxModel::minimize(const HxExpression &expr)

Shortcut for addObjective(expr, OD_Minimize).

See:HxModel::addObjective()
Parameters:expr – Expression.
Since:5.5
void HxModel::maximize(const HxExpression &expr)

Shortcut for addObjective(expr, OD_Maximize).

See:HxModel::addObjective()
Parameters:expr – Expression.
Since:5.5
void HxModel::removeObjective(int objectiveIndex) const

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::setOptimizedObjective()), or to disable it (with HxPhase::setEnabled()). Only allowed in state S_Modeling.

Since:5.0
Parameters:objectiveIndex – position of the objective to remove.
int HxModel::getNbObjectives() const

Gets the number of objectives added to this model.

HxExpression HxModel::getObjective(int objectiveIndex) const

Gets the objective with the given index.

Parameters:objectiveIndex – Index of the objective.
Returns:Objective with the given index.
HxObjectiveDirection HxModel::getObjectiveDirection(int objectiveIndex) const

Gets the direction of the objective with the given index.

Parameters:objectiveIndex – Index of the objective.
Returns:Objective direction.
int HxModel::getNbOperands() const

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.

Returns:Number of operands.
void HxModel::close()

Closes the model. Only allowed in state S_Modeling. When this method is called, the optimizer is placed in state S_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.

void HxModel::open()

Reopens the model. Only allowed in state S_Stopped. When this method is called, the optimizer is placed in state S_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.

bool HxModel::isClosed() const

Returns true if the model is closed, false otherwise.

Returns:True if the model is closed.
std::string HxModel::toString() const

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.