This page is for an old version of Hexaly Optimizer.
We recommend that you update your version and read the documentation for the
latest stable release.
LSBlackBoxFunction Interface¶
-
template<typename
T
>
classLSBlackBoxFunction
¶ Black-box function interface. To use your own black-box functions within LocalSolver, you have to first define your black-box function in one of two ways:
- Implement the LSBlackBoxFunction interface with the call method. The
call method must take a
LSBlackBoxArgumentValues
as single argument and must return a lsint or lsdouble value. The argument values contain the values of the expressions passed to the function. A distinction is made between integer arguments (bool, int) and floating point arguments (double). - If your program is compiled with C++11, you can use a function, a
functor or a lambda function instead. This function may take any
number of lsint and lsdouble arguments, or alternatively a single
LSBlackBoxArgumentValues
. It must return a lsint or lsdouble value.
Then:
- Instantiate the function as an LSExpression with
LSModel::createBlackBoxFunction()
or the dedicated shortcutLSModel::blackBoxFunction()
. - Pass arguments to your function and call it using
LSModel::call()
. The first operand must the LSExpression returned by createBlackBoxFunction. The other operands must be LSExpressions, whose values will be made accessible to your black-box function when it is called.
Note 1: LocalSolver does not manage memory of objects created outside of its environment. You are responsible for the lifetime of your LSBlackBoxFunction, which must last as long as the search is active.
Node 2: You can provide additional data for your function (such as bounds or the maximum number of evaluations) with the help of the
LSBlackBoxContext
associated with your function (seeLSExpression::getBlackBoxContext()
).Since: 9.5 - Implement the LSBlackBoxFunction interface with the call method. The
call method must take a
Summary¶
call |
The function to call. |
~LSBlackBoxFunction |
Default virtual destructor. |
Functions¶
-
virtual T
LSBlackBoxFunction
::
call
(const LSBlackBoxArgumentValues &argumentValues) = 0¶ The function to call. The argument values contain the arguments to pass to your function.
Parameters: argumentValues – Values of the arguments passed to the function. Returns: The value of the LSExpression.
-
virtual
LSBlackBoxFunction
::
~LSBlackBoxFunction
()¶ Default virtual destructor.