Originally posted by: optimiz
Hi again,
Thanks for the above help Mr. DanielJunglas. I am new to this forum, so sorry about my confusion. My original question is:
I am working on an optimization model which is an MIP. I am changing one of the variables "y" that is a binary variable and solve the model again. I keep doing this for a predetermined number of iterations. The sample code is:
int main()
{
//randomly generate y arrays. for example, y can be y={1,1,1,1,1,1,0,0,0}. This will be updated throughout the iterations.
for(int j=0; j<100; j++)
{
problem(y);
}
}
int problem(int y[])
{
IloEnv env;
try{
IloModel model(env);
// definition of variables and constraints here. One of the constraints is below:
IloRangeArray C1(env, 20, 0, 0);
//Objective:
IloObjective objective;
IloObjective objective = IloMinimize(env);
model.add(objective);
for(IloInt i = 0; i < 20; i ++){
objective.setLinearCoef(f[i], p[i]*y[i]);
}
for(IloInt i = 0; i < 20; i++){
C1[i].setLinearCoef(x[i],1);
C1[i].setLinearCoef(y[i],-1);
model.add(C1[i]);
}
C1.end();
IloCplex cplex(model);
cplex.setOut(env.getNullStream());
cplex.solve();
return cplex.getObjValue();
env.end();
}
catch (IloException& ex) {
cerr << "Error: " << ex << endl;
}
catch (...) {
cerr << "Error" << endl;
}
}
There exists a huge memory leak with this implementation. How would I be able to eliminate this leak? I have tried removing the constraints but it did not seem to help. I appreciate any suggestions. Thanks
#CPLEXOptimizers#DecisionOptimization