Originally posted by: istenc
Hi,
I generate a model with the following script:
IloEnv env;
IloModel mod1(env);
Here, there are some lines to define variables and constraints of the model
I also generate another model which is equivalent (at least I think it is) to the first model as follows:
lloModel mod2 (env);
mod2.add(mod1);
Then, I want to extract variables and constraints of the second model by using the following script.
for (IloModel::Iterator it(mod2); it.ok(); ++it) {
IloExtractable e = *it;
if (e.isVariable())
variables.add(e.asVariable());
else if (e.isObjective())
obj = e.asObjective();
else if (e.isConstraint()) {
IloRangeI *impl = dynamic_cast<IloRangeI *>(e.asConstraint().getImpl());
if (impl) //if this constraint has a range type, then add it to rng array
rng.add(IloRange(impl));
}
}
Although I can reach the variables and constraints of the first model by using the for loop above, it fails when I run it for the second model. It iterates only once and exits the loop and in that single iteration, IloExtractable e is not a variable, a constraint or an objective.
Does "mod2.add(mod1)" command not produce an equivalent model to mod1? If so, how can I produce an equivalent one?
I appreciate any help in advance.
Best,
İstenç
#CPLEXOptimizers#DecisionOptimization