Cut callback to get LP with cuts
int cutCallbackShareRootCuts (CPXCENVptr env,
void *cbdata,
int wherefrom,
void *cbhandle,
int *useraction_p)
{
int status;
*useraction_p = CPX_CALLBACK_DEFAULT;
Problem *tempProblem = (Problem*) cbhandle;
Problem &problem = *tempProblem;
// cutCallbackRootCalled is a flag to avoid calling the callback again and again
// CPX_CALLBACK_MIP_CUT_LAST indicates that CPLEX is done adding cuts and the user has a last chance to add cuts
if(problem.cutCallbackRootCalled == 0 && wherefrom == CPX_CALLBACK_MIP_CUT_LAST)
{
// With this, we stop the optimization after the callback is executed
*useraction_p = CPX_CALLBACK_FAIL;
problem.cutCallbackRootCalled = 1;
CPXLPptr tmpLp;
status = CPXgetcallbacknodelp(env, cbdata, wherefrom, &tmpLp);
DBG_IF_RETURN(status, 1, "Error getting callback lp");
status = CPXwriteprob(env, tmpLp, "ProblemWithCuts.lp", NULL);
DBG_IF_RETURN(status, 1, "Error writing cut callback lp");
}
return 0;
}
Callback function is in Callback.cpp
To use the callback function, add it to the CPLEX env before calling CPXmipopt:
status = CPXsetusercutcallbackfunc(mainEnv, cutCallbackShareRootCuts, this);
DBG_IF_RETURN(status, 1, "Error setting cut callback");