0

I am coding a decomposition algorithm including scenario subproblems. I need to use model pointer to create subproblem optimization models. Then, it is needed to modify the objective function coefficient of each subproblem as the algorithm proceeds. I need to use pointers to avoid creating the subproblem models every time from scratch. How should I do that? Can I use this:

 IloModel** MaxProblemPtr= new(env) IloModel*[numberOfScenarios];

 IloObjective** MaxObjPtr= new(env) IloObjective*[numberOfScenarios];

Then, is it correct to keep pointers to the implementation instances for each scenario subproblem like the followings:

IloModel MaxProblem(env);
*(MaxProblemPtr[scnenarioN])=MaxProblem.getImpl();

IloObjective MaxObj=IloAdd(MaxProblem, IloMaximize(env));
*(MaxObjPtr[scnenarioN])=MaxObj.getImpl();

Thank you much,

1 Answers1

0

Use std::vector to hold a collection of pointers. It's much easier to use and understand. e.g:

std::vector<IloModel*> models(numberOfScenarios);

Then you can fill it like so:

models.push_back(new IloModel);
Mohamad Elghawi
  • 2,071
  • 10
  • 14