Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only

Optimization in main cycle, changing script of excel file

  • 1.  Optimization in main cycle, changing script of excel file

    Posted 04/05/14 08:14 PM

    Originally posted by: M_ST


    Hello.

    Im trying to run several sequential models with data to and from an excel data.

    im trying to do something like the following, but I'm still failing...

    Can you please see what am I doing wrong or if there is other way of doing this?

     

    main model

    //main model
    
    main {
      var source = new IloOplModelSource("modelo2.mod");
      var cplex = new IloCplex();
      var def = new IloOplModelDefinition(source);
      var opl = new IloOplModel(def,cplex);
       
       for(var k=1;k<=1;k++){
      
      var opl = new IloOplModel(def,cplex);
      
      var k0= k+1;
      var k1=k+2;
      var k2=k+21;
      
      var data2= new IloOplDataElements();
      data2.b=k;
      
      data2.s1="xmod2.xlsx";
    
      data2.s5="ABC!D"+k1+":D"+k2;
      data2.s6="
    ABC
    !C"+k1+":C"+k2;
      data2.s7="other!B1";
      data2.s13=  "
    ABC
    !H"+k1+":H"+k2;
      data2.s14=  "
    ABC
    !I"+k1+":I"+k2;
      data2.s16=  "
    ABC
    !G"+k1+":G"+k2;
      
      opl.addDataSource(data2);
      
      
      
      var data3=new IloOplDataSource("d1.dat");
      opl.addDataSource(data3);
      
      opl.generate();
    
    
    
    if (cplex.solve()) {
         writeln("OBJ = " + cplex.getObjValue());
    opl.postProcess();
         
      } else {
         writeln("No solution for k=",k);
      }
    
    
     }
      data2.end();
      
      opl.end();
    }
    

    data files:

    d1.dat:

    SheetConnection sheet(s1);
    
    d from SheetRead(sheet,s5);
    l from SheetRead(sheet,s6);
    c from SheetRead(sheet,s7); 
    
    
    x to SheetWrite(sheet,s13); 
    y to SheetWrite(sheet,s14); 
    w to SheetWrite(sheet,s16);
    

    b1.dat:

    b=1;
    
    s1="xmod2.xlsx";
    s5="
    ABC
    !D3:D22";
    s6="
    ABC
    !C3:C22";
    s7="other!B1";
    s13=  "
    ABC
    !H3:H22";
    s14=  "
    ABC
    !I3:I22";
    s16=  "
    ABC
    !G3:G22";
    

     

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer