Hi,
Consider a model where a set is defined as follows:
set s /s1*s100/;
All the parameters and variables including objective function are defined in “s”. For instance, OF(s), X(s), etc.
My problem is simple, but I cannot find a way to solve it.
I want to solve the problem for each “s” i.e., 100 times. However, as we know, GAMS can only solve problems in which the objective function has no domain.
How can I solve this problem?
Any help or useful suggestion is highly appreciated.
Thanks.
Hi,
You need to do two things:
-
Work with a dynamic set sx(s) that contains only the elements of s you want in your single solve (it seems that in your case you just want one element).
-
Make an extra objective variable with in an extra constraint.
The code could look like this:
set s /s1*s100/, sx(s);
variable obj(s), objx;
equation defobj(s); defobj(sx).. obj(sx) =e= OF(sx) + X(sx);
equation defobjx; defobjx.. objx =e= sum(sx, obj(sx));
...
model m /all/;
loop(s,
option clear=sx; sx(s) = yes;
solve m using lp min objx;
);
-Michael
Dear Michael,
I really appreciate your very useful suggestion.
That was a great idea and my code is properly working.
Thanks a lot.