Hello ,
I am new to gams and I am trying to define a dynamic set in a “for statement”. In fact, I want to solve my model using a different set each time and I am using the embedded code facility for python to define in each iteration my new dynamic set.
In my model I have declared my parameters and equations using the main set and then the definition using the subset.
Below is my code and this is the error I am getting, I don’t know what I am missing and if this is the right way to do it
Error:
Assignment to set used in ‘ord’ or lag
this statement changes the content of a set previously used with ‘ord’ or lag/lead
Code:
Sets i products / i0*i50 /
j suppliers / j0*j50 /
t time periods / t0*t50 /
sub_j(j) dynamic subset for j
sub_t(t) dynamic subset for t
sub_i(i) dynamic subset for i ;
for ( product = 1 to 5 by 2,
for( supplier = 1 to 5 by 2,
for ( time = 1 to 5 by 2,
embeddedCode Python:
product = list(gams.get("product"))
supplier = list(gams.get("supplier"))
time = list(gams.get("time"))
sub_i = list(gams.get("sub_i"))
sub_j = list(gams.get("sub_j"))
sub_t = list(gams.get("sub_t"))
"gams.set("sub_i",["i" + str(x) for x in list(range(0, int(product)))])"
"gams.set("sub_j",["j" + str(x) for x in list(range(0, int(supplier)))])"
"gams.set("sub_t",["t" + str(x) for x in list(range(0, int(time)))])"
endEmbeddedCode sub_i sub_j sub_t
Solve model minimizing cost using mip ;
);
);
);
Any help would be appreciated
Thanks !