Overview | Group | Tree | Graph | Index | Concepts |
The routine CPXgetcallbackinfo
is used to access
information about the current optimization process from within a
user-written callback function.
This routine is the only routine that can access optimization status information from within a non-advanced user-written callback function. It is also the only Callable Library routine that may be called from within a non-advanced user-written callback function, and in fact, may only be called from the callback function.
Parameters
env
A pointer to the CPLEX environment
as returned by CPXopenCPLEX
.
cbdata
The cbdata
pointer passed to the
user-written callback function. The parameter
cbdata
MUST be the value of
cbdata
passed to the user-written callback function.
wherefrom
An integer value indicating the optimization algorithm
from which the user-written callback function was called.
The parameter wherefrom
MUST be the value of
wherefrom
passed to the user-written callback
function. See CPXgetlpcallbackfunc
CPXgetmipcallbackfunc
,
and CPXgetnetcallbackfunc
for possible values of wherefrom
and their meaning.
whichinfo
An integer value indicating the specific information
that should be returned by CPXgetcallbackinfo
to the result argument. Values for whichinfo
,
the type of the information returned into *result_p
,
plus a description appear in the table.
result_p
A generic pointer to a variable of type double
or int
, dependent on the value of whichinfo
,
as documented in the following tables.
For LP algorithms:
whichinfo | type of *result_p | description |
CPX_CALLBACK_INFO_PRIMAL_OBJ | double | primal objective value |
CPX_CALLBACK_INFO_DUAL_OBJ | double | dual objective value |
CPX_CALLBACK_INFO_PRIM_INFMEAS | double | measure of primal infeasibility |
CPX_CALLBACK_INFO_DUAL_INFMEAS | double | measure of dual infeasibility |
CPX_CALLBACK_INFO_PRIMAL_FEAS | int | 1 if primal feasible, 0 if not |
CPX_CALLBACK_INFO_DUAL_FEAS | int | 1 if dual feasible, 0 if not |
CPX_CALLBACK_INFO_ITCOUNT | int | iteration count |
CPX_CALLBACK_INFO_CROSSOVER_PPUSH | int | primal push crossover itn. count |
CPX_CALLBACK_INFO_CROSSOVER_PEXCH | int | primal exchange crossover itn. count |
CPX_CALLBACK_INFO_CROSSOVER_DPUSH | int | dual push crossover itn. count |
CPX_CALLBACK_INFO_CROSSOVER_DEXCH | int | dual exchange crossover itn. count |
CPX_CALLBACK_INFO_USER_PROBLEM | CPXCLPptr | returns pointer to original user problem; available for primal, dual,barrier, mip |
For Network algorithms:
whichinfo | type of *result_p | description |
CPX_CALLBACK_INFO_PRIMAL_OBJ | double | primal objective value |
CPX_CALLBACK_INFO_PRIM_INFMEAS | double | measure of primal infeasibility |
CPX_CALLBACK_INFO_ITCOUNT | int | iteration count |
CPX_CALLBACK_INFO_PRIMAL_FEAS | int | 1 if primal feasible, 0 if not |
For Presolve algorithms:
whichinfo | type of *result_p | description |
CPX_CALLBACK_INFO_PRESOLVE_ROWSGONE | int | number of rows eliminated |
CPX_CALLBACK_INFO_PRESOLVE_COLSGONE | int | number of columns eliminated |
CPX_CALLBACK_INFO_PRESOLVE_AGGSUBST | int | number of aggregator substitutions |
CPX_CALLBACK_INFO_PRESOLVE_COEFFS | int | number of modified coefficients |
For MIP algorithms:
whichinfo | type of *result_p | description |
CPX_CALLBACK_INFO_BEST_INTEGER | double | obj. value of best integer solution |
CPX_CALLBACK_INFO_BEST_REMAINING | double | obj. value of best remaining node |
CPX_CALLBACK_INFO_NODE_COUNT | int | total number of nodes solved |
CPX_CALLBACK_INFO_NODES_LEFT | int | number of remaining nodes |
CPX_CALLBACK_INFO_MIP_ITERATIONS | int | total number of MIP iterations |
CPX_CALLBACK_INFO_MIP_FEAS | int | returns 1 if feasible solution exists; otherwise, 0 |
CPX_CALLBACK_INFO_CUTOFF | double | updated cutoff value |
CPX_CALLBACK_INFO_CLIQUE_COUNT | int | number of clique cuts added |
CPX_CALLBACK_INFO_COVER_COUNT | int | number of cover cuts added |
CPX_CALLBACK_INFO_DISJCUT_COUNT | int | number of disjunctive cuts added |
CPX_CALLBACK_INFO_FLOWCOVER_COUNT | int | number of flow cover cuts added |
CPX_CALLBACK_INFO_FLOWPATH_COUNT | int | number of flow path cuts added |
CPX_CALLBACK_INFO_FRACCUT_COUNT | int | number of Gomory fractional cuts added |
CPX_CALLBACK_INFO_GUBCOVER_COUNT | int | number of GUB cover cuts added |
CPX_CALLBACK_INFO_IMPLBD_COUNT | int | number of implied bound cuts added |
CPX_CALLBACK_INFO_MIRCUT_COUNT | int | number of mixed integer rounding cuts added |
CPX_CALLBACK_INFO_USER_PROBLEM | CPXCLPptr | returns pointer to original user problem; available for primal, dual, barrier, MIP |
CPX_CALLBACK_INFO_PROBE_PHASE | int | current phase of probing (0-3) |
CPX_CALLBACK_INFO_PROBE_PROGRESS | double | fraction of probing phase completed (0.0-1.0) |
CPX_CALLBACK_INFO_FRACCUT_PROGRESS | double | fraction of Gomory cut generation for the pass completed (0.0 - 1.0) |
CPX_CALLBACK_INFO_DISJCUT_PROGRESS | double | fraction of disjunctive cut generation for the pass completed (0.0 - 1.0) |
CPX_CALLBACK_INFO_FLOWMIR_PROGRESS | double | fraction of flow cover and MIR cut generation for the pass completed (0.0 - 1.0) |
CPX_CALLBACK_INFO_MY_THREAD_NUM | int | identifier of the parallel thread making this call |
CPX_CALLBACK_INFO_USER_THREADS | int | total number of parallel threads currently running |
Example
See lpex4.c
in the CPLEX User's Manual.
Suppose you want to know the objective value on each iteration for a
graphical user display. In addition, if primal simplex is not feasible after
1000 iterations, you want to stop the optimization. The function
mycallback
is a callback function to do this.
int mycallback (CPXCENVptr env, void *cbdata, int wherefrom, void *cbhandle) { int itcount; double objval; int ispfeas; int status = 0; if ( wherefrom == CPX_CALLBACK_PRIMAL ) { status = CPXgetcallbackinfo (env, cbdata, wherefrom, CPX_CALLBACK_INFO_PRIMAL_FEAS, &ispfeas); if ( status ) { fprintf (stderr,"error %d in CPXgetcallbackinfo\n", status); status = 1; goto TERMINATE; } if ( ispfeas ) { status = CPXgetcallbackinfo (env, cbdata, wherefrom, CPX_CALLBACK_INFO_PRIMAL_OBJ, &objval) ) if ( status ) { fprintf (stderr,"error %d in CPXgetcallbackinfo\n", status); status = 1; goto TERMINATE; } /* Do some graphics with the value of objval */ } else { status = CPXgetcallbackinfo (env, cbdata, wherefrom, CPX_CALLBACK_INFO_ITCOUNT, &itcount); if ( status ) { fprintf (stderr,"error %d in CPXgetcallbackinfo\n", status); status = 1; goto TERMINATE; } if ( itcount > 1000 ) status = 1; } } TERMINATE: return (status); }