ORD on an unordered set - error P

Top  Previous  Next

When ORD is used on a set that is not ordered one receives error 198.  Ordered sets typically are ones with explicit set elements.  Unordered sets generally refer to cases where set elements are calculated or elements appear in different order across different sets.  The last case is illustrated in the following two examples errorwithord.gms

 

In the first example we define a set that uses elements that have already been defined in another set that has some of the elements in the first one but is a more extensive set

 

set a    a couple of the elements /r2,r3/;

set b    more elements /r1*r4/;

scalar count counter /0/;

loop(b$(ord(b) gt 3),count=count+1);

display count;

 

In this case if one printed out b it would be

    r2 r3 r1 r4

and GAMS will produce the error.  To fix this one could just reorder the two set definitions defining b before a.

 

 

In the second example we define a set that uses elements that have already been defined in another set but in a different order.

 

 set a1a all the elements /r1*r10/;

 set a1b  elements in different order /r3,r1/;

 loop(a1b$(ord(a1b) gt 3),count=count+1);

 display count;

 

To fix this one must always specify the elements in set 1b in the same order as in 1a.  This is required because of the Unique Element List and associated ordering employed within GAMS.