Decision Optimization

Decision Optimization

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


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

Using multiple data files to automate the program

  • 1.  Using multiple data files to automate the program

    Posted 03/30/18 01:05 AM

    Originally posted by: Srihitha Reddy B


    How to execute the program file in a single "run configuration" click using multiple data files(excel sheets)? 

    Like we have to provide say, 10 input data files (10 excel sheets), then our program should connect all these 10 data files to the program itself, and when it is executed, we have to obtain 10 corresponding results.

    Which means, instead of changing data files 10 times and running them individually to obtain the corresponding 10 results, is there any way of programming in which we will automate the process by giving 10 input data files at a time and obtain 10 outputs.

     

     

    Thanks and regards,

    Srihitha.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Using multiple data files to automate the program



  • 3.  Re: Using multiple data files to automate the program

    Posted 03/30/18 12:11 PM

    Originally posted by: Srihitha Reddy B


    Hi, Alex!

    Thanks for answering my question.

    I have looked at the above link which you provided. But it was still confusing.

    I had some variables in my program, and I need to have all those variables data again in a separate file or separate columns. I couldn't understand how the same program can be run multiple times with the multiple copies of data each executing individually.

    Here, I tried using the code as follows in .dat file. Please let me know the modifications.

     

    SheetConnection my_data("Allocationalgo.xlsx");
     
     averagefdel from SheetRead(my_data,"avgfdel");
     averageactpower from SheetRead(my_data,"avgactpow");
     pcap from SheetRead(my_data,"p_cap");
     power from SheetRead(my_data,"actpow");
     currentpower from SheetRead(my_data,"serverpow");
     //power_cap from SheetRead(my_data,"actpower");
     
     pcap from SheetRead(data2,"pcap");
     averagefdel from SheetRead(data2,"fdel");
     averageactpower from SheetRead(data2,"avgactpower");
      power from SheetRead(data2,"actpower");
     currentpower from SheetRead(data2,"serverpower");

    By doing this, am getting an error saying, "Data element 'pcap' has already been set."

     

    Please help me out with this issue.

    Thanks,

    Srihitha.

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Using multiple data files to automate the program



  • 5.  Re: Using multiple data files to automate the program

    Posted 03/31/18 05:42 AM

    Originally posted by: Srihitha Reddy B


    Hi,

    In the above link, https://www.ibm.com/developerworks/community/forums/html/topic?id=471cc451-9dc2-44d8-a0e9-5f146fb14765&ps=25 , we are giving input maxOfx value once and then we are using that in the first mod file i.e sub.mod and then using the y value as x value in the next mod file, sub2.mod. But, here my scenario is different.

    I need to have multiple excel sheets for having multiple sets of data and I need a single program in ehich I had to able to automate the process of executing all the multiple data files at the same time.

    Hope you understand my problem.

     

    Thanks,

    Srihitha.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Using multiple data files to automate the program

    Posted 03/31/18 06:05 AM

    Hi,

    could you have a look at the example in

    CPLEX_Studio128\opl\examples\opl\examples_suite

    ?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Using multiple data files to automate the program

    Posted 03/31/18 08:50 AM

    Originally posted by: Srihitha Reddy B


    Hi,

    I had a glance at those examples. But I couldn't find the examples which uses multiple input files (multiple excel sheets) and then program in the main part of mod file correspondingly.

     

    Thanks,

    Srihitha

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Using multiple data files to automate the program

    Posted 03/31/18 09:12 AM

    Hi,

    let me give you a small example:

    sub.mod

    float maxOfx = ...;
        dvar float x;

        maximize x;
        subject to {
          x<=maxOfx;
        }

        execute
        {
        writeln("x= ",x);
        }

    sub.dat

     maxOfx=10;

    sub2.dat

    maxOfx=11;

    then

    {string} datFiles={"sub.dat","sub2.dat"};

    main {

    for(var datFile in thisOplModel.datFiles)
    {
      var source = new IloOplModelSource("sub.mod");
      var cplex = new IloCplex();
      var def = new IloOplModelDefinition(source);
      var opl = new IloOplModel(def,cplex);
      var data = new IloOplDataSource(datFile);
      opl.addDataSource(data);
      opl.generate();
      if (cplex.solve()) {
         writeln("OBJ = " + cplex.getObjValue());

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

      opl.end();
     
      data.end();
      def.end();
      cplex.end();
      source.end();
    }
    }

    gives

    OBJ = 10
    OBJ = 11

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: Using multiple data files to automate the program

    Posted 03/31/18 10:16 AM

    Originally posted by: Srihitha Reddy B


    Hi,

    Thank you so much for the response.

    But, I had a query about creating two .dat  files?

    So, as I want to have two excel sheet files, now after creating two .dat files, what I can do is, to use SheetConnection and establish the connection and then I can implement the same thing in the .mod file which you have shown.

    Also, where should be the main function written, in the .mod file itself or anywhere else?

     

    Thanks,

    Srihitha.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: Using multiple data files to automate the program

    Posted 03/31/18 10:31 AM

    Hi

    in sub.dat and sub2.dat you could have some SheetConnection and SheetRead

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: Using multiple data files to automate the program

    Posted 03/31/18 10:34 AM

    Originally posted by: Srihitha Reddy B


    Hi,

    How should we create another .dat file?

    While creating mod file, we can create one dat file. But how can we create multiple dat files?

     

    Thanks,

    Srihitha.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 12.  Re: Using multiple data files to automate the program

    Posted 03/31/18 10:37 AM


  • 13.  Re: Using multiple data files to automate the program

    Posted 03/31/18 11:00 AM

    Originally posted by: Srihitha Reddy B


    Hi,

    I am almost there, but getting some errors.

    Please have a look at my files.

    ERROR: 

    "Data element "averagefdel" has already been set. Algodata2.dat /Allocationalgo 12:43-44 C:\Users\SRIHITHA\opl\Allocationalgo\Algodata2.dat OPL Problem Marker"

    Try downloading .rar file. I also attached the individual files even.

    Thanks in advance,

    Srihitha.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 14.  Re: Using multiple data files to automate the program

    Posted 03/31/18 12:23 PM

    Hi

    I generally like to have a main in a separate file

    oplrun mainindia.mod works fine

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 15.  Re: Using multiple data files to automate the program

    Posted 04/02/18 12:32 AM

    Originally posted by: Srihitha Reddy B


    Hi,

    But am not able to add two .mod files to "configuration 1(default). Only one .mod file is getting added and multiple .dat files are getting added.

    Please suggest me an alternate solution.

     

    Thanks,

    Srihitha.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 16.  Re: Using multiple data files to automate the program



  • 17.  Re: Using multiple data files to automate the program

    Posted 03/30/18 12:17 PM

    Originally posted by: Srihitha Reddy B


    Hi,

    I am having the same issue as below. But, I couldn't understand the solution.

    https://www.ibm.com/developerworks/community/forums/html/topic?id=09847297-e0ed-47b0-b2a2-81a1e370a014

     

    Thanks in advance,

    Regards,

    Srihitha


    #DecisionOptimization
    #OPLusingCPLEXOptimizer