Originally posted by: Namal
Hello,
I am using cplex to calculate solutions for a problem in which I set a pair of variables to 0 or 1. So i have two for loops that run over all the variables and set the bonds for it.
First I tried to use a single environment:
IloEnv lp;
try{
IloModel model(lp);
IloNumVarArray var(lp);
IloRangeArray con(lp);
//adding problem
model.add(con);
for(unsigned int i = 0; i<A.get_num_variables()-1;++i)
for(unsigned int j = i+1; j<A.get_num_variables();++j){
//for 00
var[i].setBounds(0,0);
var[j].setBounds(0,0);
IloCplex cplex(model);
cplex.setOut(lp.getNullStream());
cplex.setParam(IloCplex::RootAlg, IloCplex::Dual);
cplex.setParam(IloCplex::Param::MIP::Tolerances::MIPGap, 1.0);
int solution = cplex.solve();
if(!solution)...
//for 01
var[i].setBounds(0,0);
var[j].setBounds(1,1);
solution = cplex.solve();
if(!solution)...
//for 10
var[i].setBounds(1,1);
var[j].setBounds(0,0);
solution = cplex.solve();
if(!solution)...
//for 11
var[i].setBounds(1,1);
var[j].setBounds(1,1);
solution = cplex.solve();
if(!solution)...
//setting both variables back
var[i].setBounds(0,1);
var[j].setBounds(0,1);
}
}
catch (IloException &e) {
lp.error() << "Failed to optimize LP" << endl;
cerr << "Concert exception caught: " << e <<'\n';
}
catch (...) {cerr << "Unknown exception caught" <<'\n';}
lp.end();
but this takes too much memory and is far slower than when i make that double for loop around one environment where I have to load my problem again and again. Do I forget to clear up the memory or why is it so slow?
#CPLEXOptimizers#DecisionOptimization