Initializing a variable

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 :slight_smile:

Thank you very much

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

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
And here is the entire code.
TFE.gms (5.07 KB)

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

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

INITSTOCKD(D) .. sum(T$(Ord(T) = 1), SD(D,T))  SID(D);

You can also use “sameas”:

INITSTOCKD(D) .. sum(T$(sameas(T, "PRINTEMPS"), SD(D,T))  SID(D);

But this is all more cumbersome.

Cheers
Renger

Thank you very much! This helped :slight_smile: