$Include

Top  Previous  Next

One may include external files using the syntax

 

$Include externalfilename

 

where the externalfilename can

Include the full path or just a file name relative to the current working directory  (which will be the IDE project file location) using no path name or syntax like ./subdir/externalfilename that goes into a subdirectory below this one or a .. like ../filename which goes above this directory.
Be quoted or unquoted.
Only contain part of name and does not need to incorporate the extension gms.  In turn if
A file with just the name given in the $Include is found in the current working directory (which will be the IDE project file location), then it will be used.
If not a file with the name externalfilename.gms will be searched for in the current working directory (which will be the IDE project file location) and if found, then it will be used.

Example:

Suppose we break a transport problem into three files (trandata.gms, tranmodl.gms, tranrept.gms) and include them into one composite file tranint.gms as follows

 

$Include trandata

$Include tranmodl

$Include tranrept

 

Note also tranrept.gms includes another file trannest.gms.  The resultant LST file looks as follows

 

INCLUDE    D:\GAMSPDF\TRANDATA.GMS

    2  SETS  PLANT    PLANT LOCATIONS  /NEWYORK  , CHICAGO , LOSANGLS /

    3        MARKET   DEMAND MARKETS   /MIAMI,   HOUSTON, MINEPLIS, PORTLAND/

    4  PARAMETERS   SUPPLY(PLANT)  QUANTITY AVAILABLE AT EACH PLANT

    5                  /NEWYORK   100, CHICAGO   275, LOSANGLS   90/

    6               DEMAND(MARKET)   QUANTITY REQUIRED BY DEMAND MARKET

    7                  /MIAMI 100,HOUSTON 90,MINEPLIS 120,PORTLAND 90/;

    8   TABLE   DISTANCE(PLANT,MARKET)   DISTANCE FROM EACH PLANT TO EACH MARKET

    9                       MIAMI   HOUSTON   MINEPLIS   PORTLAND

   10           NEWYORK      1300     1800       1100       3600

   11           CHICAGO      2200     1300        700       2900

   12           LOSANGLS     3700     2400       2500       1100      ;

INCLUDE    D:\GAMSPDF\TRANMODL.GMS

   14  PARAMETER COST(PLANT,MARKET)    CALCULATED COST OF MOVING GOODS;

   15             COST(PLANT,MARKET) = 50 + 1 * DISTANCE(PLANT,MARKET);

   16   POSITIVE VARIABLES

   17           SHIPMENTS(PLANT,MARKET) AMOUNT SHIPPED OVER A TRANSPORT ROUTE;

   18   VARIABLES TCOST                 TOTAL COST OF SHIPPING OVER ALL ROUTES;

   19   EQUATIONS TCOSTEQ               TOTAL COST ACCOUNTING EQUATION

   20             SUPPLYEQ(PLANT)       LIMIT ON SUPPLY AVAILABLE AT A PLANT

   21             DEMANDEQ(MARKET)      MINIMUM REQUIREMENT AT A DEMAND MARKET;

   22   TCOSTEQ.. TCOST =E=SUM((PLANT,MARKET), SHIPMENTS(PLANT,MARKET)*

   23                                                 COST(PLANT,MARKET));

   24   SUPPLYEQ(PLANT).. SUM(MARKET,SHIPMENTS(PLANT,MARKET))=L=SUPPLY(PLANT);

   25   DEMANDEQ(MARKET)..SUM(PLANT,SHIPMENTS(PLANT,MARKET))=G=DEMAND(MARKET);

   26   MODEL TRANSPORT /ALL/;

   27   SOLVE TRANSPORT USING LP MINIMIZING TCOST;

