Originally posted by: SystemAdmin
Hello, I am trying to code Benders reformulation on CPLEX with C++ for my PhD research study and have an issue to understand cplex.clearModel(). What I am trying to do is to solve the dual sub problem over and over again until certain condition is reached (until the obj value of dual is close enough to obj value of dual problem). Since each time the dual formulation is created from scratch, I need to find a way to clear the dual model and create it again to generate cuts for my restricted master problem. So, I am testing the below code to understand how cplex.clearModel() works. But the issue is that I can't get the correct obj value of the second dual and have concert exception as highlighed in below code. Here is the code. If anybody can help me on this, I will appreciate.
#include <ilcplex/ilocplex.h>
#include <time.h>
ILOSTLBEGIN
int
main (void) {
int time = clock();
IloEnv env;
try
{
//Variables
IloNumVar x(env,0,IloInfinity,ILOINT);
IloNumVar y(env,0,IloInfinity,ILOINT);
cout<<"===== Variables are Defined"<<endl;
IloModel model(env);
// objective function
IloExpr cost(env);
cost = x+y;
model.add(IloMinimize(env, cost));
cout<<"===== Objective Function is Defined"<<endl;
// Constraints
model.add(x + 2*y >= 5);
model.add(2*x + 3*y <= 10);
cout<<"===== Constraints are Defined"<<endl;
IloCplex cplex(model);
cplex.solve();
cout<<"------------------------------------------------------------------------------"<<endl;
env.out() << endl;
env.out() << "Solution Status1 = " << cplex.getStatus() << endl << endl;
env.out() << "Solution Value1 = " << cplex.getObjValue() << endl << endl; //
I have the correct obj value (3) here when it is written. cplex.clearModel();
model.add(IloMinimize(env, cost));
model.add(x + y <= 2);
model.add(x + y >= 1);
cplex.solve();
cout<<"------------------------------------------------------------------------------"<<endl;
env.out() << endl;
env.out() << "Solution Status2 = " << cplex.getStatus() << endl << endl;
env.out() << "Solution Value2 = " << cplex.getObjValue() << endl << endl; //*But this one is incoirrect when it is written*
env.out() << cplex.getValue(x) << endl; //
Here the concert excpetion is caught as it was stated that IloExtractable 0 has not been extracted by Algorithm env.out() << cplex.getValue(y) << endl;
cplex.end();
model.end();
}
catch (IloException& e)
{
cerr << "Concert exception caught: " << e << endl;
}
catch (...)
{
cerr << "Unknown exception caught" << endl;
}
env.end();
return 0;
}
#CPLEXOptimizers#DecisionOptimization