> Advanced Programming Techniques > Using Callbacks > Implementing Callbacks in the Callable Library

ILOG CPLEX optimization routines in the Callable Library incorporate a callback facility to allow your application to transfer control temporarily from ILOG CPLEX to the calling application. Using callbacks, your application can implement interrupt capability, for example, or create displays of optimization progress. Once control is transferred back to a function in the calling application, the calling application can retrieve specific information about the current optimization from the routine CPXgetcallbackinfo. Optionally, the calling application can then tell ILOG CPLEX to discontinue optimization.

To implement and use a callback in your application, you must first write the callback function and then tell ILOG CPLEX about it. For more information about the ILOG CPLEX Callable Library routines for callbacks, see the ILOG CPLEX Reference Manual. In that reference manual, the group optim.cplex.callable.callbacks gives you direct access to all such routines.

Setting Callbacks

In the Callable Library, diagnostic callbacks are organized into two groups: LP callbacks and MIP callbacks. For each group, one callback function can be set by the functions CPXsetlpcallbackfunc and CPXsetmipcallbackfunc, respectively. You can distinguish between the actual callbacks by querying the parameter wherefrom passed to the callback function as a parameter by ILOG CPLEX.

The LP callback is also called during the solution of problems of type QP and QCP.

Callbacks for LP/QP/QCPs and for MIPs

ILOG CPLEX will evaluate two user-defined callback functions, one during the solution of LP, QP, and QCP problems and one during the solution of MIP problems. ILOG CPLEX calls the LP/QP/QCP callback once per iteration during the solution of an LP, QP, or QCP problem and periodically during the presolve. ILOG CPLEX calls the MIP callback periodically during the probing phase of MIP preprocessing, periodically during cut generation, and once before each subproblem is solved in the branch & cut process.

Every user-defined callback must have these arguments:

The arguments wherefrom and cbdata should be used only in calls to CPXgetcallbackinfo.