Decision Optimization

 View Only
Expand all | Collapse all

Cplex parallel optimization using IloOplExec() in a main{}

  • 1.  Cplex parallel optimization using IloOplExec() in a main{}

    Posted Sun February 19, 2023 07:53 PM

    Hi everyone,

    I recently set up a Cplex sequential model that calls data from a database, does an annual optimization and publishes in the database when it's over. So I have a main.mod that iterates over the years :

    main {

          var source = new IloOplModelSource("MyModel.mod");

          var cplex = new IloCplex();

          var def = new IloOplModelDefinition(source);

        

        

        

          for(var k=2023;k<=2024;k++)

          {

          var opl = new IloOplModel(def,cplex);

          var dataParam= new IloOplDataElements();

          dataParam.ResolutionYear=k;

          opl.addDataSource(dataParam);

          writeln("ResolutionYear : " + dataParam.ResolutionYear);

          var data = new IloOplDataSource("Parameters.dat");

          var data2 = new IloOplDataSource("LectureBD.dat");

          var data3 = new IloOplDataSource("PublicationBD.dat");

          opl.addDataSource(data);

          opl.addDataSource(data2);

          opl.addDataSource(data3);

          opl.generate();

          if (cplex.solve()) { 

             opl.postProcess();

             writeln("OBJ = " + cplex.getObjValue());

          } else {

             writeln("No solution");

          }

         opl.end();

        }  

        }

    Now, in order to reduce the computation time, I would like to run the annual optimization in parallel. I've read this thread (https://community.ibm.com/community/user/ai-datascience/discussion/how-to-call-many-models-in-parallel-thanks-to-ilooplexec) about using the command IloOplExec() but I don't manage to include it to my main.mod. I think that all the problem revolves around the fact that the parameter "ResolutionYear" is used in the "LectureBD.dat" (to read the data from the database") but I didn't manage to make solve that problem.

    Does anyone have an idea that could solve my issue ?

    Thank you for your help



    ------------------------------
    Grégoire Turzo
    ------------------------------


  • 2.  RE: Cplex parallel optimization using IloOplExec() in a main{}

    Posted Mon February 20, 2023 02:34 AM

    Hi,

    to do that // run I used to use IloOplExec but with recent versions IloOplExec waits for the process to end so I moved to writing a shell script from OPL and then execute that script from OPL.

    See https://github.com/AlexFleischerParis/howtowithopl/blob/master/parallelrun.mod in how to with OPL



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------