INCLUDE    D:\GAMSPDF\TRANREPT.GMS

   29  PARAMETER MOVEMENT(*,*)  COMMODITY MOVEMENT;

   30  MOVEMENT(PLANT,MARKET)=SHIPMENTS.L(PLANT,MARKET);

   31  MOVEMENT("TOTAL",MARKET)=SUM(PLANT,SHIPMENTS.L(PLANT,MARKET));

   32  MOVEMENT(PLANT,"TOTAL")=SUM(MARKET,SHIPMENTS.L(PLANT,MARKET));

   33  MOVEMENT("TOTAL","TOTAL")=SUM(MARKET,MOVEMENT("TOTAL",MARKET));

   34  OPTION DECIMALS=0;

   35  DISPLAY MOVEMENT;

   36  PARAMETER COSTS(*,*)  COMMODITY MOVEMENT COSTS BY ROUTE;

   37  COSTS(PLANT,MARKET)=COST(PLANT,MARKET)*SHIPMENTS.L(PLANT,MARKET);

   38  COSTS("TOTAL",MARKET)

   39      =SUM(PLANT,COST(PLANT,MARKET)*SHIPMENTS.L(PLANT,MARKET));

   40  COSTS(PLANT,"TOTAL")

   41      =SUM(MARKET,COST(PLANT,MARKET)*SHIPMENTS.L(PLANT,MARKET));

   42  COSTS("TOTAL","TOTAL")=TCOST.L;

   43  OPTION DECIMALS=0;

   44  DISPLAY COSTS;

   45  PARAMETER SUPPLYREP(PLANT,*)  SUPPLY REPORT;

   46  SUPPLYREP(PLANT,"AVAILABLE")=SUPPLY(PLANT);

   47  SUPPLYREP(PLANT,"USED")=MOVEMENT(PLANT,"TOTAL");

   48  SUPPLYREP(PLANT,"MARGVALUE")=ABS(SUPPLYEQ.M(PLANT));

   49  OPTION DECIMALS=2;

   50  DISPLAY SUPPLYREP;

   51  PARAMETER DEMANDREP(MARKET,*)  DEMAND REPORT;

   52  DEMANDREP(MARKET,"REQUIRED")=DEMAND(MARKET);

   53  DEMANDREP(MARKET,"RECIEVED")=MOVEMENT("TOTAL",MARKET);

   54  DEMANDREP(MARKET,"MARGCOST")=ABS(DEMANDEQ.M(MARKET));

   55  OPTION DECIMALS=2;

   56  DISPLAY DEMANDREP;

   57  PARAMETER CMOVEMENT(*,*) COSTS OF CHANGING COMMODITY MOVEMENT PATTERN;

   58  CMOVEMENT(PLANT,MARKET)=SHIPMENTS.M(PLANT,MARKET);

   59  OPTION DECIMALS=2;

   60  DISPLAY CMOVEMENT;

INCLUDE    D:\GAMSPDF\TRANNEST.GMS

   61 *this is a nested include

 

and runs just as if it were one continuously typed file.

Notes:

In the LST file the incidence of the include file is marked in two ways.
Wherever an include file starts the echo print contains a line that indicates the file name and location.  In the echo print of the above example 4 such lines appear as shown just below.  Note as illustrated in the LST file above these are separated by a echo print of the content of the included files and are just grouped together here for convenience of exposition.

INCLUDE    C:\GAMS\ADVCLASS\CLASS\EXAMPLE\LINK\TRANDATA.GMS

INCLUDE    C:\GAMS\ADVCLASS\CLASS\EXAMPLE\LINK\TRANMODL.GMS

INCLUDE    C:\GAMS\ADVCLASS\CLASS\EXAMPLE\LINK\TRANREPT.GMS

INCLUDE    D:\GAMSPDF\TRANNEST.GMS

 

At the end of the file one gets an indication of what was inserted and where

SEQ        GLOBAL TYPE                PARENT                LOCAL        FILENAME

 

1        1        INPUT                        0                0        C:\GAMSPDF\TRANINT.GMS

2        6        INCLUDE                1                6        .C:\GAMSPDF\TRANDATA.GMS

3        25        INCLUDE                1                7        .C:\GAMSPDF\TRANMODL.GMS

4        44        INCLUDE                1                8        .C:\GAMSPDF\TRANREPT.GMS

5        77        INCLUDE                4                33        ..C:\GAMSPDF\TRANNEST.GMS

 

There are several columns to this display

The SEQ column gives a number to the include files encountered always including the base GMS file which is listed as INPUT (tranint.gms).
The GLOBAL column gives the line number within the composite LST file (which is expanded for the presence of the included files as above) where the $Include statement occurs.
The TYPE column indicates the type of include present.  The various types can be INPUT, INCLUDE, BATINCLUDE, LIBINCLUDE, and SYSINCLUDE.  INPUT is used to label the base file (tranint.gms).  The other modifiers in front of the word include will be discussed below.
The PARENT column provides the number of the file from the SEQ column into which this file was included (note in the above example most were included in file number 1 the base Input but that trannest.gms was included in file number 4 which is tranrept.gms).
The LOCAL column gives the local line number in the parent file where the $Include appeared (showing the first three were included in lines 6, 7 and 8 of the INPUT file tranint.gms and that trannest.gms is included into line 33 of tranrept.gms.
The FILENAME column gives the path and name for the included file.