LSArrayExternalFunction Interface¶
-
template<typename T>
class LSArrayExternalFunction¶ Array external function interface. To use your own external functions within LocalSolver, first you have to implement the LSArrayExternalFunction interface with the call method. The call method must take a
LSExternalArgumentValues
as first argument and the reference of a vector of lsint or lsdouble as second argument. 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). The vector must be filled with the values to be returned by your function.Then:
Instantiate the function as an LSExpression with
LSModel::createExternalFunction()
or the dedicated shortcutLSModel::externalFunction()
.Pass arguments to your function and call it using
LSModel::call()
. The first operand must the LSExpression returned by createExternalFunction. The other operands must be LSExpressions, whose values will be made accessible to your external function when it is called.
Note 1: Most of the time your external function will be called when the solver is in state
S_Running
. Do not attempt to call any method of the solver (to retrieve statistics, values of LSExpressions, etc.) in that state or an exception will be thrown.Note 2: Your functions must be thread-safe. According to the “nbThreads” parameter, LocalSolver 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 LocalSolver to one thread with
LSParam::setNbThreads()
.Note 3: LocalSolver does not manage memory of objects created outside of its environment. You are responsible for the lifetime of your LSArrayExternalFunction, which must last as long as the search is active.
Node 4: You can provide additional data for your function (such as lower and upper bounds) with the help of the
LSExternalContext
associated with your function (seeLSExpression::getExternalContext()
).- Since:
11.0
Summary¶
The function to call. |
|
Default virtual destructor. |
Functions¶
-
virtual void LSArrayExternalFunction::call(const LSExternalArgumentValues &argumentValues, std::vector<T> &returnValues) = 0¶
The function to call. The argument values contain the arguments to pass to your function. The vector of return values must be filled with the values to be returned by your function.
- Parameters:
argumentValues – Values of the arguments passed to the function.
returnValues – Vector of return values of the function.
-
virtual LSArrayExternalFunction::~LSArrayExternalFunction()¶
Default virtual destructor.