Hexaly Optimizer
Object-oriented APIs are provided for C++, allowing a full integration of Hexaly
Optimizer in your C++ business applications. Hexaly’s APIs are lightweight, with
only a few classes to manipulate. Note that Hexaly Optimizer is a model & run
math programming solver: having instantiated the model, no additional code has
to be written in order to run the optimizer.
Build your model
First, you have to create a HexalyOptimizer
environment. It is the
main class of the Hexaly Optimizer library. Then, use the methods of the
class HxModel
to build your model with expressions. Expressions are
a particularly important concept in Hexaly Optimizer. In fact, every aspect
of a model is an expression: variables, objectives and even constraints are
HxExpression
. There are 3 different ways to create these
HxExpressions with the class HxModel:
You can use the available shortcut methods like
HxModel::sum()
, HxModel::eq()
,
HxModel::boolVar()
or HxModel::sqrt()
.
You can also use the more generic version of these operators with the
method HxModel::createExpression()
. It takes the type of the
expression to add as first argument, then the list of the operands of
the expression. It is also possible to add operands one-by-one with the
method HxExpression::addOperand()
.
See HxOperator
for the complete list of available operators.
Finally, you can use the overloaded operators for common operations:
+, -, *, /, <=, >=, ==, !=, >, <, %, [], &&, ||, !, ()
.
Most of these methods accept HxExpressions as arguments but also integers or
double constants. If you prefer, you can also create constants explicitly
with HxModel::createConstant()
.
Solve your model
Once you have created your model, you have to close it with
HxModel::close()
and call HexalyOptimizer::solve()
to launch
the resolution. By default, the search will continue until an optimal
solution is found. To set a time limit or an iteration limit, create
a HxPhase
, with createPhase()
, then
set the according attributes.
Retrieve the solution
You can retrieve the solution with the method
HexalyOptimizer::getSolution()
. The solution carries the values of
all expressions in the model and the status of the solution.
There are 4 different statuses:
SS_Inconsistent
: The optimizer was able to prove
that the model admits no feasible solution.
SS_Infeasible
: The solution is infeasible.
Some constraints or expressions are violated.
SS_Feasible
: The solution is feasible but
the optimality was not proven.
SS_Optimal
: The solution is optimal.
All objective bounds are reached.
You can also directly use the methods getValue()
or getDoubleValue()
available on HxExpression
to get the value of the expression in the solution.
Consult statistics
You can retrieve statistics of the search (number of iterations, % of
feasible moves, etc.) with the HxStatistics
object. Statistics
are provided for the global search or for each phase.
Error handling
All classes and methods of the Hexaly Optimizer API can throw exceptions.
The exception type related to Hexaly Optimizer errors is
HxException
.