Originally posted by: MarkusS.
Hello,
I am working with Concert and CPLEX 12.3 and have a model, where I want to solve an ILP in a subproblem to generate cuts, which strengthen the formulation.
However, I get an "accessing IloAlgorithm through 0 handle" error in the Callback (I want to add the myCover Expression to the original model)
Here is my code-snippet of the callback:
ILOUSERCUTCALLBACK3(CoverCallback, Graph*, G,
const IloBoolVarArray&, y, int, U_)
{
int n_nodes=G->get_number_of_nodes();
int U=U_; IloCplex subCplex; IloEnv subEnv; IloModel subModel; IloNumArray y_lp(getEnv(),n_nodes); getValues(y_lp,y);
try
{ subEnv=IloEnv(); subModel=IloModel(subEnv); IloBoolVarArray z(subEnv, n_nodes);
for (
int i=0;i<n_nodes;i++)
{ stringstream myname; myname <<
"z_" << i; z[i]=IloBoolVar(subEnv, myname.str().c_str());
} IloExpr myKP(subEnv);
for (
int i=0;i<n_nodes;i++)
{
int r=G->get_revenue(i); myKP+=r*z[i];
} subModel.add(myKP<=U); myKP.end(); IloExpr myObjective(subEnv);
for (
int i=0;i<n_nodes;i++)
{ myObjective+=y_lp[i]*z[i];
} subModel.add(IloMinimize(subEnv,myObjective)); myObjective.end(); subCplex.solve();
double result=subCplex.getObjValue();
if(result<1)
{
int size=0; IloNumArray z_lp(subEnv); subCplex.getValues(z_lp,z); IloExpr myCover(getEnv());
for (
int i=0;i<n_nodes;i++)
{
if(z_lp[i]>0.9)
{ size++; myCover+=y[i];
}
} add(myCover<=size-1); myCover.end();
} subEnv.end();
}
catch(IloException& e)
{ cerr<<
"Concert exception2!"<<endl; cerr<<e<<endl;
}
catch(...)
{ cerr<<
"Unknown exception2!"<<endl;
}
}
Moreover, I have another small question in this direction: I want to repeatedly resolve my original problem with different objective functions and each time, I want to have another value for parameter U of my callback. So after solving the model, I need to remove the current callback, and add it again with different value for U, how can I do this? Also, does CPLEX keep the cuts generated with my callback for resolving with a different objective? (actually I do not want this do happen, so if yes, is there a way to remove these cuts before resolving?)
#CPLEXOptimizers#DecisionOptimization