| Overview | Group | Index | Concepts | 
This is an advanced routine. Advanced routines typically demand a thorough understanding of the algorithms used by ILOG CPLEX. Thus they incur a higher risk of incorrect behavior in your application, behavior that can be difficult to debug. Therefore, ILOG encourages you to consider carefully whether you can accomplish the same task by means of other Callable Library routines instead.
The routine CPXsetheuristiccallbackfunc sets or modifies
 the user-written callback to be called by ILOG CPLEX during MIP optimization
 after the subproblem has been solved to optimality. That callback is not
 called when the subproblem is infeasible or cut off. The callback supplies
 ILOG CPLEX with heuristically-derived integer solutions.
If a linear program must be solved as part of a heuristic callback, make a copy of the node LP and solve the copy, not the CPLEX node LP.
Example
status = CPXsetheuristiccallbackfunc(env, myheuristicfunc, mydata);
See also the example admipex2.c in the standard distribution.
Parameters
env
A pointer to the CPLEX environment, 
 as returned by CPXopenCPLEX.
heuristiccallback
A pointer to a user-written heuristic callback. If this callback is set to NULL, no callback is called during optimization.
cbhandle
A pointer to the user's private data. This pointer is passed to the callback.
Callback description
 int callback (CPXCENVptr env,
               void       *cbdata,
               int        wherefrom,
               void       *cbhandle,
               double     *objval_p,
               double     *x,
               int        *checkfeas_p,
               int        *useraction_p);
 The call to the heuristic callback occurs after an optimal solution to the subproblem has been obtained. The user can provide that solution to start a heuristic for finding an integer solution. The integer solution provided to ILOG CPLEX replaces the incumbent if it has a better objective value. The basis that is saved as part of the incumbent is the optimal basis from the subproblem; it may not be a good basis for starting optimization of the fixed problem.
The integer solution returned to CPLEX is for the original problem if the
 parameter CPX_PARAM_MIPCBREDLP was set to CPX_OFF
 before the call to CPXmipopt that calls the callback.
 Otherwise, it is for the presolved problem.
Callback return value
The callback returns zero if successful and nonzero if an error occurs.
Callback arguments
env
A pointer to the CPLEX environment, as returned by
 CPXopenCPLEX.
cbdata
A pointer passed from the optimization routine to the user-written
 callback to identify the problem being optimized. The only purpose of the
 cbdata pointer is to pass it to the callback information
 routines.
wherefrom
An integer value indicating at which point in the optimization this
 function was called. It has the value
 CPX_CALLBACK_MIP_HEURISTIC for the heuristic callback.
cbhandle
A pointer to user private data.
objval_p
A pointer to a variable that on entry contains the optimal objective value of the subproblem and on return contains the objective value of the integer solution found, if any.
x
An array that on entry contains primal solution values for the subproblem
 and on return contains solution values for the integer solution found, if
 any. The values are from the original problem if the parameter 
 CPX_PARAM_MIPCBREDLP is turned off (that is, set to 
 CPX_OFF); otherwise, the values are from the
 presolved problem.
checkfeas_p
A pointer to an integer that indicates whether or not ILOG CPLEX should
 check the returned integer solution for integer feasibility. The solution is
 checked if checkfeas_p is nonzero. When the solution is checked
 and found to be integer infeasible, it is discarded, and optimization
 continues.
useraction_p
A pointer to an integer to contain the indicator for the action to be taken on completion of the user callback. The table summarizes the possible values.
| Value | Symbolic Constant | Action | 
|---|---|---|
0 | CPX_CALLBACK_DEFAULT | No solution found | 
1 | CPX_CALLBACK_FAIL | Exit optimization | 
2 | CPX_CALLBACK_SET | Use user solution as indicated in return values |