User Tools

Site Tools


How do I output zero values with a display statement?

GAMS uses all sparse structures and, in general, having a value of zero and not existing are the same. However GAMS has a special value that means the element in question is numerically zero but that it does exist. That value is EPS. So, if you run the following example:

Set i /i1 * i2/;
Set j /j1 * j2/;
Parameter x(i, j) /
 i1.j1 11
 i1.j2 12
Display x;
x(i, j)$(Not x(i, j)) = EPS;
Display x;

You'll see that the second row of data is written by the second display statement.

You could still use x with the EPS entries for computations but you would lose efficiency because x would be treated as dense instead of sparse (no importance for such a tiny example, of course).

If you don't like EPS, you can use an acronym instead:

Acronym zero;
x(i, j)$(Not x(i, j)) = zero;
Display x;

but then you can't do computations with the result.

If you don't like the looks of zero, you can make the acronym equal to lower case letter o instead. If you don't like that, you'll have to switch to writing reports with the Put statement.

IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/output_zero_values_with_a_display_statement.txt · Last modified: 2008/06/18 14:35 by support