Originally posted by: gangulo
As an example, consider the following code:
#include <ilcplex/cplex.h> #include <ctype.h> #include <stdlib.h> #include <string.h> #include <math.h>
int heuristicCallback (CPXCENVptr env,
void *cbdata,
int wherefrom,
void *cbhandle,
double *objval_p,
double *x,
int *checkfeas_p,
int *useraction_p);
int incumbentCallback (CPXCENVptr env,
void *cbdata,
int wherefrom,
void *cbhandle,
double objval,
double *x,
int *isfeas_p,
int *useraction_p);
int main (
int argc,
char *argv[])
{
int status = 0; CPXENVptr env = NULL; CPXLPptr lp = NULL; env = CPXopenCPLEX (&status); status = CPXsetintparam (env, CPX_PARAM_SCRIND, CPX_ON); lp = CPXcreateprob (env, &status, argv[1]); status = CPXreadcopyprob (env, lp, argv[1], NULL); status = CPXsetheuristiccallbackfunc (env, heuristicCallback, NULL); status = CPXsetincumbentcallbackfunc(env, incumbentCallback, NULL); status = CPXsetintparam(env, CPX_PARAM_REDUCE, CPX_PREREDUCE_PRIMALONLY); status = CPXmipopt (env, lp);
return 0;
}
int heuristicCallback (CPXCENVptr env,
void *cbdata,
int wherefrom,
void *cbhandle,
double *objval_p,
double *x,
int *checkfeas_p,
int *useraction_p)
{ fprintf (stdout,
"H\n");
return 0;
}
int incumbentCallback (CPXCENVptr env,
void *cbdata,
int wherefrom,
void *cbhandle,
double objval,
double *x,
int *isfeas_p,
int *useraction_p)
{ fprintf (stdout,
"I\n"); *isfeas_p = 0; *useraction_p = CPX_CALLBACK_SET;
return 0;
}
The code reads an lp/mps file and rejects all solutions (note that I have to turn off dual reductions), but I think it should call the heuristic anyway. As an example, try
Minimize obj: 40 x_1 + 60 x_2 + 47 x_3 + 68 x_4 + 60 x_5 Binaries x_1 x_2 x_3 x_4 x_5 End
In the output, I only see I's and no H's, why?
#CPLEXOptimizers#DecisionOptimization