I have an optimization model that I want to implement in IBM CPLEX Optimization Studio 12.10. I wrote the model code in OPL and the first implementation is working. What I would like to do now is to iterate the model multiple times to see how the resolution time changes depending on the dimension of the parameters.
In the .mod file I have defined three sets:
- int numSet1=...;
- int numSet2=...;
- int numSet3=...;
- range Set1 = 1..numSet1;
- range Set2 = 1..numSet2;
- range Set3 = 1..numSet3;
And four parameters:
- float Par1[Set1]=...;
- float Par2[Set1][Set2]=...;
- float Par3[Set1]=...;
- float Par4[Set1][Set2][Set3]=...;
In the .dat file, I have defined the initial values for these sets and parameters.
What I would like to do now is to define, in the flow control, a code that allows me to change the dimensions fo the sets, and thus, of the parameters, and save the resolution time for each resolution:
main {
var mod = thisOplModel.modelDefinition;
var dat = thisOplModel.dataElements;
for (var sizenumSet1 = 2; sizenumSet1 <= 10; sizenumSet1 += 2) {
for (var sizenumSet2 = 1; sizenumSet2 <= 5; sizenumSet2 +=1) {
for (var sizenumSet3 = 1; sizenumSet3 <=5; sizenumSet3 +=1) {
var MyCplex = new IloCplex();
var opl = new IloOplModel(mod, MyCplex);
dat.changenumSet1=sizenumSet1;
dat.changenumSet2=sizenumSet2;
dat.changenumSet3=sizenumSet3;
opl.addDataSource(dat);
opl.generate();
if (MyCplex.solve()) {
writeln("Solution: ", MyCplex.getObjValue(),
" / sizeSet1: ", sizenumSet1,
" / sizeSet2: ", sizenumSet2,
" / sizeSet3: ", sizenumSet3,
" / time: ", MyCplex.getCplexTime());
}
opl.end();
MyCplex.end();
}
}
}
}
When I launch this code what I obtain is the following list of errors:
- Execution of main failed. Processing OPL model failed
- Index out of bound for array Par4(1)(1):3
- Scripting runtime error: (in generate) Processing OPL model failed
How can I solve this? Thank you for your help.