Quick Question

Hi, I’m looking for ideas.

I want to write an equation/declare a variable conditionally based on if a certain parameter “has data”. I am currently doing this by checking for $(param ne 0), but I can see in the future there will be complications with true zeroes of said parameter.

Are there any easy workarounds for this ? I mean checking if a certain parameter has been defined for a certain combination of set elements

Regards and thanks in advance
Claudio


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Claudio,

I think the short answer is no. There are probably some quick and dirty ways to check if the parameter is initialized at all, but even those techniques operate on the parameter as a whole. E.g. if you have

set i / 1 * 4 /;
parameter a(i);

  • The display below will not work: a is not initialized/assigned
    display a;

and if you do

a(‘1’) = 0;

there is no way to distinguish the zero in a(1) from the zero in a(2).

One way to deal with this is to use the GAMS eps value. You can think of an eps as a stored zero. Numerically, it is zero (in GAMS, NOT some very small number) but since it is stored it is logically different from zero. So for example, you could have

parameter prodCap(i) ‘production capacities’ /
1 eps
2 4
3 0
/;

to indicate the presence of two production units (at locations 1 and 2). The capacities for locations 3 and 4 are both zero. There is no difference between them, even though one is initialized to zero and the other not. Neither zero is stored.

To use eps, it’s key to appreciate the difference between

  • this looks good to me
    myEq(i)$prodCap(i) … blah blah blah =L= prodCap(i);

  • probably not what you want
    myEq(i)$[prodCap(i) 0] … blah blah blah =L= prodCap(i);

You can read more about the rules for how GAMS handles eps (e.g. what is eps + eps? eps - eps? eps + 0?) in the Users Guide. Model crazy from GAMSLIB also is relevant.

-Steve


On Tue, Jun 17, 2014 at 3:23 PM, Claudio Delpino wrote:

Hi, I’m looking for ideas.

I want to write an equation/declare a variable conditionally based on if a certain parameter “has data”. I am currently doing this by checking for $(param ne 0), but I can see in the future there will be complications with true zeroes of said parameter.

Are there any easy workarounds for this ? I mean checking if a certain parameter has been defined for a certain combination of set elements

Regards and thanks in advance
Claudio


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.



\

Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdirkse@gams.com
http://www.gams.com

Steve: Right on the spot, as always. This accomplishes the behaivour I want.

Thank you very much !

Claudio


On Thu, Jun 19, 2014 at 12:28 PM, Steven Dirkse wrote:

Claudio,

I think the short answer is no. There are probably some quick and dirty ways to check if the parameter is initialized at all, but even those techniques operate on the parameter as a whole. E.g. if you have

set i / 1 * 4 /;
parameter a(i);

  • The display below will not work: a is not initialized/assigned
    display a;

and if you do

a(‘1’) = 0;

there is no way to distinguish the zero in a(1) from the zero in a(2).

One way to deal with this is to use the GAMS eps value. You can think of an eps as a stored zero. Numerically, it is zero (in GAMS, NOT some very small number) but since it is stored it is logically different from zero. So for example, you could have

parameter prodCap(i) ‘production capacities’ /
1 eps
2 4
3 0
/;

to indicate the presence of two production units (at locations 1 and 2). The capacities for locations 3 and 4 are both zero. There is no difference between them, even though one is initialized to zero and the other not. Neither zero is stored.

To use eps, it’s key to appreciate the difference between

  • this looks good to me
    myEq(i)$prodCap(i) … blah blah blah =L= prodCap(i);

  • probably not what you want
    myEq(i)$[prodCap(i) 0] … blah blah blah =L= prodCap(i);

You can read more about the rules for how GAMS handles eps (e.g. what is eps + eps? eps - eps? eps + 0?) in the Users Guide. Model crazy from GAMSLIB also is relevant.

-Steve


On Tue, Jun 17, 2014 at 3:23 PM, Claudio Delpino wrote:

Hi, I’m looking for ideas.

I want to write an equation/declare a variable conditionally based on if a certain parameter “has data”. I am currently doing this by checking for $(param ne 0), but I can see in the future there will be complications with true zeroes of said parameter.

Are there any easy workarounds for this ? I mean checking if a certain parameter has been defined for a certain combination of set elements

Regards and thanks in advance
Claudio


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.



\

Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdirkse@gams.com
http://www.gams.com


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

\

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.