I am trying to solve an iterative optimization problem in cplex opl using main function. The optimization objective and constraints are written in subvaluenew.mod.
float maxOfx = ...;
dvar float x;
int z=...;
maximize x+z;
subject to {
x<=maxOfx;
}
execute
{
writeln("x= ",x);
}
and the main script is written in examplenew.mod file.
main {
var source = new IloOplModelSource("subvaluenew.mod");
var cplex = new IloCplex();
var def = new IloOplModelDefinition(source);
for(var k=1;k<=10;k++)
{
var opl = new IloOplModel(def,cplex);
var data = new IloOplDataSource("examplenew.dat");
var data2= new IloOplDataElements();
data2.maxOfx=k;
opl.addDataSource(data2);
opl.generate();
if (cplex.solve()) {
opl.postProcess();
writeln("OBJ = " + cplex.getObjValue());
} else {
writeln("No solution");
}
opl.end();
}
}
One of the parameter that is used in objective function is read from the excel file in examplenew.dat file.
SheetConnection Data("C:\\Users\\subha\\Downloads\\rk.xlsx");
z from SheetRead (Data, "sheet3!F18:F18");
I am getting error in this code. If I have to use the .dat file to load the parameter data, how can I eliminate this error. The error showing is : data element z is not defined. However, I am defining the parameter z in subvaluenew.mod file. Please help me in solving this error.
In the main model
opl.addDataSource(data);
Is missing