Making subsets work for you

Top  Previous  Next

One other set definition consideration involves the use of subsets.  Sometimes it is desirable to have items that can be treated simultaneously in some places, but separately elsewhere.  For example, when entering crop budgets one might wish to enter yield along with usage of inputs, land, labor, and water, in one spot yet treat those differently elsewhere (i.e., where variable inputs might be in one equation, yield balance in another, with water and labor availability in yet a third and fourth equation).  Subsets allow this.  Consider two models

In the Egypt.gms model from the GAMS model library we have yields and input costs in two tables some 50 lines apart

 

Table yield (c,r)  yield for different commodites

             u-egypt   m-egypt    e-delta    m-delta     w-delta

*               ton      ton        ton        ton         ton

   wheat       1.29     1.36       1.39       1.404       1.36

   barley      1.41     1.26       1.33        .984        .96

 

 

Table cropdat(c,*) seed protein starch misc costs and pestic data

         protein  starch  seed   misc    pest    n-fer    p-fer

*          %       %      ton    le      le      ton      ton

wheat      .1    23.3    .075    12.0            0.054    0.015

barley     .1    23.3    .060     8.0            0.045    0.015

 

In my ASM model (asmall10.gms, asmcrop10.gms) I have

 

TABLE CCCBUDDATA(ALLI,SUBREG,CROP,WTECH,CTECH,TECH)  REGIONAL CROP BUDGET

               northeast.corn.DRYLAND.BASE.0

corn                  115.87

CROPLAND                1.00

LABOR                   4.34

nitrogen               24.69

potassium              15.17

phosporous              7.34

 

Where everything for a crop budget is together in concurrence with practices in data sources.  We use subsets (asmsets10.gms) to unravel the data

 

SET ALLI               ALL BUDGET ITEMS

      /  corn      ,    soybeans  ,

         cropland  ,   pasture   ,     labor,

         nitrogen  ,    potassium ,    phosporous,    trancost /

set PRIMARY(ALLI)      PRIMARY PRODUCTS

       /  cotton    ,    soybeans /

set INPUT(ALLI)    NATIONAL INPUTS

       /  nitrogen  ,    potassium ,  trancost  ,    phosporous/

set LANDTYPE(ALLI)         LAND TYPES

       /  cropland  ,    pasture   /

 

Use of subsets and a general set like ALLI allow one to both organize the input according to convenience with data sources and then deal with it efficiently in the model and report writer statements.  You can also avoid the * in the input data sets.