"How can I add a row of tuple data (Links) in each iteration within a loop in the main block in OPL CPLEX?" In this code, I want to add one row from the tuple Links to the model in each iteration, and I want the value of the variable x to remain constant for the next iteration. However, I'm having trouble adding a row from Links to the model in each iteration! The number of rows in the tuple "Links" is equal to 7. I appreciate your help. Thank you.
{int}s={};
range M = 1..5;
tuple link {
key int N;
int fromnode;
int tonode;
int EP;
int LD;
float I;
int dr;
};
{link} Links = ...;
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=1;iter<=7;iter++)
{
var opl = new IloOplModel(def,cplex);
var data= new IloOplDataElements();
data.M=thisOplModel.M;
data.Links=thisOplModel.s;
data.Links.add(iter);
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]);
}}}
}
if (cplex.solve()) {
writeln('\n=================================');
writeln("ITERATION ", iter, " / TIME = ", cplex.getCplexTime());
writeln("N=",data.N);
writeln('\n****OBJ************');
writeln("OBJ = " + cplex.getObjValue());
} else {
writeln("No solution");
}
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();
}
}```