Our goal is to explain the use of this computer program as a tool for solving problems of economic optimisation, and to show how it can be applied in Economic Theory, Production Planning, Management Science and other areas of Economic Studies.
The GAMS program is a very useful tool because it can solve different models, maintaining a fixed framework but varying the solver. This program is different to the other user friendly programs like Excel, QSB+, Lindo, Gino, etc, because it needs a previously prepared file of instructions (the input file) and the results appear in another file (the output file), but this is not much of an inconvenience once you have learned how to use it.
However this is not the only case where we can use GAMS. It is also possible to apply it to solve other problems such as the diet problem (Linear programming problems), problems with integer conditions over the variables (Integer programming problems), etc. Once students know the framework of this program, GAMS becomes a useful and easy way to solve problems and to analyse the results.
GAMS is a powerful computer program which allows one to solve a huge range of problems: with discontinous derivatives in nonlinear programming, relaxed mixed integer programming, etc. These are specialized problems that exceed our goal and on undergraduate courses we concentrate our efforts on using GAMS in teaching Linear, Nonlinear and Integer programming. However we can indicate to students how the program can be used to solve the more complex problems which might be encountered on higher level courses.
To use this program it is necessary to write a previous file (the input file) with extension GMS (usually for GAMS files). In this file it is necessary to introduce some special features to identify the variables, equations, model and solver. Also, it is possible to change the algorithm in order to solve several kind of problems. For more information about the program see Brooke et. al. (1992). Here we will focus on showing how to apply the GAMS program to the kind of problems that students face in their undergraduate courses.
To illustrate the use of GAMS, we will introduce four different problems, giving the input file and part of the output file, showing the solution and its meaning in the problem. The problems are taken from Chiang (1984).
Max U(x,y) = (x+2) * (y+1)To solve this problem prepare an input file as shown in Table 1.s.t. 4*x + 6*y = 130
VARIABLES X Y U; X.L=1; Y.L=1; EQUATIONS OBJ UTILITY FUNCTION RP BUDGET CONSTRAIN; OBJ.. U =E= (X+2)*(Y+1); RP.. 4*X + 6*Y =E= 130; MODEL MAXUTIL/OBJ,RP/; SOLVE MAXUTIL USING NLP MAXIMIZING U;
Table 1
In constructing the input file, it is necessary to define the variables (X, Y, U). It is not necessary to fix the starting point (1,1) because if this point is not declared GAMS will assume an initial point (0,0). However providing a better first approximation sometimes makes it makes it easier to find the solution.
The second step is to declare the equations (name and expression), in this case the functions OBJ and RP. After that we declare the model (MAXUITL) and the equations (OBJ & RP) which form the model.
Finally, it is necessary to declare the solve statement, the solver (NLP, LP, or MIP, etc) and the direction of optimization (Maximizing or minimizing).
To execute the program, once the computer program has been installed on a PC, mainframe or workstation, one types a suitable instruction. For example on a PC the instruction is:
C:\GAMS>GAMS INPUT.GMS OUTPUT OUTFILE.LST
The output file is an extensive file, but the part most important is the solution report (see Table 2).
EXIT  OPTIMAL SOLUTION FOUND LOWER LEVEL UPPER MARGINAL  EQU OBJ . . . 1.000  EQU RP 130.000 130.000 130.000 3.000 OBJ UTILITY FUNCTION RP BUDGET CONSTRAIN LOWER LEVEL UPPER MARGINAL  VAR X INF 16.000 +INF .  VAR Y INF 11.000 +INF EPS  VAR U INF 216.000 +INF .
Table 2
The optimal solution of this problem is: X = 16 (level), Y = 11 and U = 216, and the most important feature is the value of the Lagrange multiplier which is associated with the RP equation in the marginal value (3).
A very important feature is the analysis of the significance of this marginal utility, and for this reason it is helpful to build a new file with the original equations and a new equation with 131 as the value for RHS. An example of such a file is given in Table 3. The relevant output file is shown in Table 4.
VARIABLES X Y U; X.L=1; Y.L=1; EQUATIONS OBJ UTILITY FUNCTION RP BUDGET CONSTRAIN RP1 NEW RHS; OBJ.. U =E= (X+2)*(Y+1); RP.. 4*X + 6*Y =E= 130; RP1.. 4*X + 6*Y =E= 131; MODEL MAXUTIL/OBJ,RP/; MODEL MAXUTIL1/OBJ,RP1/; SOLVE MAXUTIL USING NLP MAXIMIZING U; SOLVE MAXUTIL1 USING NLP MAXIMIZING U;
Table 3
EXIT  OPTIMAL SOLUTION FOUND LOWER LEVEL UPPER MARGINAL  EQU OBJ . . . 1.000  EQU RP 130.000 130.000 130.000 3.000 OBJ UTILITY FUNCTION RP BUDGET CONSTRAIN LOWER LEVEL UPPER MARGINAL  VAR X INF 16.000 +INF .  VAR Y INF 11.000 +INF EPS  VAR U INF 216.000 +INF . EXIT  OPTIMAL SOLUTION FOUND LOWER LEVEL UPPER MARGINAL  EQU OBJ . . . 1.000  EQU RP1 131.000 131.000 131.000 3.021 OBJ UTILITY FUNCTION RP1 NEW RHS LOWER LEVEL UPPER MARGINAL  VAR X INF 16.125 +INF EPS  VAR Y INF 11.083 +INF .  VAR U INF 219.010 +INF .
Table 4
As can be seen the new value of the utility function is U = 219.01, and this value is the old one (216) plus the marginal utility (3). There is a small difference (0.01) because the increment of the new right hand side is not infinitessimal.
Let this problem be:
Min C = 4*K + 5*L s.t. 10 * K^{0.5} * L^{0.5} 1000The input file is built in a similar way to the utility maximization problem, changing the name of the variables and equations.K 0, L 0
In the input file seen before we add the condition of non negativity for the variables K and L (positive variables). To obtain the marginal rate of technical substitution, we add the new value of Q_{0}, (1001) for subtituting the original value (1000). The file will be as in Table 5.
VARIABLES K L C; POSITIVE VARIABLES K,L; K.L=10; L.L=10; EQUATIONS OBJ COST FUNCTION P PRODUCTION QUANTITY P1 NEW QUANTITY; OBJ.. C =E= 4*K + 5*L; P.. 10*(K**(0.5) * L**(0.5)) =G= 1000; P1.. 10*(K**(0.5) * L**(0.5)) =G= 1001; MODEL MINCOS/OBJ,P/; MODEL MINCOS1/OBJ,P1/; SOLVE MINCOS USING NLP MINIMIZING C; SOLVE MINCOS1 USING NLP MINIMIZING C;
Table 5
The solution part of the output file is in Table 6.
EXIT  OPTIMAL SOLUTION FOUND LOWER LEVEL UPPER MARGINAL  EQU OBJ . . . 1.000  EQU P 1000.000 1000.000 +INF 0.894 OBJ COST FUNCTION P PRODUCTION QUANTITY LOWER LEVEL UPPER MARGINAL  VAR K . 111.803 +INF .  VAR L . 89.443 +INF EPS  VAR C INF 894.427 +INF . EXIT  OPTIMAL SOLUTION FOUND LOWER LEVEL UPPER MARGINAL  EQU OBJ . . . 1.000  EQU P1 1001.000 1001.000 +INF 0.894 OBJ COST FUNCTION P1 NEW QUANTITY LOWER LEVEL UPPER MARGINAL  VAR K . 111.915 +INF EPS  VAR L . 89.532 +INF .  VAR C INF 895.322 +INF .
Table 6
We see that the new value of the cost function (895.322) is approximately equal to the old cost value (894.427) plus the Lagrange multiplier marginal to equation P, (0.894).
Min C = 0.6 x_{1} + x_{2} s.t. 10 x_{1} + 4 x_{2} 20 (calcium constraint) 5 x_{1} + 5 x_{2} 20 (protein constraint) 2 x_{1} + 6 x_{2} 20 (vitamin A constraint) x_{1} 0 ; x_{2} 0In this problem the difference between its GAMS input file and the previous one, is basically the change of solver (LP instead NLP)  see Table 7 with the solution part of the output file in Table 8.
VARIABLES X1 X2 C; POSITIVE VARIABLES X1,X2; EQUATIONS COST COST FUNCTION CALCIUM PROTEIN VITAMINA; COST.. C =E= 0.6*X1 + X2; CALCIUM.. 10*X1 + 4*X2 =G= 20; PROTEIN.. 5*X1 + 5*X2 =G= 20; VITAMINA.. 2*X1 + 6*X2 =G= 12; MODEL DIET/COST, CALCIUM, PROTEIN, VITAMINA/; SOLVE DIET USING LP MINIMIZING C;
Table 7
LOWER LEVEL UPPER MARGINAL  EQU COST . . . 1.000  EQU CALCIUM 20.000 34.000 +INF .  EQU PROTEIN 20.000 20.000 +INF 0.080  EQU VITAMINA 12.000 12.000 +INF 0.100 COST COST FUNCTION CALCIUM PROTEIN VITAMINA LOWER LEVEL UPPER MARGINAL  VAR X1 . 3.000 +INF .  VAR X2 . 1.000 +INF .  VAR C INF 2.800 +INF .
Table 8
We should point out that in this computer program it is possible to add the sensitivity analysis, but only with two algorithms for solving linear programming with OSL and CPLEX.
Let's consider the following problem from Winston (1991):
Max Z = 4 x_{1} + x_{2} s.t. 2 x_{1} + x_{2} 5 2 x_{1} + 3 x_{2} = 5 x_{1} 0 ; x_{2} 0 x_{1} , x_{2} integer.For the input file we only change the conditions over the variables (integer instead positive), and the solver (LP for MIP)  see Table 9 and Table 10 for the GAMS output.
VARIABLES X1 X2 Z; INTEGER VARIABLES X1,X2; EQUATIONS OBJ R1 R2; OBJ.. Z =E= 4*X1 + X2; R1.. 2*X1 + X2 =L= 5; R2.. 2*X1 + 3*X2 =E= 5; MODEL ILP/OBJ, R1, R2/; SOLVE ILP USING MIP MAXIMIZING Z;
Table 9
LOWER LEVEL UPPER MARGINAL  EQU OBJ . . . 1.000  EQU R1 INF 3.000 5.000 .  EQU R2 5.000 5.000 5.000 2.000 LOWER LEVEL UPPER MARGINAL  VAR X1 . 1.000 100.000 EPS  VAR X2 . 1.000 100.000 5.000  VAR Z INF 5.000 +INF .
Table 10
TO 


