CPXXsetsolvecallbackfunc and CPXsetsolvecallbackfunc
The routine CPXXsetsolvecallbackfunc/CPXsetsolvecallbackfunc sets and modifies the
user-written callback to be called during MIP optimization to optimize
subproblems (for example, node and heuristic subproblems).
int CPXXsetsolvecallbackfunc( CPXENVptr env, int(CPXPUBLIC *solvecallback)(CPXX_CALLBACK_SOLVE_ARGS), void * cbhandle )
int CPXsetsolvecallbackfunc( CPXENVptr env, int(CPXPUBLIC *solvecallback)(CALLBACK_SOLVE_ARGS), void * cbhandle )
Description
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 CPXXsetsolvecallbackfunc/CPXsetsolvecallbackfunc sets and modifies the
user-written callback to be called during MIP optimization to optimize
subproblems (for example, node and heuristic subproblems).
Arguments
- env
-
A pointer to the CPLEX environment, as returned by
CPXXopenCPLEX/CPXopenCPLEX. - solvecallback
-
A pointer to a user-written solve callback. If the callback is set to
NULL, no callback is called during optimization. - cbhandle
-
A pointer to user 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 = CPXsetsolvecallbackfunc(env, mysolvefunc, mydata);
See also the example admipex1.c
distributed with the product.
Before you invoke
CPXXgetcallbacknodeintfeas/CPXgetcallbacknodeintfeas
from a solve callback function, (for example, as part of the
user-written callback set by CPXXsetsolvecallbackfunc/CPXsetsolvecallbackfunc)
a solution must exist. That is,
you must first create the solution by calling a CPLEX
optimization routine, such as CPXXdualopt/CPXdualopt,
and then verify that this routine generated a solution by
checking its return value before
you call CPXXgetcallbacknodeintfeas/CPXgetcallbacknodeintfeas.
Callback description
int CPXPUBLIC
callback (CPXCENVptr env,
void *cbdata,
int wherefrom,
void *cbhandle,
int *useraction_p);
CPLEX calls the solve callback before CPLEX solves the
subproblem currently associated with the current node.
The user can choose to solve the
subproblem in the solve callback instead by setting the user action
argument of the callback. The optimization that the user provides to solve
the subproblem must provide a CPLEX solution. That is, the
Callable Library routine CPXXgetstat/CPXgetstat
must return a nonzero value. The user may access the
lp pointer of the subproblem with the Callable Library routine
CPXXgetcallbacknodelp/CPXgetcallbacknodelp.
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 where in the optimization this function was
called. It will have the value CPX_CALLBACK_MIP_SOLVE.
cbhandle
A pointer to user private data.
useraction_p
A pointer to an integer specifying the action to be taken on completion of the user callback. Table 11 summarizes the possible actions.
| Value | Symbolic Constant | Action |
|---|---|---|
0 |
CPX_CALLBACK_DEFAULT |
Use CPLEX subproblem optimizer |
1 |
CPX_CALLBACK_FAIL |
Exit optimization |
2 |
CPX_CALLBACK_SET |
The subproblem has been solved in the callback |