Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Calling a model built in one function to another

    Posted 06/24/21 01:39 PM
    Hello everyone 
    I need a small help. I am C++ user and trying  to solve my MIP model by calling Cplex. I built an model called "modelu" in a function like this.

    double modelu (....)
    {
     IloEnv env;
    IloModel mdl(env);
    IloCplex cub(env);
    IloRangeArray  constr1(env);
    IloRangeArray  constr2(env);
    IloRangeArray  constr3(env);
    IloRangeArray  constr4(env);
    //decsion variables//
    //
    //add the constraints and objective function//.
    }
    This part is ok for me . I want to remove constr1 from the model "mdl" I created in the function above  and do some other things in another function  

    double anotherfunction(....) 
    {
    mdl.remove(constr1);
    //do the other tasks//
    }
    int main()
    {
    double anotherfunction(....) 
    }

    I do not know how can I call "mdl" model and the constraint that will be removed  to the anotherfunction(), what should I write exactly? and how should I define them in the main block before anotherfunction(). 
    I checked the files but  could not find the answer I looked for , thank you in advance

    ------------------------------
    milena kafka
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Calling a model built in one function to another

    Posted 06/24/21 04:24 PM
    There are a number of ways to do this. I would probably create a class to hold the model. All the stuff declared at the top of your modelu() function would be class variables (fields). The class constructor would build the initial model. The function anotherfunction() would be a class method, and would have direct access to the model, constraints etc. by referring to the appropriate class fields.

    If for some reason you do not want to do that, you can pass the "mdl" model and the constraint(s) to remove as arguments to anotherfunction().

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------