FROM 
City 1 
City 2 
City 3 
City 4 
SUPPLY

Plant 1 
8 
6 
10 
9 
35

Plant 2 
9 
12 
13 
7 
50

Plant 3 
14 
9 
16 
5 
40

DEMAND 
45 
20 
30 
30 
Figure 1
For this problem, in GAMS it is possible to define the SET (index) for plants and cities, furthermore, we display the equations of this, and display the solution of the problem.
The input file is (Table 11):
$TITLE A TRANSPORTATION PROBLEM OPTIONS LIMROW = 10; SETS I plants / PLANT1, PLANT2, PLANT3 / J markets / CITY1, CITY2, CITY3, CITY4 / ; PARAMETERS A(I) supply / PLANT1 35 PLANT2 50 PLANT3 40 B(J) demand / CITY1 45 CITY2 20 CITY3 30 CITY4 30 / ; TABLE C(I,J) shipping cost CITY1 CITY2 CITY3 CITY4 PLANT1 8 6 10 9 PLANT2 9 12 13 7 PLANT3 14 9 16 5 ; VARIABLES X(I,J) shipment quantities Z total transportation costs ; POSITIVE VARIABLE X ; EQUATIONS COST objective function SUPPLY(I) supply of plant i DEMAND(J) demand of market j ; COST .. Z =E= SUM((I,J), C(I,J)*X(I,J)) ; SUPPLY(I) .. SUM(J, X(I,J)) =L= A(I) ; DEMAND(J) .. SUM(I, X(I,J)) =G= B(J) ; MODEL TRANSPORT /ALL/ ; SOLVE TRANSPORT USING LP MINIMIZING Z ; DISPLAY X.L, Z.L ;
Table 11
The LP formulation of this problem is (Table 12):
 COST =E= objective function COST..  8*X(PLANT1,CITY1)  6*X(PLANT1,CITY2)  10*X(PLANT1,CITY3)  9*X(PLANT1,CITY4)  9*X(PLANT2,CITY1)  12*X(PLANT2,CITY2)  13*X(PLANT2,CITY3)  7*X(PLANT2,CITY4)  14*X(PLANT3,CITY1)  9*X(PLANT3,CITY2)  16*X(PLANT3,CITY3)  5*X(PLANT3,CITY4) + Z =E= 0; (LHS = 0)  SUPPLY =L= supply of plant i SUPPLY(PLANT1).. X(PLANT1,CITY1) + X(PLANT1,CITY2) + X(PLANT1,CITY3) + X(PLANT1,CITY4) =L= 35 ; (LHS = 0) SUPPLY(PLANT2).. X(PLANT2,CITY1) + X(PLANT2,CITY2) + X(PLANT2,CITY3) + X(PLANT2,CITY4) =L= 50 ; (LHS = 0) SUPPLY(PLANT3).. X(PLANT3,CITY1) + X(PLANT3,CITY2) + X(PLANT3,CITY3) + X(PLANT3,CITY4) =L= 40 ; (LHS = 0)  DEMAND =G= demand of market j DEMAND(CITY1).. X(PLANT1,CITY1) + X(PLANT2,CITY1) + X(PLANT3,CITY1) =G= 45 ; (LHS = 0 ***) DEMAND(CITY2).. X(PLANT1,CITY2) + X(PLANT2,CITY2) + X(PLANT3,CITY2) =G= 20 ; (LHS = 0 ***) DEMAND(CITY3).. X(PLANT1,CITY3) + X(PLANT2,CITY3) + X(PLANT3,CITY3) =G= 30 ; (LHS = 0 ***) DEMAND(CITY4).. X(PLANT1,CITY4) + X(PLANT2,CITY4) + X(PLANT3,CITY4) =G= 30 ; (LHS = 0 ***)
