GAMS is a modeling system for optimization that provides an interface with a variety of different algorithms. Models are supplied by the user to GAMS in an input file in the form of algebraic equations using a higher level language. GAMS then compiles the model and interfaces automatically with a "solver" (i.e., optimization algorithm). The compiled model as well as the solution found by the solver are then reported back to the user through an output file. The simple diagram below illustrates this process. ![]() The conventions for naming the extensions of the files are as follows:
Output file: Filename.LST
In order to provide e brief overview of the syntax for the input file
in GAMS we will present two simple example problems. For a detailed description
the user should read "GAMS-A User's Guide" by Brooke, Kendrick and Meeraus
which is provided with this case study.
Example 1 Consider the following nonlinear programming (NLP) problem that is given
in Prob1em 8.26 in the book "Engineering Optimization" by Reklaitis, Ravindran
and Ragsdell (1983):
s.t. 1-x2-1x3 > 0 x1-x3 > 0 x1-x22+x2x3-4 = 0 0 < x1 < 5 0 < x2 < 3 0 < x3 < 3 (1)
x2 = 2 x3 = 2
The GAMS input file TEST.GMS for the rearranged problem in (1) is given in the next page (click on the "TEST.GMS"). First note that the $ sign in column 1 is a control directive, the first for specifying the title, the other two for suppressing some details in the output (e.g., map of symbols). In general, you will always include these keywords (see also pp.112-113, GAMS User's Guide). The keyword VARIABLES is used to list our variables x1, x2 and x3. Note that Z, the objective function value must also be included. The keyword POSITIVE VARIABLES is used to specify the non-negativity of x1, x2, x3. The objective function values should not be included here as in general it might take positive or negative values. Finally, note that the semicolon ; must be included to specify the end of the lists. Next, the keyword EQUATIONS is for listing the names of the constraints and objective function. The names are arbitrary and here we have selected the names CON1, CON2, CON3, for the constraints, and OBJ for the objective function. The actual equations are then defined by first listing the name followed by two periods. Note that the following syntax must be used for the equality and inequality signs:
=G= for > =L= for <
- subtraction * multiplication / division ** exponent
Next in the input file we specify the upper bounds and initial values. This is done by adding a subfield to the variables. The format is a period followed by a character, and they are as follows:
.UP upper bound .L level value, meaning actual value (initial or final) .M dual prices, Lagrange or Kuhn-Tucker multipliers The keyword MODEL is used to name our model and to specify which equations should be used. In this case we name our model as TEST and specify that all equations be used. Next, the OPTION statements are used to suppress output for debugging the compilation of the equations. Pages 102-106 in the User's Guide gives a detailed explanation of this keyword. Suffice it to say that in most cases you want to use both the OPTION LIMROW = 0 and OPTION LIMCOL = 0 to avoid long output files. Finally, we invoke the optimization algorithm with the SOLVE statement. Here the format is as follows:
TEST.GMS $TITLE Test Problem
* Example from Problem 8.26 in "Engineering Optimization"
VARIABLES X1, X2, X3, Z ;
EQUATIONS CON1, CON2, CON3, OBJ ; CON1.. X2 - X3 =G= 0 ;
* Upper bounds
* Initial point
MODEL TEST / ALL / ; OPTION LIMROW = 0;
SOLVE TEST USING NLP MINIMIZING Z; The main solver types available in GAMS are as follows:
MIP, RMIP ZOOM NLP MINOS5.3 MINLP DICOPT++ GAMS bas a default for selecting each optimization algorithm. It is the first in the above list. If we wish to select another algorithm, say ZOOM instead of BDMLP when solving an LP, this is specified with the statement:
Note that the first pan of the output is identical to the input file (lines 4 to 36). Next, statistics on the problem size are reported (e.g., 4 variables: x1, x2, x3, Z; 4 equations: 3 constraints and objective). The derivative pool refers to the fact that analytical gradients for the nonlinear model have been generated by GAMS. The solve summary indicates that the optimum bas been found (local because it is an NLP) with an objective function value Z = 7.2177. Resource usage indicates the solver MINOS took 1.648 secs. A detailed explanation of the other output in this sections can be found in pp.117-119 of the User's Guide. Finally, information on the equations and variables are listed. The column labeled LEVEL gives the actual values. So for instance X1 = 2.526, X2=0.916, X3= 0, Z = 7.218. The columns LOWER and UPPER give the lower and upper bounds, while the column MARGINAL gives the dual variables or multipliers. So for insistence, the third constraint (CON3) has s multiplier of 2.637 as the equation is an active constraint. The first two constraints have zero multipliers since they are not active at the lower or upper bounds. More details on the output can be found in pp.120-121 of the User's Guide.
TEST.LST GAMS 2.25 PC AT/XT
09/16/97
4
COMPILATION TIME =
0.060 SECONDS VERID TP5-00-
MODEL STATISTICS BLOCKS OF EQUATIONS
4 SINGLE EQUATIONS
4
GENERATION TIME =
0.000 SECONDS
EXECUTION TIME
= 0.110 SECONDS
VERID TP5-00-
S O L V E S U M M A R Y MODEL TEST
OBJECTIVE Z
**** SOLVER STATUS 1 NORMAL
COMPLETION
RESOURCE USAGE, LIMIT
0.336 1000.000
M I N O S
5.3 (Nov 1990)
Ver: 225-DOS-02
B. A. Murtagh, University
of New South Wales
D E M O N S T R A T I O N
M O D E
Estimate work space needed
-- 39 Kb
EXIT -- OPTIMAL SOLUTION FOUND
LOWER LEVEL UPPER MARGINAL ---- EQU CON1
. 0.916
+INF .
LOWER LEVEL UPPER MARGINAL ---- VAR X1
. 2.526
5.000 .
**** REPORT SUMMARY :
0 NONOPT
EXECUTION TIME
= 0.050 SECONDS
VERID TP5-00-
USER: CACHE DESIGN CASE STUDIES SERIES
G911007-
**** FILE SUMMARY INPUT C:\GAMS\TEST.GMS
Example 2 Consider the problem of assigning process streams to heat exchangers as described in pp.409-410 of the book "Optimization of Chemical Process" by Edgar and Himmelblau. The optimization problem is given by:
s.t. Si xij=1 j=l,...,n Sj xij=1 i=l,...,n (4) xij=0,1 i=l,...,n & j=l,...,n The cost Cij of assigning stream i to exchanger j is as follows:
Streams 1 2 3 4 A 94 1 54 68 B 74 10 88 82 C 73 88 8 76 D 11 74 81 21 We can formulate the above problem in GAMS in the form of the model in (4) using index sets (click on the HEAT.GMS to see the input file). As shown in the output file HEAT.LST in the next page (click on the "HEAT.LST" to see the output file), the structure of this file is similar to the one of Example 1, except for the use of indices. Note that the data are given in terms of SETS and the TABLE. (see pp.43-47 and pp.53-57 in the User's Guide). The elements of a set can be names (A, B, C, D) or numbers. In the latter case we can use the * sign to denote the range (1*4, means 1, 2, 3, 4). For the TABLE there is no need to place the numbers in precise positions; they only have to be consistent, Data can also be entered using the keywords SCALAR and PARAMETERS (see p.53 and pp.51-53 of the User's Guide). Note that we can specify xij as a variable with indices, X(I,J), and similarly the two equations: ASSI(J) means for j = 1, 2, 3, 4; ASSJ(I) means for i = A, B, C, D. Also, in this case since xij is restricted to 0-1 values, we use the keyword BINARY VARIABLES. The summation is expressed in the form of SUM (index of summation, terms in sum) (see pp.17.18 of User's Guide). Last, for the input, we have used the OPTION SOLPRINT=OFF statement, so as to only print the values of the variables xij and the objective Z. This is done with the DISPLAY keyword where we list the level value of the xij (X.L - no indices are needed) and of Z (Z.L). More information on DISPLAY can be found in pages 143-148 of the user's guide. Finally, note that in the SOLVE statement we specify the solver MIP due to the fact that the xij are binary variables. The solve summary indicates that the optimum objective function is Z=97. We also note that the solution was obtained from the relaxed LP. This is nor surprising since it is well known that the assignment problem has a "unimodular" matrix and therefore the solutions for the xij are guaranteed to be 0-1 if we solve the problem as an LP (you may try this as a simple experiment). Finally, due to the use of the DISPLAY statement the requested variables are printed. Note that stream A is assigned to exchanger 4, B to 2, C to 3, and D to 1, with a minimum cost of 97.
HEAT.GMS $TITLE Test Problem
*
SETS
TABLE C(I,J) Cost of assigning stream i to exchanger j 1
2 3 4
VARIABLES X(I,J), Z;
EQUATIONS ASSI(J), ASSJ(I), OBJ; ASSI(J).. SUM( I, X(I,J) ) =E= 1;
MODEL HEAT / ALL /; OPTION LIMROW = 0;
SOLVE HEAT USING MIP MINIMIZING Z; DISPLAY X.L, Z.L ; HEAT.LST GAMS 2.25 PC AT/XT
09/16/97
4
COMPILATION TIME =
0.060 SECONDS VERID TP5-00-
MODEL STATISTICS BLOCKS OF EQUATIONS
3 SINGLE EQUATIONS
9
GENERATION TIME =
0.050 SECONDS
EXECUTION TIME
= 0.160 SECONDS
VERID TP5-00-
S O L V E S U M M A R Y MODEL HEAT
OBJECTIVE Z
**** SOLVER STATUS 1 NORMAL
COMPLETION
RESOURCE USAGE, LIMIT
0.047 1000.000
Z O O M / X M P --- PC Version 2.2 Nov 1990 Dr Roy E. Marsten and Dr Jaya Singhal,
D E M O N S T R A T I O N
M O D E
Estimate work space needed
-- 16 Kb
Iterations Time
**** REPORT SUMMARY :
0 NONOPT
---- 40 VARIABLE X.L 1 2 3 4 A
1.000
---- 40 VARIABLE Z.L
= 97.000
EXECUTION TIME
= 0.060 SECONDS
VERID TP5-00-
USER: CACHE DESIGN CASE STUDIES SERIES
G911007-
**** FILE SUMMARY INPUT C:\GAMS\HEAT.GMS
Useful Hints and Information
The two examples given in this introduction have only covered the basic elements for the GAMS language. Two other useful operators that the reader will find in several of the problems of this case study are:
|