Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Writing multi dimensional array results in flow control to Excel

    Posted 01/25/19 09:52 AM

    Originally posted by: Nomykan


    Hi Alex.

     i have been through to the following informative posts

    1): How to write into excel results from a flow control loop in OPL ?

     https://www.ibm.com/developerworks/community/forums/html/topic?id=b84f0aff-970f-4c26-a2aa-41614b08c560&ps=25   

    2); write multidimensional array into excel

    https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014419923

    i have no problem in both and works fine. but i am unable to write a 3 dimensional array result into excel in the flow control. how to do that in the flow control? Also what does the "A"+k+":A"+k; mean in the 

     data2.SheetWriteConnectionString="A"+k+":A"+k; 

    whether i need to change here for the 3 dimension array or how can we do that?  help in this regard will be highly appreciated.

    Thanks


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Writing multi dimensional array results in flow control to Excel

    Posted 01/25/19 10:11 AM

    Hi

    data2.SheetWriteConnectionString="A"+k+":A"+k; 

    is simply a way to write the string that will be used in SheetWrite in a dynamic way.

    So in order to write multi dimension array in flow controls you should compute the tuple sets in post process and then the SheetWrite string according to the size of the tuple set

    regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Writing multi dimensional array results in flow control to Excel

    Posted 01/25/19 10:50 AM

    Originally posted by: Nomykan


    Hi Alex,

    Thanks for your reply but still a little confused. if i have a decision variable like X[A][B][C] and i do like this in the post process in the .mod file 

    tuple Xsol { int i; int j; int k; int value; }  {Xsol} solX={<i,j,k, X[i][j][k]> | i in 1..5, j in 1..10, k in 1..3}; 

    without flow control this works fine and writes results in the excel file but i have three models. i take one result from the first model and second result from the second model and then parse it to the third model through flow control. now i want to write the result of the third model which in this case  is the X[A][B][C] into excel. so you mean i just parse the details of the solX to the sheetwrite string or how? because of the "A"+k+":A"+k; syntax its much confusing as to how i should change it to multi dimension. can you make it more clear to understand. I shall be very thankful. i have spent much time on it but still in vain. your help will make it easier for me.

    Thanks 


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Writing multi dimensional array results in flow control to Excel

    Posted 01/25/19 11:51 AM

    Ok then in your main block why not forgetting about SheetWrite and relying on https://www.ibm.com/developerworks/community/forums/html/topic?id=3fd44d41-210b-4b81-a005-819530d6377b&ps=25

    ?

     

    But if you really want to rely on SheetWrite you could use a .mod and .dat for this.

    Suppose you want to write into an excel file from a main a set of n numbers.

    Then in the main.mod you could write

    main
    {
    var source = new IloOplModelSource("sub.mod");
      var cplex = new IloCplex();
      var def = new IloOplModelDefinition(source);
      var opl = new IloOplModel(def,cplex);
      var data=new IloOplDataElements();
      data.n=10;
      var data2 = new IloOplDataSource("sub.dat");
      opl.addDataSource(data);
      opl.addDataSource(data2);
      opl.generate();
      if (cplex.solve()) {
         writeln("OBJ = " + cplex.getObjValue());
         opl.postProcess();

      } else {
         writeln("No solution");
      }

    }

    and in sub.mod

    int n=...;
    {int} s=asSet(1..n);

    string connectionString;;


    subject to
    {

    }

    execute
    {
    writeln(s);

    connectionString="A1:A"+n;
    }

    and sub.dat

     

    SheetConnection sheet("file.xlsx");
    s to SheetWrite(sheet,connectionString);

    This will generate file.xls with 10 rows from 1 to 10

     

    regards

     

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer