Callback interface

Describes the common callback interface.

Two callback classes in the hierarchy need extra attention. The first is the base class IloCplex::CallbackI in the C++ API (IloCplex.Callback in the Java API or Cplex.Callback in the .NET API or callbacks.Callback in the Python API). Since there is no corresponding callback in the Callable Library (C API), this class cannot be used for implementing user callbacks. Instead, its purpose is to provide an interface common to all callback functions.

This common interface consists of these methods:

  • getModel, which returns the model that is extracted to the IloCplex object that is calling the callback;

  • getEnv, which returns the corresponding environment (C++ only),

  • abort, which aborts the current optimization.

Further, methods getNrows and getNcols allow you to query the number of rows and columns of the current cplex LP matrix. These methods can be called from all callbacks.

Note:

For C++ users, no manipulation of the model or, more precisely, no manipulation of any extracted modeling object is allowed during the execution of a callback. No modification is allowed of any array or expression not local to the callback function itself (that is, constructed in the callback and end –ed in the callback). The only exception is the modification of array elements. For example, x[i] = 0 is permissible, whereas x.add(0) is not permissible unless x is a local array of the callback.