error Index out of bound for array in ilog opl cplex

27 Views Asked by At

I am writing a code in opl cplex space, but I am facing "Index out of bound for array "x(8)": 2." error. I have a loop in this code, in each step the variables of the previous step must be fixed for the next step. please help me.

{int}s={};
range M = 1..5;
tuple link {
    key int N;
    int     fromnode;
    int     tonode;
};
main{
   var source = new IloOplModelSource("subset.mod");
   var cplex = new IloCplex();
   var def = new IloOplModelDefinition(source);
   
   var output = new Array(3);
   for (var i=1; i<=5; i++) {
     output[i] = new Array(3);
     for(var j=1; j<=7; j++) {
       output[i][j] = 0.0;
     }
   }
 
       for(var iter=6;iter<=12;iter++)
       {
      cplex.tilim=300;
      
      var opl = new IloOplModel(def,cplex);
      var data= new IloOplDataElements();
      data.N=thisOplModel.s;
      data.N.add(iter);
    data.M=thisOplModel.M;
    data.Links=thisOplModel.Links;
    opl.addDataSource(data);
    opl.generate();
   if (iter!=1){
     for (var r in data.N){ 
            for (var k in data.M){
            if (output[k][r]==1){
       opl.x[k][r].LB=output[k][r];
       opl.x[k][r].UB=output[k][r];
     writeln("xds[",k,"]","[",r,"]"," = ",output[k][r]);
     }}}   
   }         
    
      opl.postProcess(); 
   for (var k in data.M){
      for (var r in data.N){
       output[k][r]=opl.x[k][r].solutionValue;
     }
   }   
  data.end();    
  opl.end();   
    }
}
0

There are 0 best solutions below