Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Solution output using docplexcloud

    Posted 08/29/19 07:06 PM

    Originally posted by: Filipe Costa


    Hi all,

    Before I had model that I run on docplexcloud from Decision Optimization. On dropsolve I can download the output as a json (Great!!).

    However I added to the model a Main script block and now I cannot download anymore on dropsolve the solution as a json - the status is "Failed- System Error".

    I know that I have solutions because in the log file I can visualize it.

    What I need to add in order to have the result in a json file at dropsolve?


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: Solution output using docplexcloud

    Posted 08/30/19 04:32 AM

    Hi,

    you could have a look at docplexcloud APIs : https://developer.ibm.com/docloud/documentation/docloud/

     

    Models with main work fine on docplexcloud

    I managed to dropsolve the model I shared at https://www.ibm.com/developerworks/community/forums/html/topic?id=022856ea-463e-4ded-80d3-970a5aa38882&ps=25

    regards


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: Solution output using docplexcloud

    Posted 08/30/19 09:27 AM

    Originally posted by: Filipe Costa


    Yes, But using that code no solution is directly returned.

    On the optimization studio the status of the job is "Processed (Unknown)", instead of "Processed (Feasible solution)".

    At drop solve, This is what I see IMG1.

    As you can see there is no option to download the result (Before I had the main block I was able do download the result IMG2).

    Regards


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: Solution output using docplexcloud

    Posted 08/30/19 10:13 AM

    Hi,

    with the CPLEX OPL IDE in order to get the results back from docplexcloud you could use a tuple set

    For instance if I run in the IDE

    using CP;
     
     int nbKids=300;
        float costBus40=500;
        float costBus30=400;
         
        dvar int+ nbBus40;
        dvar int+ nbBus30;
         
        minimize
         costBus40*nbBus40  +nbBus30*costBus30;
         
        subject to
        {
         ctKids:40*nbBus40+nbBus30*30>=nbKids;
        }
        
        tuple t
        {
        int b40;
        int b30;    
        }
        
        {t} res;

        execute
        {
        writeln("nbBus40 = ",nbBus40);
        writeln("nbBus30 = ",nbBus30);
        res.add(nbBus40,nbBus30);
        }

        main
        {
        thisOplModel.generate();

        cp.solve();
        thisOplModel.postProcess();

        //now 350 kids instead of 300
        writeln("now 350 kids instead of 300");
            
        thisOplModel.ctKids.LB=350;

        cp.solve();
        thisOplModel.postProcess();


        // no more than 4 buses 40 seats
        writeln("no more than 4 buses 40 seats");

        thisOplModel.nbBus40.UB=4;

        cp.solve();
        thisOplModel.postProcess();

       

       

         


        }

    then if I run in the cloud and right click to get back the results I will see

     

    regards


    #DecisionOptimization


  • 5.  Re: Solution output using docplexcloud

    Posted 08/30/19 11:31 AM

    Originally posted by: Filipe Costa


    Thanks for the answer.

    But If at the beginning  you have this declaration:

    thisOplModel.generate();
      var def  = thisOplModel.modelDefinition;
      var data = thisOplModel.dataElements;
      var data2 = thisOplModel.dataElements;
      var parm = thisOplModel.settings;

    How would you do the first step using var opl1 = new IloOplModel(def, cp); and for the second step  using :

    var cp2 = new IloCP();
    var opl2 = new IloOplModel(def, cp2)

    ?

    Regards,


    #DecisionOptimization
    #OPLusingCPOptimizer


  • 6.  Re: Solution output using docplexcloud

    Posted 08/30/19 11:44 AM

    Hi,

    if I adapt that to your model, this gives

     using CP;
     
     tuple t
     {
     float a;
     float b;
     }
     
     {t} res={};
     
     dvar int x;
     
     subject to
     {
     x==2;
     }
     
     
     
     main{
     
     var o1=0;
     var o2=0;
     
      //thisOplModel.generate();
      var source = new IloOplModelSource("sub.mod");
     
      var def = new IloOplModelDefinition(source);
      var data = new IloOplDataElements();
      var parm = thisOplModel.settings;
      var opl1 = new IloOplModel(def,cp);
      data.use_delay=1;
      data.use_bal=1;
      data.use_isi_grade=1;
     
       data.use_setup=0;
      data.use_isi_grade2=0;
      opl1.addDataSource(data);
     
      opl1.generate();
      //  STEP 1
      writeln("STEP 1: Minimizing Bal,Delay,ISI");
      cp.param.TimeLimit = 50;
      cp.param.NoOverlapInferenceLevel = "Extended";
      cp.solve();   
      writeln(opl1.printSolution());
      o1=cp.getObjValue();
     
      var cp2 = new IloCP();
      var opl2 = new IloOplModel(def, cp2);
     
     
      data.use_setup=1;
      data.use_isi_grade2=1;
      opl2.addDataSource(data);
      opl2.generate();
     
     


     

     
      //  STEP 2
      writeln("STEP 2: Minimizing regular machines usage");
      cp2.param.TimeLimit = 5400;
      cp2.param.NoOverlapInferenceLevel = "Extended";
      cp2.solve();
      o2=cp2.getObjValue();  
      writeln(opl2.printSolution());
      opl1.end();
      opl2.end();
     
      var opl=thisOplModel;
      opl.generate();
      cp.solve();
      opl.postProcess();
     
     thisOplModel.res.add(o1,o2);
    }

     

    regards


    #DecisionOptimization
    #OPLusingCPOptimizer