Originally posted by: QiuFeng
Hi Tobias:
My purpose is to get the fractional solution and tableau to calculate cuts. What I did is just install cut callback and write the node lp to file. I'm using CPLEX 112. Here I wrote down a sample code quickly, it can repeat the behavior in my project. originalModelMIP.lp is the MIP model file and attached to this post again. the root node file will be written into the file node.lp. When the first time callback is called, you will find that vars are fixed in node.lp.
Thanks for your help!
static int CPXPUBLIC
myCutCallbackIC (CPXCENVptr env,
void *cbdata,
int wherefrom,
void *cbhandle,
int *useraction_p)
{
int* node_seq = new int;
CPXgetcallbacknodeinfo( env, cbdata, wherefrom, 0 /*nodeindex*/, CPX_CALLBACK_INFO_NODE_SEQNUM, (void*)node_seq);
cout << "CPX_CALLBACK_INFO_NODE_SEQNUM: "<< *node_seq << endl;
if (*node_seq == 0)//root node
{
CPXLPptr nodelp_p ;
CPXgetcallbacknodelp(env, cbdata, wherefrom, &nodelp_p);
CPXwriteprob(env, nodelp_p, "node.lp", NULL);
}
else{// non-root node
}
*useraction_p = CPX_CALLBACK_SET;
return 0;
}
int main(int argc,char *argv[])
{
CPXENVptr t_env = NULL;
int status = 0;
/* Initialize the CPLEX environment */
t_env = CPXopenCPLEX (&status);
if ( t_env == NULL ) {
char errmsg[1024];
fprintf (stderr, "Could not open CPLEX environment.\n");
CPXgeterrorstring (t_env, status, errmsg);
fprintf (stderr, "%s", errmsg);
return 0;
}
/* Turn on output to the screen */
status = CPXsetintparam (t_env, CPX_PARAM_SCRIND, CPX_ON);
if ( status ) {
fprintf (stderr,
"Failure to turn on screen indicator, error %d.\n", status);
return 0;
}
CPXLPptr t_lp = CPXcreateprob (t_env, &status, "test");
if ( t_lp == NULL ) {
fprintf (stderr, "Failed to create LP.\n");
return 0;
}
CPXreadcopyprob(t_env, t_lp, "originalModelMIP.lp", NULL);
status = CPXsetintparam(t_env, CPX_PARAM_PRELINEAR, CPX_OFF);
status = CPXsetintparam(t_env, CPX_PARAM_MIPCBREDLP, CPX_OFF);
status = CPXsetintparam(t_env, CPX_PARAM_PREIND, CPX_OFF);
status = CPXsetintparam(t_env, CPX_PARAM_NUMERICALEMPHASIS, CPX_ON);
status = CPXsetcutcallbackfunc(t_env, myCutCallbackIC, NULL);
status = CPXmipopt (t_env, t_lp);
return 0;
}
#CPLEXOptimizers#DecisionOptimization