Logical statement

Problems with syntax of GAMS
Post Reply
huseyni
User
User
Posts: 4
Joined: 1 year ago

Logical statement

Post by huseyni »

Hello,
I need a help for my GAMS code.
I have sets i and l ;
alias(i,j) and alias (l,k).
Also i have variable ;
y(i,l,j,k).

I want to declare valid_y as in the picture and use it in the following constraints.
Adsız.jpg
WhatsApp Image 2022-06-19 at 16.03.00 (1).jpeg
con2(j).. sum((i,l,k), y(i,l,j,k)) =e= 1;
con3(i).. sum((j,l,k), y(i,l,j,k)) =e= 1;
con4(i)$(ord(i)>1).. sum((l,k,sp), z(i,l,k,sp)) =e= 1;
con5(l,i)$(ord(i)>1).. sum((k,sp), z(i,l,k,sp) ) =l= sum((j,k), y(j,k,i,l) );
con6(k,i)$(ord(i)>1).. sum((l,sp), z(i,l,k,sp) ) =l= sum((j,l), y(i,k,j,l) );

How can i do that ? Could you pls help me ?
Regards.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Logical statement

Post by bussieck »

Build a model with data and try to get as far as a you can. Post the model and ask specific questions. Then there is a chance that you can get help here.

-Michael
huseyni
User
User
Posts: 4
Joined: 1 year ago

Re: Logical statement

Post by huseyni »

test1.gms
(10.88 KiB) Downloaded 125 times
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Logical statement

Post by bussieck »

Since the conditions only apply to the index, this can be handled by a subset valid_y(i,j,k,l) and you use this everywhere you use y, e.g. con2(j).. sum(valid_y(i,l,j,k), y(i,l,j,k)) =e= 1; I have trouble interpreting the condition. What does the "," between the parts of "i<>j, i=1 and l=1, j=1 and k=1" mean. Usually, a "," in conditions means "and". In order to make i=1 and l=1 true as well as j=1 and k=1 true only (1,1,1,1) is okay. But due to i<>j this element is also kicked out, so the set is empty. I guess the "," means something different in your case. Perhaps, you write down down valid_y should look like for small i,l,j,k.

-Michael
huseyni
User
User
Posts: 4
Joined: 1 year ago

Re: Logical statement

Post by huseyni »

Thanks for you reply.
It means if i=1 then l=1. By the way, i aliases j. When i=1, j can not be equal to 1.
Or if j=1 then k=1. The same here, if j =1, i can not be equal to 1.
So, here is the question.
How can i define valid_y. Should it be under the variable header ? or under the parameter header ? and what will be the equation that satisfies these logical conditions for valid_y ?

Regards, Huseyin.
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Logical statement

Post by bussieck »

To define valid_y I used the following steps:

Code: Select all

Set valid_y(i,l,j,k);
valid_y(i,l,j,k)$(ord(i)<>ord(j)) = yes;
valid_y('1',l,j,k)$(not sameas(l,'1')) = no;
valid_y(i,l,'1',k)$(not sameas(k,'1')) = no;
Since these are exogenous requirements (they are no decision to be made by the solver) you can just limit the y variables in the model to those which belong to this set. There are multiple ways to accomplish this. Recent GAMS versions have the nice feature to limit the domain of a variable in a model without touching the equation algebra (see https://www.gams.com/latest/docs/UG_Mod ... itedDomain). So you just have to adjust the model statement to

Code: Select all

model MTD /all, y(valid_y)/;
That's all. I have attached the modified entire source code again.

-Michael
test1.gms
(11.04 KiB) Downloaded 114 times
huseyni
User
User
Posts: 4
Joined: 1 year ago

Re: Logical statement

Post by huseyni »

Hi Bussieck,
Thanks for your kindly reply my problem.
It helped me much.

Regards.
Huseyin
Post Reply