Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Multiple models with different variable bounds

    Posted 12/10/14 11:43 PM

    Originally posted by: an_drade


    Dear friends,

     

    I have a question that sounds a little silly but, in fact, I could not find the proper answer (I am using the C++ interface, Cplex 12.6.0/1).

     

    I would like to make copies/clones from a given model and, for each one, set bounds for different variables for each one and then, solve them. The trivial way to do that is to load my model (MPS file) multiple times, creating multiple copies of the variables. In this way, when setting the bounds for a variable, the bounds will be enforced in the model that that variable belongs.

     

    Is there a way to not create the multiple copies of the variables? For example, for a given model, I may query for a variable of index i, set its bounds for that model specifically, without afftecing the other models.

     

    Thanks in advance.

    My best,

    Carlos


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Multiple models with different variable bounds

    Posted 12/12/14 03:52 AM

    You will have to create copies of the variables if you want to have the variables to have different bounds in different models.

    Are you solving the different models in parallel or sequentially? If you only solve them sequentially then you could just modify the bounds, solve the model, restore the original bound for each of the models.

    Something else that may work (but I have not tried that) is the following:

    1. Read you MPS file into an IloModel instance:
      IloModel mps_model(env);
      cplex.importModel(mps_model, "model.mps", ...);
    2. Create an additional IloModel instance to describe the sub-model with different bounds:
      IloModel sub_model(env);
      sub_model.add(mps_model);
    3. Add the bound changes as constraints to sub_model:
      sub_model.add(x <= ub)

    With this, sub_model should be the original model plus the bound changes. This of course only works if the new bounds are tighter than the original ones.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Multiple models with different variable bounds

    Posted 12/12/14 08:31 AM

    Originally posted by: an_drade


    Hi Daniel,

    Thanks for your answer. In fact, I'm trying to solve these models in parallel. I did something in the same way you suggested but I couldn't fix the variables independently in each model. I created copies of these variables using the same environment and didn't work (I used IloGetClone to perform that).

    To make this work, I must create a environment (IloEnv) for each thread and load the model again. I'm to much comfortable with that due to reasons: 1) time to load the same models and create the same structures multiple times (ok, it is not so bad); 2) Can CPLEX load and process the same model in two different ways? I mean, create names, preprocessing things slight different among these multiple loads? This sounds a little bit dangerous to me.

    But, thank you very much.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Multiple models with different variable bounds

    Posted 01/06/15 04:21 AM

    When solving things in parallel you need one IloEnv and one IloCplex instance per thread. Anything else will cause race conditions.

    About question 2, I am not sure I understand correctly. If you load the model and solve it with the same parameter settings then results should be the same. If you do that again results should still be the same (unless, of course, you explicitly instructed CPLEX to use opportunistic mode). So I am not clear where you see any danger here.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Multiple models with different variable bounds

    Posted 03/06/17 04:57 PM

    Originally posted by: brownflaming1


    Hi Daniel,

    I wonder what is the best way to duplicate model in multi-threads?

    More specifically, assume I have a model IloModel mod object together with it's environment env. Now I'm going to enter a parallel for region using openMP. Each loop works on the same model with different rhs. Since you mentioned each thread needs a separate environment. What is the best way to setup the model in the loop then?

     

    I've tried a few things, IloGetClone requires the copied model to share the same environment as the original model, which doesn't seem work. I also export the model before entering the for loop and then reload the model again with a new IloEnv once in the loop, but this is not feasible neither because multiply thread accessing the same file causes problem, and multiple read and write is not very efficient.

     

    Thank you for your help!


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Multiple models with different variable bounds

    Posted 03/06/17 06:52 PM

    Originally posted by: brownflaming1


    A follow up question: If I have created an IloEnv and IloCplex object before the parallel region, will they be automatically copied for each thread once entering the loop?

     

    Thanks!


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Multiple models with different variable bounds

    Posted 03/07/17 10:35 AM

    There will be no automatic cloning of environments/models since OpenMP is not aware of CPLEX.

    I am not sure how easy it is going to be to parallelize your code with OpenMP. Since you need individual thread handling anyway, it might be easier/cleaner to do just that.

    In general, to clone the models it might indeed be best/fastest to

    1. Export the model once to a file before going parallel.

    2. In parallel, create a new environment/model for each thread and read the model from the file. Multiple threads reading the same file should not be a problem. This should also be reasonably efficient.

    Note that IloCplex::exportModel() is not the only way to export a model. This function will write the model as extracted by the engine. You can also use IloXmlContext to write/read the Concert model. This does not require an IloCplex instance.
     


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Multiple models with different variable bounds

    Posted 03/07/17 10:59 AM

    Originally posted by: brownflaming1


    Thank you Daniel! I'll give it a try.


    #CPLEXOptimizers
    #DecisionOptimization