Description
The CPXgetcallbackinfo() routine is used to access information about the current optimization process from within a user-written callback function.
|
|
This routine is the only routine which can access optimization status information from within a user-written callback function. It is also the only Callable Library routine that may be called from within a user-written callback function, and in fact, may only be called from the callback function. |
int CPXgetcallbackinfo (CPXENVptr env,
void *cbdata,
int wherefrom,
int whichinfo,
void *result_p);
CPXENVptr envThe pointer to the CPLEX environment as returned by one of the
CPXopenCPLEX routines.
void *cbdataThe
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.
int wherefromAn integer value indicating from which optimization algorithm 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() for possible values of wherefrom and their meaning.
int whichinfoAn integer value indicating what specific information 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 below.
void *result_pA generic pointer to a variable of type
double or int, dependent on the value of whichinfo, as documented in the following table:For LP algorithms:
Example
See lpex4.c in the CPLEX User's Manual.mycallback() is a callback function to do this.
int mycallback (CPXENVptr 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 */
}
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);
}
Before optimization, the call CPXsetlpcallbackfunc (env, mycallback, NULL); would be made to tell CPLEX to call the function mycallback() once per iteration. To turn off that capability, the following statement would be included:
CPXsetlpcallbackfunc (env, NULL, NULL);