Decision Optimization

 View Only
Expand all | Collapse all

Running the same MOD file to multiple instances

  • 1.  Running the same MOD file to multiple instances

    Posted Wed December 01, 2021 04:50 PM
    Hi,

    I have a mod. file that i would like to see aplied to multiple instances. Each instance I have is in the same excel file but it a diferent sheet.
    For each instance there is information like the number of edges, and edge list, the number of nodes, etc.. So the dat. file for each sheet would't be exactly the same. For instance, for two diferent sheets the dat. files would be:

    1.
    ne from SheetRead(sheet, "'Lpr-a-02'!B10");
    np from SheetRead(sheet, "'Lpr-a-02'!B11");
    nv from SheetRead(sheet, "'Lpr-a-02'!B2");
    e from SheetRead(sheet, "'Lpr-a-02'!N3:O93");
    tolpar=0.05;
    tolbal=0.1;
    b from SheetRead(sheet, "'Lpr-a-02'!S3:U93");
    d from SheetRead(sheet, "'Lpr-a-02'!R3:R93");

    2.
    SheetConnection sheet("V4.xlsm");
    ne from SheetRead(sheet, "'Lpr-a-01'!B10");
    np from SheetRead(sheet, "'Lpr-a-01'!B11");
    nv from SheetRead(sheet, "'Lpr-a-01'!B2");
    e from SheetRead(sheet, "'Lpr-a-01'!N3:O49");
    tolpar=0.05;
    tolbal=0.1;
    b from SheetRead(sheet, "'Lpr-a-01'!S3:T49");
    d from SheetRead(sheet, "'Lpr-a-01'!R3:R49");

    I was wondering if there was a way i could do this without having to write the dat file to every single instance.

    Thank you!

    ------------------------------
    Beatriz Santos
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Running the same MOD file to multiple instances

    Posted Thu December 02, 2021 04:40 AM
    Hi,

    within Excel and optimization  you could have a look at Variable SheetRead
    where you can see ow to set Sheet parameters from flow control.

    main
    {
      var source = new IloOplModelSource("variablesheetreadstring.mod");
      var cplex = new IloCplex();
      var def = new IloOplModelDefinition(source);
      var opl = new IloOplModel(def,cplex);
      var data1=new IloOplDataElements();
      
      data1.paramread="params!A2";
      data1.parambuses="buses!A2:B3";
      data1.paramwrite="buses!E2:F3";
      
      opl.addDataSource(data1);
      
      var data2 = new IloOplDataSource("variablesheetreadstring.dat");
      opl.addDataSource(data2);
      opl.generate();
      if (cplex.solve()) {
         writeln("OBJ = " + cplex.getObjValue());
         opl.postProcess();
    
      } else {
         writeln("No solution");
      }
      
    
      opl.end();
      
      
    }​

    and in the .dat you can see

    SheetConnection s("zoo2.xlsx");
    
    
    params from SheetRead(s,paramread); 
    buses from SheetRead(s,parambuses);
    results to SheetWrite(s,paramwrite);
    






    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------