Initializing a variable Topic is solved

Problems with syntax of GAMS
Post Reply
jleeuws
User
User
Posts: 3
Joined: 4 years ago

Initializing a variable

Post by jleeuws »

Hi,

I am an beginner at GAMS and this is my first code.
I am modelling a production plan and I would like to initialize several of my variables.

I have defined my equations like this:

INITSTOCKD(D) .. SD(D,0) =E= SID(D);
INITSTOCKMP(MP) .. SMP(MP,0) =E= SIMP(MP);

However, the (D,0) part gives my an error (error 145 "Set identifier or quoted element expected" and 148 "Dimension different - The symbol is referenced with more/less indices as declared")

My variables are defined as follows:
SMP(MP,T)
SD(D,T)

And my parameters are :
CSMP(MP)
/CHOCOLATE 0.1
FRUIT 0.35/
CSD(D)
/DESERT1 0.25
DESERT2 0.25/


How do I access and define the 0 position of a variable? Or GAMS doesn't work that way ?
If anyone could give me some clues or help, I would appreciate it :)

Thank you very much
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Initializing a variable

Post by Renger »

Hi
You should treat set elements as strings, even if they are numbers. This means that SMP(D,0) is not understood by Gams and should be SMP(D,"0").
If you need the value of a set element in a calculation, you can use .val (e.g. t.val) for the value of a numeric set element and ord(t) for numeric or string elements. (ord gives the position in the set).

Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
jleeuws
User
User
Posts: 3
Joined: 4 years ago

Re: Initializing a variable

Post by jleeuws »

Thank you for your answer!

Adding the "0" does not seem to fix the problem

If I use the ORD, how should I use it? I don't think value is the right one to use because my set is not numeric, it is a set of string element.
Like this ? SMP(MP,ORD(0)) ?

If it helps, this is the constraint I am trying to implement
image.png
image.png (9.23 KiB) Viewed 8977 times
And here is the entire code.
TFE.gms
(5.07 KiB) Downloaded 214 times
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Initializing a variable

Post by Renger »

Hi
I assumed T was time like this T /0*10/. But now you sent the code, it is more clear: It should be

Code: Select all

INITSTOCKD(D) .. SD(D,"PRINTEMPS") =E= SID(D);
GAMS gave you already a hint: "170 Domain violation for element". It didn't recognized "0" as a set element.
If you want to use ord in expression like that you could use

Code: Select all

INITSTOCKD(D) .. sum(T$(Ord(T) = 1), SD(D,T))  SID(D);
You can also use "sameas":

Code: Select all

INITSTOCKD(D) .. sum(T$(sameas(T, "PRINTEMPS"), SD(D,T))  SID(D);
But this is all more cumbersome.

Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
jleeuws
User
User
Posts: 3
Joined: 4 years ago

Re: Initializing a variable

Post by jleeuws »

Thank you very much! This helped :)
Post Reply