Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

Write to a spreadsheet using IBM ILOG Script for OPL

  • 1.  Write to a spreadsheet using IBM ILOG Script for OPL

    Posted 12/08/13 08:29 AM

    Originally posted by: DidacR


    Hi there,

     

    I am running a set of stochastic mixed integer programs using IBM ILOG SCRIPT.

    I need to write the results of one run to an excel file, that will be later read by a different script.

    In my *.dat file I have

    SheetConnection sheet1("EVS_Sols.xls");
     
     OpenBranch to SheetWrite(sheet1,"result");

    however, after execution, the excel file appears empty.

    I wonder if it is due to the fact that I must do the writing from inside the script, in a way similar to the way we write in a plain text file

    var ofile = new IloOplOutputFile("EVS_Sols;.txt");

    ofile.writeln(result);
     

    Many thanks in advance for any advise.

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Write to a spreadsheet using IBM ILOG Script for OPL

    Posted 12/09/13 02:49 AM

    Hi,

    do you use a main block in scripting ?

    And if yes, did you do the call to postProcess ?

    Anyway you should have a look at the example oil in the product which shows how to connect to an Excel spreadsheet

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Write to a spreadsheet using IBM ILOG Script for OPL

    Posted 12/09/13 03:42 AM

    Originally posted by: DidacR


    Hi Alex,

     

    Thank for your answer.

    Unfortunatelly, the oil example does not use a main block. Therefore, as I understand, I can not use execute blocks inside. Will appreciate if you can give me some other hint.

    Thanks,


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Write to a spreadsheet using IBM ILOG Script for OPL

    Posted 12/09/13 03:46 AM

    Hi,

    do you want to attach your projects ?

    Do you call postProcess in your main block ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Write to a spreadsheet using IBM ILOG Script for OPL

    Posted 12/09/13 04:08 AM

    Originally posted by: DidacR


    Hi Alex,

     

    I am sending a reduced version of main{} with the basic elements.

    Instead uf using the spreadsheet option. I am using a second text file as output.

    ********************************************************************

    main{
     
      thisOplModel.generate();
      var EVS = thisOplModel;
      var Locat= EVS.Locat;
     
      var ofile = new IloOplOutputFile("EVS.txt",true);
      var OpFile = new IloOplOutputFile("EVS_Locat.txt",true);

      if(cplex.solve()){

        var OpLocat = EVS.OpenLocat;
       
        OpFile.writeln(OpLocat);
        
        var Status = cplex.getCplexStatus()
        ofile.writeln("Status =", Status );
        var BestNode = cplex.getObjValue();
        var BestInt = cplex.getBestObjValue();
        if(Status == 1){
        ofile.writeln("Optimal");}
        else{
        var RelGap = (Math.abs(BestNode-BestInt))/(1e-10+Math.abs(BestNode));
        ofile.writeln("Optimallity Gap =",RelGap);
        }
        
        
        ofile.writeln(OpLocat);
        ofile.writeln(BestInt);
        ofile.writeln(BestNode);
     
    }

    ********************************************************************

     

    *******************          dat file                   ************************

    SheetConnection sheet("Locations.xls");

    OpLocat to SheetWrite(sheet,"Sheet1!A1:A400");

    ***********************************************************

    Thanks

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Write to a spreadsheet using IBM ILOG Script for OPL

    Posted 12/09/13 04:47 AM

    Hi,

     

    in order to call the SheetWrite, after

    if(cplex.solve()){

    you should do thisOplModel.postProcess()

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Write to a spreadsheet using IBM ILOG Script for OPL

    Posted 12/09/13 09:26 AM

    Originally posted by: DidacR


    Thaks Alex,

     

    Sorted!


    #DecisionOptimization
    #OPLusingCPLEXOptimizer