CPXXsetheuristiccallbackfunc and CPXsetheuristiccallbackfunc

The routine CPXXsetheuristiccallbackfunc/CPXsetheuristiccallbackfunc sets or modifies the user-written callback to be called by CPLEX during MIP optimization after the subproblem has been solved to optimality.

int  CPXXsetheuristiccallbackfunc( CPXENVptr env, int(CPXPUBLIC *heuristiccallback)(CPXX_CALLBACK_HEURISTIC_ARGS), void * cbhandle )

int  CPXsetheuristiccallbackfunc( CPXENVptr env, int(CPXPUBLIC *heuristiccallback)(CALLBACK_HEURISTIC_ARGS), void * cbhandle )

Description

Warning:

This is an advanced routine. Advanced routines typically demand a thorough understanding of the algorithms used by CPLEX. Thus they incur a higher risk of incorrect behavior in your application, behavior that can be difficult to debug. Therefore, the team encourages you to consider carefully whether you can accomplish the same task by means of other Callable Library routines instead.

The routine CPXXsetheuristiccallbackfunc/CPXsetheuristiccallbackfunc sets or modifies the user-written callback to be called by 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 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.

Arguments

env

A pointer to the CPLEX environment, as returned by CPXXopenCPLEX/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.

Return

The routine returns 0 (zero) if successful and nonzero if an error occurs.

Example


 status = CPXsetheuristiccallbackfunc(env, myheuristicfunc, mydata);

See also the example admipex2.c in the standard distribution.

Callback description


 int CPXPUBLIC
 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. (Do not provide multiple solutions: the most recently provided solution overwrites previously provided solutions.) The integer solution provided to 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 MIP callback switch between original model and reduced, presolved model (CPXPARAM_MIP_Strategy_CallbackReducedLP) was set to CPX_OFF before the call to CPXXmipopt/CPXmipopt that calls the callback. Otherwise, it is for the presolved problem.

Callback return value

The callback returns 0 (zero) if successful and nonzero if an error occurs.

Callback arguments

env

A pointer to the CPLEX environment, as returned by CPXXopenCPLEX/CPXopenCPLEX.

cbdata

A pointer to pass to functions that obtain callback-specific information, such as the number of integer-infeasible values at the current node, or that take callback-specific action, such as to add a cut in a user cut callback.

wherefrom

An integer value reporting 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 MIP callback switch between original model and reduced, presolved model (CPXPARAM_MIP_Strategy_CallbackReducedLP) 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 specifies whether or not 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 specifier of the action to be taken on completion of the user callback. The table summarizes the possible values.

Table 1. Actions to be taken after a user-written heuristic callback
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 reported in return values