NO FRAMES

CPXgetcallbackinfo

public int CPXgetcallbackinfo(CPXCENVptr env, void * cbdata, int wherefrom, int whichinfo, void * result_p)
Definition file: cplex.h

The routine CPXgetcallbackinfo accesses information about the current optimization process from within a user-written callback function.

Note

This routine is the only routine that can access optimization status information from within a nonadvanced user-written callback function. It is also the only Callable Library routine that may be called from within a nonadvanced 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 argument cbdata MUST be the value of cbdata passed to the user-written callback function.

wherefrom

An integer value specifying the optimization algorithm from which the user-written callback function was called. The argument 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 specifying 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:

whichinfotype of *result_pdescription
CPX_CALLBACK_INFO_PRIMAL_OBJdoubleprimal objective value
CPX_CALLBACK_INFO_DUAL_OBJdoubledual objective value
CPX_CALLBACK_INFO_PRIM_INFMEASdoublemeasure of primal infeasibility
CPX_CALLBACK_INFO_DUAL_INFMEASdoublemeasure of dual infeasibility
CPX_CALLBACK_INFO_PRIMAL_FEASint1 if primal feasible, 0 if not
CPX_CALLBACK_INFO_DUAL_FEASint1 if dual feasible, 0 if not
CPX_CALLBACK_INFO_ITCOUNTintiteration count
CPX_CALLBACK_INFO_CROSSOVER_PPUSHintprimal push crossover itn. count
CPX_CALLBACK_INFO_CROSSOVER_PEXCHintprimal exchange crossover itn. count
CPX_CALLBACK_INFO_CROSSOVER_DPUSHintdual push crossover itn. count
CPX_CALLBACK_INFO_CROSSOVER_DEXCHintdual exchange crossover itn. count
CPX_CALLBACK_INFO_USER_PROBLEMCPXCLPptrreturns pointer to original user problem; available for primal, dual, barrier, mip

For Network algorithms:

whichinfotype of *result_pdescription
CPX_CALLBACK_INFO_PRIMAL_OBJdoubleprimal objective value
CPX_CALLBACK_INFO_PRIM_INFMEASdoublemeasure of primal infeasibility
CPX_CALLBACK_INFO_ITCOUNTintiteration count
CPX_CALLBACK_INFO_PRIMAL_FEASint1 if primal feasible, 0 if not

For Presolve algorithms:

whichinfotype of *result_pdescription
CPX_CALLBACK_INFO_PRESOLVE_ROWSGONEintnumber of rows eliminated
CPX_CALLBACK_INFO_PRESOLVE_COLSGONEintnumber of columns eliminated
CPX_CALLBACK_INFO_PRESOLVE_AGGSUBSTintnumber of aggregator substitutions
CPX_CALLBACK_INFO_PRESOLVE_COEFFSintnumber of modified coefficients

For MIP algorithms and informational callbacks:

whichinfotype of *result_pdescription
CPX_CALLBACK_INFO_BEST_INTEGERdoubleobj. value of best integer solution
CPX_CALLBACK_INFO_BEST_REMAININGdoubleobj. value of best remaining node
CPX_CALLBACK_INFO_NODE_COUNTinttotal number of nodes solved
CPX_CALLBACK_INFO_NODES_LEFTintnumber of remaining nodes
CPX_CALLBACK_INFO_MIP_ITERATIONSinttotal number of MIP iterations
CPX_CALLBACK_INFO_MIP_FEASintreturns 1 if feasible solution exists; otherwise, 0
CPX_CALLBACK_INFO_CUTOFFdoubleupdated cutoff value
CPX_CALLBACK_INFO_PROBE_PHASEintcurrent phase of probing (0-3)
CPX_CALLBACK_INFO_PROBE_PROGRESSdoublefraction of probing phase completed (0.0-1.0)
CPX_CALLBACK_INFO_FRACCUT_PROGRESSdoublefraction of Gomory cut generation for the pass completed (0.0 - 1.0)
CPX_CALLBACK_INFO_DISJCUT_PROGRESSdoublefraction of disjunctive cut generation for the pass completed (0.0 - 1.0)
CPX_CALLBACK_INFO_FLOWMIR_PROGRESSdoublefraction of flow cover and MIR cut generation for the pass completed (0.0 - 1.0)

For MIP algorithms and advanced callbacks:

whichinfotype of *result_pdescription
CPX_CALLBACK_INFO_BEST_INTEGERdoubleobj. value of best integer solution
CPX_CALLBACK_INFO_BEST_REMAININGdoubleobj. value of best remaining node
CPX_CALLBACK_INFO_NODE_COUNTinttotal number of nodes solved
CPX_CALLBACK_INFO_NODES_LEFTintnumber of remaining nodes
CPX_CALLBACK_INFO_MIP_ITERATIONSinttotal number of MIP iterations
CPX_CALLBACK_INFO_MIP_FEASintreturns 1 if feasible solution exists; otherwise, 0
CPX_CALLBACK_INFO_CUTOFFdoubleupdated cutoff value
CPX_CALLBACK_INFO_CLIQUE_COUNTintnumber of clique cuts added
CPX_CALLBACK_INFO_COVER_COUNTintnumber of cover cuts added
CPX_CALLBACK_INFO_DISJCUT_COUNTintnumber of disjunctive cuts added
CPX_CALLBACK_INFO_FLOWCOVER_COUNTintnumber of flow cover cuts added
CPX_CALLBACK_INFO_FLOWPATH_COUNTintnumber of flow path cuts added
CPX_CALLBACK_INFO_FRACCUT_COUNTintnumber of Gomory fractional cuts added
CPX_CALLBACK_INFO_GUBCOVER_COUNTintnumber of GUB cover cuts added
CPX_CALLBACK_INFO_IMPLBD_COUNTintnumber of implied bound cuts added
CPX_CALLBACK_INFO_MIRCUT_COUNTintnumber of mixed integer rounding cuts added
CPX_CALLBACK_INFO_ZEROHALFCUT_COUNTintnumber of zero-half cuts added
CPX_CALLBACK_INFO_USER_PROBLEMCPXCLPptrreturns pointer to original user problem; available for primal, dual, barrier, MIP
CPX_CALLBACK_INFO_PROBE_PHASEintcurrent phase of probing (0-3)
CPX_CALLBACK_INFO_PROBE_PROGRESSdoublefraction of probing phase completed (0.0-1.0)
CPX_CALLBACK_INFO_FRACCUT_PROGRESSdoublefraction of Gomory cut generation for the pass completed (0.0 - 1.0)
CPX_CALLBACK_INFO_DISJCUT_PROGRESSdoublefraction of disjunctive cut generation for the pass completed (0.0 - 1.0)
CPX_CALLBACK_INFO_FLOWMIR_PROGRESSdoublefraction of flow cover and MIR cut generation for the pass completed (0.0 - 1.0)
CPX_CALLBACK_INFO_MY_THREAD_NUMintidentifier of the parallel thread making this call
CPX_CALLBACK_INFO_USER_THREADSinttotal 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;
       }
       
     }
     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);
 }
 

Returns:

The routine returns zero if successful and 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 from primal simplex.