Objective Function with Domain

Problems with modeling
Post Reply
Only_God
User
User
Posts: 11
Joined: 6 years ago

Objective Function with Domain

Post by Only_God »

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.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Objective Function with Domain

Post by bussieck »

Hi,

You need to do two things:

1) 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).

2) Make an extra objective variable with in an extra constraint.

The code could look like this:

Code: Select all

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
Only_God
User
User
Posts: 11
Joined: 6 years ago

Re: Objective Function with Domain

Post by Only_God »

Dear Michael,
I really appreciate your very useful suggestion.
That was a great idea and my code is properly working.
Thanks a lot.
bussieck wrote: 6 years ago Hi,

You need to do two things:

1) 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).

2) Make an extra objective variable with in an extra constraint.

The code could look like this:

Code: Select all

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
Post Reply