Decision Optimization

Decision Optimization

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

 View Only
  • 1.  OPL _ Subproblem Parallel Computing

    Posted Wed February 19, 2020 11:17 AM

    Originally posted by: K__U


    Hi,

    I have an opl model that solves five consecutive connected models. One of the submodel solves many problems with a for loop and the next model combines these solutions.

    Since the parameters are known for this set of subproblems, I would like to call these models in parallel.  I couldn't use the IloOplExec since the model inputs (for the entire subproblem set) are connected to the previous model solution.

    Do you have any suggestion ?  Subproblem code is below:

     

    for (var SubSol in opl2.Sub_Sol) {
        writeln("********************** SubSet >> Multi Period Solution **************************"); 
        
        for (var SubDem in opl2.Sub_Dem){
            if(SubSol.id==SubDem.id) {opl2.Selected_Demands.add(SubDem.dem)}
        }

        for (var SubSup in opl2.Sub_Supply){
            if(SubSup.id==SubSol.id) {opl2.Selected_Supply.add(SubSup.supply);}
        }

        var src3 = new IloOplModelSource("13_Sub_Problem.mod");
        var def3 = new IloOplModelDefinition(src3);
        var cplex3 = new IloCplex();
        var opl3 = new IloOplModel(def3, cplex3);
        var data3 = new IloOplDataElements();
        data3.t=thisOplModel.t;                        
        data3.Demand_N=opl2.Selected_Demands;
        data3.Demand_L=opl2.Demand_L;
        data3.Dtemp=opl2.D;
        data3.solutionpath=solutionpath;
        data3.maxDist=opl2.maxDist;
        data3.DistanceTemp=opl2.DistanceTemp;
        data3.wType=opl2.wType;
        data3.SubSolID=SubSol.id;
        data3.Supply=opl2.Selected_Supply;
        data3.iterationno=iterationno;

        
        //SubProblem Relaxation
        data3.DC=opl2.Empty;
        if(all_locations==1){
            if(opl2.Selected_Demands.contains(SubSol.dc)){
                data3.DC=opl2.Selected_Demands;
                }else{    
                data3.DC=(opl2.Selected_Demands);
                data3.DC.add(SubSol.dc);
                };        
        }else{
            data3.DC.add(SubSol.dc);
        };    



        data3.AltNew=opl2.EmptyIntSet;
        data3.AltNew.add(1);
        data3.AltNew.add(2);
        data3.AltNew.add(3);
        data3.AltNew.add(4);
        data3.AltNew.add(5);
        data3.AltNew.add(6);
        data3.AltNew.add(7);
        data3.AltNew.add(8);
        data3.AltNew.add(9);
        data3.AltNew.add(10);
        
        opl3.addDataSource(data3);
        opl3.generate();
        cplex3.tilim = 90;
        cplex3.epgap=0.001;  // relative gap
        cplex3.mipemphasis=2;


        if (!cplex3.solve() || cplex3.getCplexStatus()==11){
            writeln("NO solution found during the initial time limit, so now we`ll change settings");    
            cplex3.tilim = 3600;
            cplex3.epgap = 0.01;  // relative gap
            cplex3.mipemphasis = 3;

        }else{
            writeln("Solution found with initial settings, now we`ll continue to postprocess");
            writeln("Status : ",cplex3.getCplexStatus());
            opl3.postProcess();    
        };
        

    // Updating the 00_tmp_sub_control data:
        for (var j1 in opl3.DC){opltmp.Control_DC.add(SubSol.id,SubSol.alt,j1)};
        for (var j2 in opl3.Demand_N){opltmp.Control_Demand.add(SubSol.id,j2)};
        cplextmp.solve();
        opltmp.postProcess();
        thisOplModel.Dem_Per.add(opl3.Dem_Per_tmp);
        thisOplModel.Columns.add(opl3.Columns);

        var dempersize=0;
        for(var k in opl3.Dem_Per_tmp){
            thisOplModel.Covering[k.dem][k.per].add(k.id);
            dempersize++;
        };

        opl3.Dem_Per_tmp.clear();
        opl3.Columns.clear();
        opl3.Columns_tmp.clear();
        opl3.Columns_cost_tmp.clear();
        opl3.Columns_cost.clear();
        opl3.DC.clear();
        opl3.AltNew.clear();
        opl3.end();
        data3.end();
        def3.end();
        src3.end();
        cplex3.end();
        opl2.Selected_Demands.clear();
        opl2.Selected_Supply.clear();

    }; //end of for loop

     

    Thanks

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: OPL _ Subproblem Parallel Computing



  • 3.  Re: OPL _ Subproblem Parallel Computing

    Posted Thu February 20, 2020 12:29 PM

    Originally posted by: K__U


    Hi Alex,

     

    I am struggling with IloOplExec. In your example data is defined in the mod file and you only add two parameters as input (n and nbthreads).

    However, I need to transfer a lot of parameters from the previous solution (like below) and then run the new model in parallel. 

    Do you have any suggestions ?

     

    data3.Demand_N=opl2.Selected_Demands;

     

    Thanks,

    Kaan


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: OPL _ Subproblem Parallel Computing

    Posted Thu February 20, 2020 02:43 PM

    Hi,

    in

    range r=1..20;
        execute
        {
        d=new Date();

        writeln(d);
        
        var f=new IloOplOutputFile("c:\\temp\\parallel.bat");
        
        for(i in r)
        {
          writeln(i);
          f.writeln("start C:\\ILOG\\CPLEX_Studio1210\\opl\\bin\\x64_win64\\oplrun.exe "+
        " -Dn="+i+" -Dnbthreads=1 c:\\temp\\scalableWarehouse.mod ");
        }   
        
        
        f.close();

        IloOplExec("c:\\temp\\parallel.bat");
        
        
        
        var d2=new Date();
        writeln("total time : ",(d2-d)/1000);
        
        }

     

    I set n but you could set whatever you need

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: OPL _ Subproblem Parallel Computing

    Posted Fri February 21, 2020 05:24 PM

    Originally posted by: K__U


    Hi Alex,

     

    Can we use a 2D or 3D array or a tuple as IloOplExec parameters ?

    (instead of a single number)

     

    Thanks,


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: OPL _ Subproblem Parallel Computing

    Posted Sat February 22, 2020 11:04 AM

    Hi,

    with oplrun -D you can use only singletons

    But you could write another file that will be used as parameters

    See https://www.ibm.com/developerworks/community/forums/html/topic?id=a90c8e32-cd8a-4bb8-bd80-4d4c3c9bb5cd&ps=25

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: OPL _ Subproblem Parallel Computing

    Posted Sun February 23, 2020 01:48 PM

    Originally posted by: K__U


    Thank you Alex ! Your comments helped me a lot. Now I can run multiple models in parallel (with different .dat files).
    However, now I have another problem. My parallel models are required to be solved in between two models.

    So I need to use parallel solution results in the next model, something like this:

    • Model A (creates input for parallel sub-models)
    • Parallel Models (5-10 run in parallel)
    • Model C (uses the output of parallel models as input parameters)

    The problem here is the Model C continues without waiting for the Parallel Models' solutions and the master problem returns an error.

    I used IloOplExec(...,true) for the last iteration of the parallel models, but this also did not solve the problem.

    Since the last iterated model can be solved earlier than the first iterated model. So is there a way to wait for all parallel model solutions to end and then proceed? 

    (Notes: I additionally created a runner.mod file to run the parallel models (as an alternative) and I am using CPLEX 12.8)

     

    Thanks,


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: OPL _ Subproblem Parallel Computing

    Posted Tue February 25, 2020 06:35 AM

    Hi,

    then what you could do is read https://www.ibm.com/developerworks/community/forums/html/topic?id=5358e11f-4501-4486-9c69-0d4d9019e12d&ps=25

    and do what you need in the exec.bat that will run all your // jobs and then you call another ilooplexec that will wait for the exec.bat

    That s for windows but you can do the same with all OS

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer