Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  print array from OPL into Excel

    Posted 12/18/15 06:40 PM

    Originally posted by: Samira Fazel


    Hi,

    I wrote a code to generate data in OPL in .mod and would like to print the result in Excel file. My code doesn't have decision variables, objective function and subject to{....

    The result which I would like to print in excel is a 5 dimensional array. I wrote my array using tuple for result and then I used writeln to print this result. I can see this output in OPL and command prompt as 6 dimensional array including the value of my array which is fine. Moreover, in order to connect to Excel I wrote

    SheetConnection Sheet1("Result.xlsx");
    demand to SheetWrite(Sheet1, "demand");

    in .dat file.

    However, I have some error in .dat file saying: the file is read only...

    I was wondering if someone can help me for this question.

     

    Thanks,

    Sami


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: print array from OPL into Excel

    Posted 12/19/15 05:51 AM

    Hi,

    can you try again but close the excel file before ?

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: print array from OPL into Excel

    Posted 12/19/15 10:53 AM

    Originally posted by: Samira Fazel


    Thanks Alex,

    I closed the excel file and I also changed the name of demand to Result: Result to SheetWrite(Sheet1, "demand");

    Now it works. Thanks!

    Moreover, I have another question:

    When I am working with large size problem, OPL can not run the program. So, I use command prompt to see the result. Again, I can run and see the results in command prompt but the point is that I would like to have access to all data I am generating in excel. Just wondering if you guide me how to print the result from command prompt to excel / txt / notepad++?

    Thanks,

    Sami

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: print array from OPL into Excel

    Posted 12/19/15 12:41 PM

    Hi

    you should use IloOplOutputFile in order to have whatever you need in a text file.

    See the example in documentation:

     

    execute {
      var f = new IloOplOutputFile("output.txt");
      f.writeln("Hello World");         // lazy open
      f.close();
     
      var f2 = new IloOplOutputFile("output.txt", true);
      if (f2.exists)
         writeln("output.txt exists ==> append mode");
      else
         writeln("output.txt doesn't exist");
      f2.writeln("another line");
      f2.close();
    }

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: print array from OPL into Excel

    Posted 12/20/15 09:48 PM

    Originally posted by: Samira Fazel


    Thank you Alex,

    Actually I use the following code and I can see the results in text:

    main {
      thisOplModel.generate();
      cplex.solve(); 
      thisOplModel.postProcess()
      var ofile = new IloOplOutputFile("data-11.txt");
      ofile.writeln(thisOplModel.printExternalData());
      ofile.writeln(thisOplModel.printInternalData());
      ofile.writeln(thisOplModel.printSolution());
      ofile.close();

    However, this is possible only if I can run the code in OPL. My problem is that when I have a large size problem I can not run the program in OPL and there is a crash in OPL and no result is printed in text. As a result I use command prompt to run the code from OPL, but I would like to know is there any way that I can print the result from command prompt into excel?

    Thanks,

    Sami

      


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: print array from OPL into Excel

    Posted 12/21/15 02:19 AM

    Hi,

    can you tell more about the error you get in

    when I have a large size problem I can not run the program in OPL and there is a crash in OPL

    oplrun and the ide should work the same with regards to SheetWrite and excel. SheetWrite is the way to send data to excel.

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: print array from OPL into Excel

    Posted 12/21/15 12:18 PM

    Originally posted by: Samira Fazel


    When the size of the model increases, I get the following error:

    "Oplrun is not responding , you must relaunch the Run Configuration".

     

    Thanks,

    Sami


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: print array from OPL into Excel

    Posted 12/21/15 12:38 PM

    Hi,

    this looks like you have not enough memory. Could that be the issue ?

    Do you use a 64 bits CPLEX version ?

    You may try to use https://developer.ibm.com/docloud/try-docloud-free/

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: print array from OPL into Excel

    Posted 12/22/15 06:13 PM

    Originally posted by: Samira Fazel


    Thanks Alex. Yes, I am using 64 bits CPLEX version.

     

    Thanks,

    Sami


    #DecisionOptimization
    #OPLusingCPLEXOptimizer