Showing posts with label GAMS bug. Show all posts
Showing posts with label GAMS bug. Show all posts

Monday, July 12, 2021

GAMS Singleton Set Issue

There is a nasty problem with the singleton set in GAMS. A singleton set is a set that can contain only zero or one element. Adding more elements implies replacement. I don't use it very often. Here is a reason why. 

Consider the small example:


set i /i1*i20/;
parameter p(i);
p(i) = uniform(0,10);

* find last element >= 5
scalar threshold /5/;
singleton set k(i);
loop(i,
  k(i)$(p(i)>=threshold) =
yes;
);

display p,k;


I would expect to see as output for k the last element in p(i) that is larger than 5. However, we see:


----     12 PARAMETER p  

i1  1.717,    i2  8.433,    i3  5.504,    i4  3.011,    i5  2.922,    i6  2.241,    i7  3.498,    i8  8.563
i9  0.671,    i10 5.002,    i11 9.981,    i12 5.787,    i13 9.911,    i14 7.623,    i15 1.307,    i16 6.397
i17 1.595,    i18 2.501,    i19 6.689,    i20 4.354


----     12 SET k  

                                                      ( EMPTY )


Saturday, July 11, 2009

GAMS: x**2 not allowed in QCP

> I have the the following model:

positive variable x;
free variable z;
equation obj;

obj.. z =e= x**2;
model m/all/;

solve m minimizing z using qcp;

> it is refused by GAMS.

I would consider that a bug. You can use any of the following alternative formulations:

z =e= x*x;
z =e= sqr(x);
z =e= power(x,2);

Friday, May 30, 2008

GAMS smin bug

The expression smin(s, xxx) over an empty set s may or may not return -INF. The following fragment from a real world scheduling model with a problem in its input data illustrates inconsistencies in how GAMS evaluates this.


set si /i1,i2/;
parameter duedateadj(si) /i1 10, i2 10/;
set k /k1,k2/;
parameter duration(si,k) / i1.k1 1 /;
 
parameters
   minduration(si)
   mintime(si)   "calculate in one step"
   mintime2(si)  "calculate in two steps"
;
 
mintime(si) = duedateadj(si)-smin(k$duration(si,k),duration(si,k));
 
minduration(si) =  smin(k$duration(si,k),duration(si,k));
mintime2(si) = duedateadj(si)-minduration(si);
 
display mintime, mintime2;


This should give the same result, however when we run it we see:

----     17 PARAMETER mintime  calculate in one step
 
i1 9.000,    i2  -INF
 
 
----     17 PARAMETER mintime2  calculate in two steps
 
i1  9.000,    i2 10.000


This is of course highly undesirable. In general I would try to prevent such situations by not using SMIN or SMAX over an empty set. As GAMS does not flag these occurences you will need to add explicit tests for this.

Update

This problem has been fixed in GAMS release 24,3,1 (july 2014).