Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Strange loop behavior

    Posted 02/10/12 12:56 AM

    Originally posted by: MSaqib


    Hi everyone
    I have the following main script in a model file. I am seeing a strange behavior. The inner loop (the one that uses var i) seems to run twice for i = 1.

    
    main 
    { var rb = thisOplModel; var def = rb.modelDefinition; var data = rb.dataElements; rb.generate(); 
    
    for (var o = 6 ; o <= 24 ; o=o+6) 
    { writeln(o); writeln(); var d2 = 
    
    new IloOplDataSource(
    "w\\data" + o + 
    ".dat"); rb.addDataSource(d2); var d3 = rb.dataElements; var cycles = Opl.ceil(24*7/o);
    // d3.interval_size=o; rb.addDataSource(d3); var totalCost = 0; 
    
    for (var i= 1 ; i <= cycles+1 ; i=i+1) 
    { def = rb.modelDefinition; 
    
    if ( rb!=thisOplModel ) 
    { rb.end(); 
    } var rb1 = 
    
    new IloOplModel(def, cplex); rb1.addDataSource(d2); d2 = rb1.dataElements; 
    
    if(i > 1) 
    { 
    // set the initial_state 
    
    for (var j = 1 ; j <= rb1.availLocations ; j++) 
    { 
    
    if(rb.x[j.value][d3.interval_size]>0) d2.INIT_STATE[j] = 1; 
    
    else d2.INIT_STATE[j] = 0; 
    } 
    } d2.iter=i; rb1.addDataSource(d2); rb1.generate(); 
    
    if (cplex.solve()) 
    { 
    
    if(i>=2) 
    { totalCost = totalCost + rb1.tcxy; writeln(
    "Accumulating"); 
    } writeln(rb1.iter + 
    " " + rb1.intervalStart + 
    " " + rb1.intervalEnd); 
    } 
    } writeln(totalCost); 
    } 
    }
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Strange loop behavior

    Posted 02/10/12 12:59 AM

    Originally posted by: MSaqib


    Sorry, I hit tab while formatting the code in the posting window, which caused the message to be posted immediately. Part of the output form the script console window is:

    6
     
    1 1 6
    Accumulating
    1 1 6
    Accumulating
    2 7 12
    Accumulating
    3 13 18
    


    As you can see, i = 1 is running twice. Why would that be? This is an OPL script project in CPLEX Optimization Studio v 12.2 on MS Windows.
    #DecisionOptimization
    #OPLusingCPLEXOptimizer