1

Thank you very much for your help Mr. Alex; I have written the following main block with your help to save the output value in the next iteration. But this is not working properly; I have put the output results below.

main {
  var source = new IloOplModelSource("subset.mod");
  var cplex = new IloCplex();
  var def = new IloOplModelDefinition(source);
  var output=0;
    for(var k=1;k<=5;k++)
    {
     var opl = new IloOplModel(def,cplex);  
     var data2= new IloOplDataElements();
   data2.M=thisOplModel.s;
   data2.M.add(k);
   data2.N=thisOplModel.N;
   data2.Links=thisOplModel.Links;
   data2.CAP=thisOplModel.CAP;
   data2.Tr=thisOplModel.Tr;
     
   opl.addDataSource(data2);
   opl.generate();
if (k!=1){ 
  for (var r in data2.Links){
    opl.x[k][r.N].LB=output;
    opl.x[k][r.N].UB=output;
  }
}
     if (cplex.solve()) {
       writeln("ITERATION ", k);
       writeln('\n****OBJ************');
       writeln("OBJ = " + cplex.getObjValue());
     } else {
        writeln("No solution");
       }
     opl.postProcess();            
     for (r in data2.Links){
       output=opl.x[k][r.N].solutionValue;
      }
    data2.end();
    opl.end();
   }  
 }

output:


======================================
M= {1}
ITERATION 1

****OBJ************
OBJ = 4.1

****x************
x[1][b] = 1
x[1][c] = 1

======================================
M= {1 2}
ITERATION 2

****OBJ************
OBJ = 4.1

****x************
x[1][b] = 1
x[1][c] = 1

======================================
M= {1 2 3}
ITERATION 3

****OBJ************
OBJ = 7.9

****x************
x[1][b] = 1
x[1][c] = 1
x[2][d] = 1
x[2][e] = 1

======================================
M= {1 2 3 4}
ITERATION 4

****OBJ************
OBJ = 9.1

****x************
x[1][f] = 1
x[1][g] = 1
x[2][b] = 1
x[2][c] = 1
x[3][e] = 1
x[3][g] = 1

======================================
M= {1 2 3 4 5}
ITERATION 5

****OBJ************
OBJ = 6.8

****x************
x[1][a] = 1
x[1][c] = 1
x[2][e] = 1
x[2][g] = 1
x[3][c] = 1
x[4][a] = 1
x[4][f] = 1
x[4][g] = 1

As you can see, in iterations 4 and 5, the previous results are not saved. And iterations 1 and 2 do not change while the M parameter is updated. How can I fix this problem? I appreciate you

yalan
  • 17
  • 4

0 Answers0