relational operators within GAMS

Problems with syntax of GAMS
Post Reply
garvisgarg
User
User
Posts: 5
Joined: 6 years ago

relational operators within GAMS

Post by garvisgarg »

Hi all,
Please tell me, can we use relational operators within loop in GAMS. Please refer following code:

loop(k,
loop(i,
loop(t,
a.l(k,i,t)=l=b(i);
);
);
);
where k,i,t are sets while a (k,i,t) is variable and b(i) is parameter.


Thanks
Garvis Garg
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: relational operators within GAMS

Post by Manassaldi »

Hi, you can't define "lower else" equations with loops

if you want to initialize the variable "a" without relationship between the sets, use the next code: a.l(k,i,t) = b(i);

For use relational operators within loop in GAMS you have to define the relationship with "$" statement, for example:

suppose the next relationships:
k greater or equal than 1
i greater or equal than k
t lower than i+1

using loop and "$":
loop(k$(ord(k) ge 1),
loop(i$(ord(i) ge ord(k),
loop(t$(ord(t) lt ord(i)+1),
a.l(k,i,t)=b(i);
);
);
);

you can use subset too:
In this example, sets k and i does not have restriction, but set t depend on k and i following the "selection" subset

loop((k,i),
loop(t$selection(t,k,i),
a.l(k,i,t)=b(i);
););

I hope this can help you
best regard
garvisgarg
User
User
Posts: 5
Joined: 6 years ago

Re: relational operators within GAMS

Post by garvisgarg »

no in my problem I am using

eq(i)..sum((k,t),a.l(k,i,t))=l=b(i);

tell me the use of relational operator within the loop is possible or not.
If not possible then please tell me any alternate way to solve this problem.

Thanks
Garvis Garg
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: relational operators within GAMS

Post by Manassaldi »

For your case you must use "$"

Suppose the next relationships:
i greater or equal than 1
k lower or equal than i
t greater or equal than k


eq(i)$(ord(i) ge 1).. sum((k,t)$(ord(k) le ord(i) and ord(t) ge ord(k)), a(k,i,t)) =l= b(i);

You do not need use the "loop" command

Best regard
Jarenka
User
User
Posts: 64
Joined: 5 years ago

Re: relational operators within GAMS

Post by Jarenka »

Dear,

I have a problem with loop statement.

set P /P01 * P08/
Jn /Jn01 * Jn10/
Jm /Jm01 * Jm10/
parameters p1(P,Jm)
p2(P,Jn);

I would like to have the following: p1(P,jm) = p2(P,jn) - the values jn from p2 to be taken to jm in p1, for each P.

I tried this:
for(P,
for (jm
(p1(P,jm) = p2(P,jn));
);
);

My problem here is to change the dimension only and to keep all the values of the parameter the same.
User avatar
gamsadmin
Site Admin
Site Admin
Posts: 16
Joined: 7 years ago

Re: relational operators within GAMS

Post by gamsadmin »

You could use a mapping

Code: Select all

set P /P01 * P08/
    Jn /Jn01 * Jn10/
    Jm /Jm01 * Jm10/
    mapN_M(Jn,Jm) /#Jn:#Jm/;

display mapN_M;

parameters p1(P,Jm)
p2(P,Jn);

p2(P,Jn) = uniform(0,10);

loop((jn,jm)$mapN_M(jn,jm),
    p1(P,jm) = p2(P,jn);
);
display p1, p2;

For information on the mapping, see [url]https://www.gams.com/latest/docs/UG_SetDefinition.html[/url].

Cheers
Renger

Jarenka
User
User
Posts: 64
Joined: 5 years ago

Re: relational operators within GAMS

Post by Jarenka »

Thank you, it works !!
OMG, you are so helpful!!
And thank you for the link!

Kind regards
Jarenka
Post Reply