Interface HxIntExternalFunction


  • public interface HxIntExternalFunction
    Integer external function interface. To use your own integer functions with Hexaly Optimizer, you have to proceed in 3 steps:
    1. Implement the HxIntExternalFunction interface with the call method. The call method must take a HxExternalArgumentValues and must return an integer 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).
    2. Instanciate the function as an HxExpression with HxModel.createIntExternalFunction(com.hexaly.optimizer.HxIntExternalFunction) or with the shortcut HxModel.intExternalFunction(com.hexaly.optimizer.HxIntExternalFunction).
    3. Pass arguments to your function and call it. For that, you have to create expressions of type HxOperator.Call. The first operand must be your external function. The other operands must be HxExpressions. Their value will be made accessible to your external function through the argument values.

    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.

    Note 2: Your functions must be thread-safe. According to the "nbThreads" 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 with HxParam.setNbThreads(int).

    Note 3: You can provide additional data for your function (such as lower and upper bounds) with the help of the HxExternalContext associated with the function (see HxExpression.getExternalContext()).

    Since:
    9.5
    • Method Detail

      • call

        long call​(HxExternalArgumentValues argumentValues)
        The function to call. The argument values contain the arguments to pass to your function.
        Parameters:
        argumentValues - Argument values containing the arguments of the function.
        Returns:
        The value of the HxExpression.