Set declaration

Top  Previous  Next

In order to use any set one must first declare it.  In its most complete form the set declaration contains

 

set name        (rules for item names)
list of elements contained surrounded by /'s(rules for set element names)
optional explanatory text for the whole set        (rules for entries)
optional explanatory text for individual elements(rules for entries)

 

The general format for the set declaration and element definition statement is:

 

SET setname optional explanatory text

 /         first set element name                 Optional explanatory text

          second set element name                Optional explanatory text

               …

 /;

or

SETs setname optional explanatory text

/         first set element name                 Optional explanatory text

          second set element name                Optional explanatory text

               …

 /;

Examples:

(sets.gms)

SETs     j                                    /x1,x2,x3
         i                                    /r1 ,r2/; 

SET      PROCESS     PRODUCTION PROCESSES            /X1,X2,X3/; 

SET      commodities Crop commodities         / corn   in bushels

                                                Wheat  in metric tons

                                                milk   in pounds

                                                cost   "cost/unit"

                                                "long-complex-*&$name"

                                                'element name'/ ;

Set      jj(j)       set to b e computed later without entries ;

$onmulti

set      i           additional entries for i         /i1,i2/;

set      composite(i,j) mullltidimentsional     /r1.set.j/;

set              kk             kk has all of i and j in it /set.i,set.j/;

Notes:

The word set or sets can be used.
Set names must obey the item naming presented in the Rules for Item Names, Element names and Explanatory Text chapter.
Labels and long explanatory names should be used where possible as argued in the Writing Models and Good Modeling Practices chapter.
Multiple sets can be stacked with the set or sets keyword only used once (see example with i and j below).  When multiple sets are defined in one set statement a ; is entered after all set definitions.
Set elements are separated by spaces or commas.
Element definitions can be quoted, have blanks or special characters as discussed in the Rules for Item Names, Element names and Explanatory Text chapter.
Use of $onmulti allows multiple set statements to appear for a named set.
One can add the entire contents of a set to an element using the syntax set.setname as in definition of composite or kk above