简体   繁体   中英

How to create an array of IloModel and IloObjective object pointers in c++?

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,

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

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

Then you can fill it like so:

models.push_back(new IloModel);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM