I am doing an optimization problem. For that, some param have to take different values. I am using a Smolyak reduced grid. I have 9 realizations. I have constructed a code which includes in each set the values that the param has to take in each realization. Unfortunately, these param take the same values in various realizations, therefore making my code useless. I need a way to make ampl accept said sets.
I haven't found anything useful in ampl's book in the chapters dedicated to the sets https://ampl.com/BOOK/CHAPTERS/08-sets1.pdf https://ampl.com/BOOK/CHAPTERS/09-sets2.pdf
However I found this question, AMPL error, duplicate number for set, in which something similar happens. However, if I copy the code, the error remains.
This is where I define the sets, and the error occurs
param Level=9;
set slM1Set ordered := {45.4236, 45.3191, 45.5438,45.4236, 45.4236, 45.4236, 45.4236, 45.4236, 45.4236};
set slM2Set ordered := {3.8222, 3.8222, 3.8222, 3.8134, 3.8324, 3.8222, 3.8222, 3.8222, 3.8222};
set slP1Set ordered := {-37040,-37040,-37040,-37040,-37040,-47040,-27040, 37040,-37040};
set slP2Set ordered := {0, 0, 0, 0, 0, 0, 0, -577.350, 577.350};
param w_x;
param w_y;
param x1M;
param x2M;
and this is where I use them
for {a in 1..Level}
{
let w_x := member(a, slM1Set);
let w_y := member(a, slM2Set);
let x1M := member(a, slP1Set);
let x2M := member(a, slP2Set);
solve;
I need to know if I can change my code to work as intended, meaning that the loop will be executed 9 times, the first, the variable w_x will take the first value from slM1Set, w_y from slM2Set, x1M from slP1Set, x2M from slP2Set, in the second execution the variable w_x will take the second value from slM1Set, w_y from slM2Set, x1M from slP1Set, x2M from slP2Set and so on.
Unless there is some reason that you specifically need these to be sets, you're almost certainly better off handling them as indexed params.
param Level=9;
param slM1{1..Level} := ...
param slM2{1..Level} := ...
param slP1{1..Level} := ...
param slP2{1..Level} := ...
...
for {a in 1..Level}
{
let w_x := slM1[a];
let w_y := slM2[a];
let x1m := slP1[a];
let x2m := slP2[a];
solve;
}