ILOG CPLEX 11.0 User's Manual > Advanced Programming Techniques > Advanced MIP Control Interface > Heuristic Callback

The first user callback we consider is the heuristic callback. The first step in using this callback is to call CPXsetheuristiccallbackfunc, with a pointer to a callback function and optionally a pointer to user private data as arguments. We refer the reader to advanced example admipex2.c for further details of how this callback is used. Once this routine has been called, CPLEX calls the user callback function at every viable node in the branch & cut tree (we call a node viable if its LP relaxation is feasible and its relaxation objective value is better than that of the best available integer solution). The user callback routine is called with the solution vector for the current relaxation as input. The callback function should return a feasible solution vector, if one is found, as output.

The advanced MIP control interface provides several routines that allow the user callback to gather information that may be useful in finding heuristic solutions. The routines CPXgetcallbackgloballb and CPXgetcallbackglobalub, for example, return the tightest known global lower and upper bounds on all the variables in the problem. No feasible solution whose objective is better than that of the best known solution can violate these bounds. Similarly, the routines CPXgetcallbacknodelb and CPXgetcallbacknodeub return variable bounds at this node. These reflect the bound adjustments made during branching. The routine CPXgetcallbackincumbent returns the current incumbent - the best known feasible solution. The routine CPXgetcallbacklp returns a pointer to the MIP problem (presolved or unpresolved, depending on the CPX_PARAM_MIPCBREDLP parameter). This pointer can be used to obtain various information about the problem (variable types, etc.), or as an argument for the advanced presolve interface if the user wishes to manually translate between presolved and unpresolved values. In addition, the callback can use the cbdata parameter passed to it, along with routine CPXgetcallbacknodelp, to obtain a pointer to the node relaxation LP. This can be used to access desired information about the relaxation (row count, column count, etc.). Note that in both cases, the user should never use the pointers obtained from these callbacks to modify the associated problems.

As noted earlier, the CPX_PARAM_MIPCBREDLP parameter influences the arguments to the user callback routine. If this parameter is set to its default value of CPX_ON (1), the solution vector returned to the callback, and any feasible solutions returned by the callback, are presolved vectors. They contain one value for each variable in the presolved problem. The same is true of the various callback support routines (CPXgetcallbackgloballb, etc.). If the parameter is set to CPX_OFF (0), all these vectors relate to variables of the original problem. Note that this parameter should not be changed in the middle of an optimization.

The user should be aware that the branch & cut process works with the presolved problem, so the code will incur some cost when translating from presolved to original values. This cost is usually small, but can sometimes be significant.

We should also note that if a user wishes to solve linear programs as part of a heuristic callback, the user must make a copy of the node LP (for example, using CPXcloneprob). The user should not modify the CPLEX node LP.