Table 12
The solution of this problem is (Table 13):
 48 VARIABLE X.L shipment quantities CITY1 CITY2 CITY3 CITY4 PLANT1 10.000 25.000 PLANT2 45.000 5.000 PLANT3 10.000 30.000  48 VARIABLE Z.L = 1020.000 total transportation costs
Table 13
EXIT  OPTIMAL SOLUTION FOUN LOWER LEVEL UPPER MARGINAL  EQU OBJ . . . 1.000  EQU RP 130.000 130.000 130.000 3.000 OBJ UTILITY FUNCTION RP BUDGET CONSTRAIN LOWER LEVEL UPPER MARGINAL  VAR X INF 16.000 +INF .  VAR Y INF 11.000 +INF EPS  VAR U INF 216.000 +INF .
Figure 2
In GAMS the input file, the LP formulation and the solution of the problem are, respectively, the following:
The input file(Table 14):
$TITLE ASSIGNMENT OPTIONS LIMROW = 10; SET I MACHINE /MACH1, MACH2, MACH3, MACH4/ SET J JOB /JOB1, JOB2, JOB3, JOB4/; TABLE T(I,J) TIMES JOB1 JOB2 JOB3 JOB4 MACH1 14 5 8 7 MACH2 2 12 6 5 MACH3 7 8 3 9 MACH4 2 4 6 10 ; VARIABLES X(I,J) Z; POSITIVE VARIABLES X(I,J); EQUATIONS OBJ LIM1(I) LIM2(J); OBJ.. Z =E= SUM((I,J), T(I,J)*X(I,J)); LIM1(I).. SUM(J, X(I,J)) =E= 1; LIM2(J).. SUM(I, X(I,J)) =E= 1; MODEL ASSIG/ALL/; SOLVE ASSIG USING LP MINIMIZING Z; DISPLAY X.L, Z.L;
Table 14
The LP formulation of the problem (Table 15):
OBJ..  14*X(MACH1,JOB1)  5*X(MACH1,JOB2)  8*X(MACH1,JOB3)  7*X(MACH1,JOB4)  2*X(MACH2,JOB1)  12*X(MACH2,JOB2)  6*X(MACH2,JOB3)  5*X(MACH2,JOB4)  7*X(MACH3,JOB1)  8*X(MACH3,JOB2)  3*X(MACH3,JOB3)  9*X(MACH3,JOB4)  2*X(MACH4,JOB1)  4*X(MACH4,JOB2)  6*X(MACH4,JOB3)  10*X(MACH4,JOB4) + Z =E= 0 ; (LHS = 0)  LIM1 =E= LIM1(MACH1).. X(MACH1,JOB1) + X(MACH1,JOB2) + X(MACH1,JOB3) + X(MACH1,JOB4) =E= 1 ; (LHS = 0 ***) LIM1(MACH2).. X(MACH2,JOB1) + X(MACH2,JOB2) + X(MACH2,JOB3) + X(MACH2,JOB4) =E= 1 ; (LHS = 0 ***) LIM1(MACH3).. X(MACH3,JOB1) + X(MACH3,JOB2) + X(MACH3,JOB3) + X(MACH3,JOB4) =E= 1 ; (LHS = 0 ***) LIM1(MACH4).. X(MACH4,JOB1) + X(MACH4,JOB2) + X(MACH4,JOB3) + X(MACH4,JOB4) =E= 1 ; (LHS = 0 ***)  LIM2 =E= LIM2(JOB1).. X(MACH1,JOB1) + X(MACH2,JOB1) + X(MACH3,JOB1) + X(MACH4,JOB1) =E= 1 ; (LHS = 0 ***) LIM2(JOB2).. X(MACH1,JOB2) + X(MACH2,JOB2) + X(MACH3,JOB2) + X(MACH4,JOB2) =E= 1 ; (LHS = 0 ***) LIM2(JOB3).. X(MACH1,JOB3) + X(MACH2,JOB3) + X(MACH3,JOB3) + X(MACH4,JOB3) =E= 1 ; (LHS = 0 ***) LIM2(JOB4).. X(MACH1,JOB4) + X(MACH2,JOB4) + X(MACH3,JOB4) + X(MACH4,JOB4) =E= 1 ; (LHS = 0 ***)
Table 15
The solution (Table 16): 36 VARIABLE X.L JOB1 JOB2 JOB3 JOB4 MACH1 1.000 MACH2 1.000 MACH3 1.000 MACH4 1.000  36 VARIABLE Z.L = 15.000
Table 16
Although the use of GAMS is not used extensively as a tool by the students in the Academic world, our opinion is that, once the students are familiar with its features, GAMS is a program which can be used to solve a huge range of different problems (Linear Programming , NonLinear Programming, Integer Problems, etc.), and also to study different aspects of the same problem (sensibility, duality, etc...) with only small variations in the input file. Because all of theses reasons, our experience as lecturers in many undergraduate courses for Economics Studies is that GAMS helps students as well as lecturers in the correct use and understanding of Programming in Economics.
The fact that students must do their own input file is not a problem (from our point of view) but the way to help the student to put in order his ideas and understand deeply the problem he has to go through.
Brooke, A and alt. (1992) GAMS: User's guide Release 2.25. The Scientific Press. USA.
Winston, W. L. (1991) Introduction to Mathematical Programming: Applications & Algorithms. PWSKENT, Boston.
See the entry for GAMS in the software catalogue for details and pointers to online information about the package.