Decision Optimization

Decision Optimization

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


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

problem with script-file-loop with data read from an Excel-file

  • 1.  problem with script-file-loop with data read from an Excel-file

    Posted 09/26/08 02:10 AM

    Originally posted by: SystemAdmin


    [Max said:]

    Hey,

    I´m using OPL 5.5. In my project I read data from an Excel File, which includes 200 sheets. There is one variable that changes with every new simulation. I need to start this number of simulations in order to get as many results as possible for my Lp. So I created the following loop to make ILOG work by itself:

    main {
     
       for ( var n = 1; n <=200; n++ ) {<br />        
           var cplex = new IloCplex;
           var src = new IloOplModelSource("model1.mod");
           var def = new IloOplModelDefinition(src);
           var model = new IloOplModel(def,cplex);
       
           var data = new IloOplDataSource("data.dat");
           var data1 = new IloOplDataElements();
           [b]data1.loc = "Szenario"n"!L11:O210";[/b]
           model.addDataSource(data1);
           model.addDataSource(data);
           model.generate();

           if(cplex.solve()) {
               zfwert = cplex.getObjValue();
            }
           modell.end();
           data.end();
           def.end();
           cplex.end();
           src.end();
       }

    }

    The loc-variable is initialized in the modell following:
    string loc = ...;

    The excel-part of my data-file looks like this:

    SheetConnection sheet("Test2.xlsm");
    v from SheetRead(sheet,loc);

    The variable v should change every new run. In this forum I saw a thread where someone explained how to link a string with an integer, what I did like it was explained. It seems to work fine, but as I try to run the model I get a message "Excel range is unknown". The range I wrote is surely correct, thats not the point. But I don`t know why it won't run and I ask you if anyone could take a look at my problem and maybe has a suggestion how to solve it.

    Thanks in advance!

    Max





    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: problem with script-file-loop with data read from an Excel-file

    Posted 09/26/08 07:16 AM

    Originally posted by: SystemAdmin


    [UDOPS said:]

    I am not surprised it does not work. Can 'ID string' in sheetread be a variable or data object? A couple of ideas:

    How about, you put all of the data on one sheet, read it in as one big range, and then split it up in Opl?

    Alternately, try dynamically writing the .dat file. I do this, such as:

    var selectedproblem = new IloOplOutputFile("currentproblem.dat");  //create file on disk to write
    selectedproblem.writeln("DBConnection db2(\"odbc\", \"Rail/admin/\");");
    selectedproblem.close();


    Some other thoughts: "model" is spelled wrong in your end() statement. Is cplex a reserved word? I would not use that as a variable name.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer