Previous Page: CPXgetbestobjvalFirst PageNext Page: CPXgetchannels

CPXgetcallbackinfo


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.

Return Value

The routine returns a zero on success, and a nonzero if an error occurs. If nonzero, the requested value may not be available for the specific optimization algorithm. For example, the dual objective is not available when using primal simplex.

Synopsis

int CPXgetcallbackinfo (CPXENVptr env,
                        void *cbdata,
                        int wherefrom,
                        int whichinfo,
                        void *result_p);

Arguments


CPXENVptr env
The pointer to the CPLEX environment as returned by one of the CPXopenCPLEX routines.

void *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.

int wherefrom
An 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 whichinfo
An 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_p
A 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:

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  
CPXLPptr  
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 inequalities added  
CPX_CALLBACK_INFO_COVER_COUNT  
int  
number of cover inequalities added  
CPX_CALLBACK_INFO_USER_PROBLEM  
CPXLPptr  
returns pointer to original user problem available for primal, dual, Barrier, MIP  
CPX_CALLBACK_INFO_COVER_COUNT  
int  
number of cover inequalities added  
CPX_CALLBACK_INFO_USER_PROBLEM  
CPXLPptr  
returns pointer to original user problem available for primal, dual, Barrier, MIP  

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 (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);
Previous Page: CPXgetbestobjvalFirst PageNext Page: CPXgetchannels