How to define a variable on different intervals

Problems with syntax of GAMS
Post Reply
martinagherardi
User
User
Posts: 13
Joined: 2 years ago

How to define a variable on different intervals

Post by martinagherardi »

Hi,

I would like to define a variable on a set that varies based on another set:
x is my variable that depends on the generator g and on the discretization index q: x(g,q)
q takes values from 1 to n, where n is based on the generator g considered.

For example:
2 generators: set G /A,B/;
For generator A, q has to take values from 1 to 2
For generator B, q has to take values from 1 to 4.
Therefore, I want to define variables x(A,1), x(A,2), x(B,1), x(B,2), x(B,3), x(B,4).
Of course, I can define variables x(g,q) with Set Q/1*4/; and then add a constraint that constraints x(A,3) and x(A,4) to be null but in my real example I am trying to have less binaries as possible for computational reasons.

How to define this kind of variable on GAMS? I was thinking of dynamic sets but without any results.

Could you help me, please?

Best,
Martina
Fred
Posts: 373
Joined: 7 years ago

Re: How to define a variable on different intervals

Post by Fred »

Hi Martina,

It seems that what you need is a 2-dimensional dynamic set that maps values of G, q;
Please consider the following examples:

Code: Select all

set G /A,B/
    q /1*4/
    Gq(G,q) / A.(1,2), B.(1*4) /
;
display Gq;

variable x(G,q);
equation e;
e.. sum(Gq(G,q), x(G,q)) =e= ...
I hope this helps!

Fred
Post Reply