Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Pointer to a model

    Posted 02/01/20 05:03 AM

    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


  • 2.  Re: Pointer to a model

    Posted 02/04/20 11:47 AM

    mod2.add(mod1) will add mod1 to mod2 as one single object. The function does not look into the added model itself. This will only happen at extraction time. That is also why the loop stops after one iteration. There is also one object.

    The models are equivalent. They are actually identical! mod2 is not a copy of mod1, it contains mod1 (and nothing else).


    #CPLEXOptimizers
    #DecisionOptimization