Help me understand this line of code

Problems with syntax of GAMS
Post Reply
iwanttolearngams
User
User
Posts: 2
Joined: 3 years ago

Help me understand this line of code

Post by iwanttolearngams »

Code: Select all

t(cn)$SUM((n,rgn), dat_n(n,cn,rgn,'Node','P')) = cn(cn); /* suppliers */

t_acc_np(t,n)$SUM((rgn), dat_n(n,t,rgn,'Node','P')) = 1;
As i as I understand it is a conditional statement that would be read as :

t(cn) should be equal to cn(cn) IF the SUM for all n and rgn, and im lost after that. Thanks in advance!!

For reference this is part of a gas market model at https://www.ntnu.edu/iot/energy/energy-models-hub/ggm.

*this exact line of code is under the file "data>>in_market.gms"

Download link :

https://www.ntnu.edu/documents/140173/1 ... 5bd3738162
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Help me understand this line of code

Post by bussieck »

You should study the following chapter: https://www.gams.com/33/docs/UG_CondExpr.html. Your two examples are described in the section "Dollar on the left" (https://www.gams.com/33/docs/UG_CondExp ... rOnTheLeft). If the comparison operator is left out then you can add "<>0".

-Michael
User avatar
dirkse
Moderator
Moderator
Posts: 214
Joined: 7 years ago
Location: Fairfax, VA

Re: Help me understand this line of code

Post by dirkse »

Hello iwanttolearngams,

Your question of how to read a line of GAMS code is a good one. Unfortunately, you included two lines of GAMS code - that creates ambiguity. I assume you ask only about the first line. You describe this as "should be equal to". This is quite vague. I would say it like this:

Code: Select all

t(cn)$[booleanExpr(cn)] = p(cn);
means "for all elements of cn such that booleanExpr(cn) is true, assign the value p(cn) to t(cn)". This implies that no assignment is made where booleanExpr(cn) is false. Also, this is an assignment that happens once, when this line of code is executed. Later you could change t and/or p and they would no longer be equal. Don't confuse an assignment with an equation specifying an equality.

In your code, your boolean expression involved a sum over the sets n and rgn. It's typical to see this kind of thing, but don't let that obscure the fact that this is an assignment over (a subset of) the elements of the set cn.

Also, your code used the value cn(cn) on the RHS. This is a little strange, and probably adds confusion with no benefit. Does it even compile? If it does, cn(cn) should evaluate to 1 if a numerical value is needed, so I would just write 1 there. I didn't any of this, but that's what I would expect.

HTH,

-Steve
Post Reply