You are on page 1of 20

General Algebraic Modeling System (GAMS

)

Prepared by James R. Phimister
University of Pennsylvania
Department of Chemical Engineering
Philadelphia, PA 19104/6393

The General Algebraic Modeling System (GAMS) is a programming language that provides a
flexible framework for formulating and solving linear, nonlinear and mixed-integer optimization
problems. Among other attributes, its syntax allows for declaring associations among variables,
constants, and constraints in the form of sets. Through this syntax, input files are written
compactly and similarly to the typical formulations of optimization problems. In addition, GAMS
provides a wide array of solvers to optimize a variety of problem formulations including linear
programs (LPs), nonlinear programs (NLPs), mixed-integer linear programs (MILPs, but referred
to as MIPs by GAMS), and mixed-integer nonlinear programs (MINLPs).
Here, it is possible only to provide a limited overview of the capabilities of GAMS.
Examples discussed in the text are presented to illustrate the structure of input files for an LP, an
NLP, and an MIP. These input files can be copied from the CD-ROM that accompanies this
book. It is recommended that the reader copy and run the GAMS input files, and observe the
results. The files can be modified and rerun to observe how the optimal solutions change. As
with many software applications, one of the best means for learning GAMS is through hands-on
experience.
For interested readers a detailed presentation of GAMS is provided in GAMS: A User’s
Guide: Release 2.25 (Brook, A., D. Kendrick, and A. Meeraus, Scientific Press, San Francisco,
1992). The solvers available in GAMS are presented in GAMS - The Solver Manuals (GAMS
Development Corporation, Washington, DC, 1996).
In its simplest form, GAMS operates on a user-supplied input file (normally denoted with
a .gms or .number extension to the filename), which encodes the mathematical formulation of
the optimization problem being examined. Selection of the word processor for use in editing the
input file is left to the discretion of the user. Note, however, that files should be saved in ASCII

CD-G-1

or TEXT format. Thus, the Notepad word processor included in the Windows operating system
is a good choice. GAMS is not likely to be able to run files saved in another format (e.g. that of
.doc files in WORD) since the default save options of many word processors add formatting
codes to the saved file.
GAMS operates on a variety of platforms, with execution of the program initiated from
the command prompt line. GAMS is run using the executable (GAMS) followed by the name of
the input file at the command prompt, that is:

GAMS filename.extension

In the WINDOWS operating system, GAMS is run through the Run window, shown in Figure 1,
which is obtained by left clicking the Start window and then clicking Run. In this case, the
executable (GAMS) and the input file (CASC.1) are located in the directory C:\GAMS. The
output file, CASC.lst, is placed in the same directory as the GAMS executable, not the directory
of the input file.

Figure 1. GAMS run from WINDOWS or NT.

GAMS operates on an input file in two stages:

1. Compilation. This stage ensures that the input file is understood by GAMS. The
compiler checks for errors in the input file, ensuring that the file abides to a specific
format, does not contain syntax errors, and uses an appropriate solver. The compiler
does not solve the problem or indicate that a solution exists. When the compiler
locates errors in the input file, the errors are flagged and written in the output file (e.g.,

CD-G-2

4. For instance. The user must then correct the input file. Qsteam − R1 + 30 = 0 R1 − R2 + 2.4 in which the minimum utilities for a HEN are determined by solving a linear program: Min Qsteam Qsteam s. the solution values. R4 are all non-negative real numbers. Note that the solver declared by the user must be applicable to the formulation. 2.5 = 0 R2 − R3 − 82. CD-G-3 . Output can be controlled using display options in the input file.. GAMS proceeds to carry out the optimization using an appropriate solver for the problem formulation (e. and MIP). and R1. Execution. INPUT FILE Consider Example 10. in Figure 2 contains this LP formulation. With the input file readable.g. The GAMS input file. R3.lst) before GAMS terminates. 1. When the compilation is successful. Qcw. LP.5 = 0 R3 − R4 + 75 = 0 R4 − Qcw − 15 = 0 where Qsteam. R2. and if so. an LP solver cannot be used to solve an NLP. Note that it closely resembles the written problem formulation and is equivalent to the input file in Example 10. GAMS writes to the output file. CASC. CASC. NLP. providing information on whether the solution was obtained.t. GAMS proceeds to stage 2.1.

5 =E= 0.. Z =E= Qs. R4-Qcw-15 =E= 0. In its simplest form.0000 that shows normal completion of the linear program (LP) by the solver MINOS5 to one optimal solution. EQUATIONS OBJ. B1.B4.T1. R1 =G= 0. B6. T1. Statements Although much of the input file. B5.B6. R2 =G= 0.T4. contains a wealth of information. R2-R3-82.B2. CASC. an input file must consist of statements for: CD-G-4 . The output file... VARIABLES Qs. T4. Qcw.T2. Z = 50.. B2. that is. Figure 2. R2..B1.T5.. Qs =G= 0. R4.. MODEL CASCADE /ALL/. Z .. is self-explanatory.1 to determine minimum utilities for a HEN. Qs-R1+30 =E= 0.T3..B5. T3. T2. R3 =G= 0. B3..B3... Of particular interest is the Solve Summary: S O L V E S U M M A R Y MODEL CASCADE OBJECTIVE Z TYPE LP DIRECTION MINIMIZE SOLVER MINOS5 FROM LINE 38 **** SOLVER STATUS 1 NORMAL COMPLETION **** MODEL STATUS 1 OPTIMAL **** OBJECTIVE VALUE 50.0.1. R4 =G= 0. R3-R4+75 =E= 0. SOLVE CASCADE USING LP MINIMIZING Z. R1-R2+2. CASC. GAMS input file CASC.lst. R3. Qcw =G= 0. T5. R1.5 =E= 0. OBJ . it is important to understand the structure of a GAMS input file and its statements. B4.

) and GAMS functions (sine. The following relational operators are defined: Relation Syntax Equality constraint (=) =E= Less than or equal to (≤) =L= Greater than or equal to (≥) =G= Note there is no definition for the strict inequalities less than (<) or greater to (>). A model declaration. Variable Declaration Statement. sum. etc. Each equation is defined as a statement. The most commonly used arithmetic operators are: CD-G-5 . as statements without semicolons may cause compiler errors. Every equation name is restated as written in the declaration followed by two periods and at least one space. it is recommended that all statements be ended with a semicolon. Each variable must be declared in the input file. a corresponding equation must be defined. Equation Definition Statement. with an appropriate solve statement Initially. is ended with a semi-colon. Equation Declaration Statement. To define the equation: 1. and hence. 1. -.). Equation declarations 3. The equation is stated using the declared variables and constants. the objective function variable is denoted as Z. For every declared equation name. etc. 3. Equation definitions 4. Each constraint as well as the objective function must be defined with a name. This omission is intentional and does not result in any loss of generality by GAMS. ≥. 2. In Figure 2. the operators (+. Note that a variable for the objective function must also be declared. Variable declarations and assignments 2.

3.). Solve Statement. The model declaration statement defines a user-specified name for the model and declares the equations to be included in the model. For novice GAMS users. that is. etc. it is recommend that all equations be included. Type of solving procedure (LP. minimization or maximization. several built-in functions are available. Type of optimization. Variable to be optimized. including: Function Syntax x exponential (e ) exp(x) natural log log(x) log base 10 log10(x) sine sin(x) cosine cos(x) Model Declaration Statement. The solve statement defines the: 1. Hence. MIP. The key words ‘SOLVE’ and ‘USING’ must be present in the statement. 4. Operator Syntax Addition + Subtraction - Multiplication * Division / Exponent (to the power of) ** In addition. Model to be optimized (defined previously in the model declaration statement). 2. as well as either ‘MINIMIZING’ or ‘MAXIMIZING’ CD-G-6 . It has the form: SOLVE MODEL_NAME USING PROBLEM_TYPE MINIMIZING OBJEC_FUNC_VARIABLE. the model declaration statement is: MODEL MODEL_NAME /ALL/.

These character strings also appear in the output file. EXPANDED FEATURES . however. is minimized. CD-G-7 . There are. Note that the asterisk alerts the compiler to overlook the line. is considered to be documentation attributed to the variable or equation. Any character string placed after a variable or equation has been declared. The GAMS compiler does not distinguish between upper and lower case characters. The objective function variable. Documentation. several features that greatly improve the ease of formulation and the readability of the input and output files. In Figure 2. but prior to a comma or semi-colon.DOCUMENTATION. Z. Documentation can also be included within declaration statements. the solve statement is: SOLVE CASCADE USING LP MINIMIZING Z. the type of solving procedure is LP since only linear constraints and a linear objective function appear. It is important to add documentation to the input file to simplify debugging as well as to clarify the formulation of the optimization problem. Hence. VARIABLE REDECLARATION. a large array of optimization problems can be solved. both cases may be used interchangeably in an input file. the model name is CASCADE. to allow for more readable text. the most common being: Formulation GAMS Syntax Linear program LP Mixed integer linear program MIP Nonlinear program NLP 2. Documentation can be interspersed throughout the file by placing an asterisk (*) in the first column of a documentation line. Syntax. AND DISPLAY Using the basic features of GAMS. and consequently. There are several optimization formulations that can be solved.

To accomplish this. Alternatively.R4.Variable Redeclaration.R2. For example.L. For example. the use of re-declared variables provides for a more concise input file. To define the binary variable.Qs. Expanded Input File for Example 10. these are displayed in the output.L Subsequently. is shown in Figure 4. 100 Note that binary and integer variables must be re-declared for mixed-integer programming.L’ extension to the variable) are often of most concern.R3.4. and Qs.x. The key words to define the bounds on a variable are GAMS Syntax Range on Variable FREE (default) -∞ to ∞ POSITIVE 0 to +∞ NEGATIVE -∞ to 0 BINARY 0 or 1 only INTEGER 0. It is often desirable to re-declare a variable with bounds provided.4. a DISPLAY statement is added following the MODEL statement. variables w and x are re-declared such that bounds greater than or equal to zero are applied using the statement POSITIVE VARIABLES w. …. Variable Display. ….L. for real-valued variables. as shown in Figure 3. While a range of possible outputs can be displayed. named CASC. using the input statement: DISPLAY R1. An improved input file for Example 10. 1. However. the final values for R1. are requested in tabulated form in the output file. After computing a solution.L.2. this is accomplished using the statement: BINARY VARIABLE y. Qcw. this can be accomplished by defining equations that incorporate the bounds on the variables. CD-G-8 . In addition.Qcw.L. y. GAMS can redisplay values in tabular form toward the end of the output file.L. the level (or final) outputs (denoted with a ‘. R4. GAMS displays the variable values in the output file.

When the user provides a feasible starting point.L = 60. and hence. When a variable appears alone in a denominator.000 VARIABLE QS.L = 50. Likewise.000 VARIABLE QCW.L = 0. the user may be able discern where the global minimum is likely to exist. use: x. 3. that is. the user may be able to discern where a solution cannot exist.l’) extension: x.0. especially when the initial guessed values are poor. To set a lower bound for x. It is often difficult for a nonlinear solver to locate a feasible solution (one that satisfies the constraints). 2. CD-G-9 .000 VARIABLE R4.0. or is the argument of a log function. the likelihood of successful convergence to an optimal solution is greatly improved. but prior to the equation declaration statements.L = 82. and to set an upper bound for x. GAMS defaults initial variable values to zero. When the bounds using variable re-declaration statements are inadequate. GAMS does not seek all local minima.000 VARIABLE R2. Displayed values requested in input file CASC. the solver may abort.L = 80.up = 100.1 = 50. For nonlinear programs (NLPs) it is important to provide bounds and initial conditions where possible. VARIABLE R1. An initial starting point for the solver is supplied by the user with the level (‘. provide initial conditions near this point. This is often necessary because: 1.1 Bounds and Initial Conditions. Bounding and initialization statements appear after the variable declaration statements. the surface of the objective function contains numerous local minima.0. use: x. Nonlinear programs are often multi-modal.L = 75.500 VARIABLE R3.lo = 10.000 Figure 3. additional statements are available. and hence provide tighter bounds on the search space. With physical insights.

5 =E= 0..Qs.. T5. * Nearly done! Place all of the above in the model CASCADE MODEL CASCADE /ALL/. R2. R2. * and define the equations just declared COST ..Qcw. R1-R2+2.4. specify additional bounds on variables * or initial values could be specified here. Note that the Chen approximation to the log-mean temperature difference: 1/ 3   ∆T + ∆T2  ∆TLM = ∆T1 ∆T2  1    2  CD-G-10 . * Remember the semi-colons !!! * Declare non-negative variables POSITIVE VARIABLE Qs. T4. R4-Qcw-15 =E= 0. R4. R4 Z minimum utilities . R3.T5 . R1. T1. * and solve it using an LP solver SOLVE CASCADE USING LP MINIMIZING Z.4 * The GAMS file formulates an LP to be solved for minimum utilities * Declare the variables * Note that Z (used for the objective function) * 1. should not be made positive VARIABLES Qs.. * If desired.L.T3. R1. Qs-R1+30 =E= 0. R2-R3-82.R2. Expanded input file for LP in Example 10.5 =E= 0. Qcw. in which an optimal network for a hot stream being matched with two cold streams is determined.L Figure 4. R3-R4+75 =E= 0. T3.T2. R3. Figure 5 provides the input file for the nonlinear program discussed in Example 10. Qcw.T4.R4.R3.L. * This is the input file for Example 10.. * Let’s display these variables at the solution * at the end of the output file DISPLAY R1. Z =E= Qs. must be declared * 2.L.L.. T2. * Now declare the equations in the problem! EQUATIONS COST this defines the objective function T1.L.16.

MODEL COST /ALL/. F1+F2 =E= 22. T3-430 =G= 10.333. F2.L. * Declare total variables strictly non-negative POSITIVE VARIABLES Ah1c1. Ah1c1..L = 20 . DELh1c2. AREA2..L. EBALEX2. F4-F7-F8 =E= 0. T56.16 using Chen approximation. DELh1c2. T78.LO = 330 . Ah1c2.6).. AREA2. MBALMIX1. CD-G-11 .MBALSPL3..UP = 100 . FEAS4. Ah1c1. F1. Input file for NLP in Example 10.L. T78. F4*(T4-T78) =E= 360. F7.F1. MBALSPL1. F6.L. Z =E= 1300*(Ah1c1**0. DELh1c2. F3*(T3-T56) =E= 1620.. F5. F7..L. F3-F1-F8 =E= 0. F4. T3. is provided on the accompanying CD-ROM. EBALMIX1. the input file provides a solution which deviates slightly from that reported in Chapter 10.UP = 440 . F4.L.1. FEAS3. DELh1c1.T4. T3.L = 440 .. T3. DELh1c1. DELTAC1.L. AREA1. T78.L = 440 . * For NLPs. T56. OBJ. DELh1c2=E=((T4-368)*(T78-320)*(1/2)*((T4-368)*(T78-320)))**0. FEAS4. DELh1c2. Here.. T4.UP = 440 . F3. The GAMS input file. *Chen LMTD approximation DELTAC1. ∆T1 = TinH − Tout C and ∆T2 = Tout H − TinC .L. T78. DELh1c1=E=((T3-430)*(T56-349)*(1/2)*((T3-430)+(T56-349)))**0. MBALSPL3. T3. EQUATIONS OBJ defines the objective function. EBALMIX2.L = 330 . FEAS2. DELh1c2. FEAS1. Ah1c2.. T78-320 =G= 10.L. T3. providing initial conditions and bounds can improve the solver's * likelihood of finding feasible solutions.L. DISPLAY F1. F3.LO = 330 .. DELh1c1.. as well as avoiding numerical * difficulties DELh1c1.6)+1300*(Ah1c2**0. F3-F5-F6 =E= 0. MBALMIX2. * Specify equations. 440*F2+T56*F6-T4*F4 =E= 0.LO = 330 . T56.L. FEAS3.. DELTAC2..L = 330 . F4-F2-F6 =E= 0. F2.0 . Ah1c1*DELh1c1 =E= 1620.L. MBALSPL1. T4-368 =G= 10. T56. * Define variables VARIABLES Ah1c1.LO = 330 . MBALSPL2. F4.MBALSPL2. because numerical difficulties arise due to division by zero. EBALMIX1. AREA1. T56-349 =G= 10. F7. F8.L. EBALEX1. COST.LO = 10 . T4.UP = 440 . Ah1c2. FEAS1. DISPLAY Z.UP = 100 . F3..L.. F8 . Ah1c2. Z heat exchanger cost . Consequently.L.L = 20 ..L = 100.. EBALMIX2. T4.0 .LO = 10 . 440*F1+T78*F8-T3*F3 =E= 0. F5. Figure 5. as recommended by Floudas (1995). F6. T4. MBALMIX2. Ah1c2*DELh1c2 =E= 720.L = 100. F8. T56.is used. F2.L. MBALMIX1.UP = 440 . F5. EBALEX2. SOLVE COST USING NLP MINIMIZING Z. F6.333. DELh1c1. DELTAC2. EBALEX1. T78. FEAS2.L..

EXPANDED FEATURES: SETS. by employing sets in GAMS. S} CD-G-12 .2. Note any input file that incorporates sets can be written in GAMS without defining sets. 5} Likewise. In formulating the input file. termed HOT. In this example. variables are defined with reference to whether there is a match between a hot stream and a cold stream. However. Hence. over which interval in the heat cascade. H2.3 is a continuous variable that represents the heat transferred between hot stream 1 and cold stream 1 in interval 3. Example 10. Sets allow for subscripted variables used in variable and constant declarations.C2 is a binary variable representing whether hot stream 2 is matched to cold stream 2. yH2.8. EQUATION GROUPING GAMS has a powerful feature which allows sets to be declared. input files with defined sets can be written concisely. and QH1.…. H2 is a member of the set of hot streams. where i∈{1. To illustrate the definition of sets and how they are employed. an optimization problem might contain the five constraints: xi ≤ 10 ∀i. PARAMETERS AND SCALARS. Set Declarations. In Example 10.1. it is desired to determine the least number of matches between hot and cold streams while providing maximum heat recovery.C1. The GAMS input file. Note that the problem has been restated in Figure 6. input files can be written with subscripted constraints written in a single line. and are often easier to debug and update. and if a match exists. where: HOT= {H1. MATCH.3. TABLES. As an example of the utility of declaring sets. is shown in Figure 7. as well as equation definitions.8 is considered. and provided on the accompanying CD-ROM.

2 RH2.5 .93 HI-C2: UH1.07 QHH2.4 + QH2.1 .C1.C1.95 QCC1.3 .C2 = min{875.4 + QH1.93} = 250.4 = QHH2.5 = QHH2.W = min{250.C1.4 + QH2.C2.3 = QHH1.3 = QCC2.1 + QS.C2.1 = 127.2 = 541.RH2.C1.14.1] Figure 6.C1. 762} = 762 H2-C2: UH2.5 = QCW.3 RH2.C1.C1.3 = QHH2.3 = QCC1.W.1 H2: RH2.3 + QH2. for the potential matches are: S-C2: US.C2 + yH1.WUH2.4 QH1.2 QHH2.2 + QH2.4 .k ≥ 0.3 = 298.W.C2.2 = QCC2.C2.WUH1.j ≥ 0 and y∈[0.3 QH1.1 = 127.W + yH2.5 C2: QS.4 .2 = QCC1.3 + QH2. the upper bounds.C2.W.C2 ≤ 0 H1-W: QH1.07 QCC2.C2 + yH2.2 = QHH2.4 + QH1.4 = QCW.W ST: (MILP) S: RS.C1 + yH1.3 + QH2.84 H2-W: UH2.C2US.2 = 938.C2.W.W. CD-G-13 .1 QCC1.5 = QHH1.5 .C1.C1UH1.3 C1: QH2. 250.1 = QCC2.C2.C1 = min{762.2 + QH2.yH1.W.4 = 0 QCW.72 QHH1.2 QH1.RH1.4 + QH1.2 = 76.52.4 .14 H2-C1: UH2.C2. 588.86 QCC2.2 + QH2.07 Furthermore.2 + QH2.C1.4 .C1 + yH2.93} = 588. 588.68 QHH1.W ≤ 0 H2-C1: QH2. 127.3 + QH1.yH2.C2 ≤ 0 H1-C1: QH1. 588.C2 = min{127.C1UH2.RH2.Minimize z = yS.93 H1-W: UH1.72 QHH2.RH1.4 = 125.3 + QH1.C1 ≤ 0 H1-C2: QH1.C1.W.C1 = min{1171.4 + QH2.W.yH2.14 where Qi. Uij.C1.5 = 0 QCC1.C1.5 = 0 QCW.12 QHH1.8.RH2.C1.C2 = min{1171.2 QH1.05.yH2.yH1.3 .3 = 259.C2UH1.93} = 588.68} = 127.2 + QH2. Ri.C2 ≤ 0 H2-W: QH2.4 + QH2.68.C2.3 RH1.W.84} = 747.W.4 .5 = 125.3 .1 QH2.C2.C2 + yH1.C1.4 = QHH1.yH1.W.C2UH2.C2.1 = QHS.5 + QH2.4 . 747.yS.4 = QCC1.5 H1: RH1.3 + QH2.W = min{1171.4 = 426.68 H1-C1: UH1.3 = 232.68 QCC2.C2.3 + QH2.4 = 290.3 + QH1.C1 ≤ 0 H2-C2: QH2.C1.08 QHH2.W ≤ 0 where QHS.14} = 250.5 S-C2: QS.W. MILP for Example 10.3 = 206.j.4 + QH2.4 W: QH1.05.05.3 + QH1.

SUM(INT. QMATCH(HOT. SOLVE MATCH USING MIP MINIMIZING Z."C1"..20 259."3")+Q("H1". H1b."3")+Q("H2".INT)."3").07 125. H2a.COLD.Q. * Declare variables non-negative POSITIVE VARIABLES Q(HOT. OBJ.14 H2 762. H2d. H1c CSIDE(COLD. C2..68 0."C2".84 250."4") =E= QH("H2". H2d....COLD). -R("H1". TABLE U(HOT. QMATCH(HOT. DISPLAY R."5")."3")+Q("H2". H2. H2a.COLD) Z minimum no of matches .COLD).. CD-G-14 .L. R("H2"."3").INT) Hot side heat transferred 1 2 3 4 5 S 127. MIP input file for matching heat exchangers.COLD."2").Q(HOT. H2b.95 232.68 H1 298. S. H1b."W"."4"). H1c. R(HOT."W".07 H2 938.INT). H2c..Q(HOT.INT).86 290. W / INT interval / 1.INT)."3") =E= QH("H1"."2")+Q("H2".72 C2 127. hot and interval sets SETS HOT hot streams / H1."4") =E= QH("H1".SUM(COLD."2") =E= QH("H2".07 . MODEL MATCH /ALL/.68 541.12 206.14 S 0."5") =E= QH("H2".00 .INT)... CSIDE(COLD."4")+Q("H1"."3")-R("H2"."C1"."C1".COLD).08 426. VARIABLES Q(HOT."3")+Q("H1". R("H1".00 127. SUM(HOT..10 ."1")."W"."1") =E= QH("S"."2")+Q("H2"."4")-R("H1"."C1". R("H2".0!! TABLE QH(HOT."5") =E= QH("H1".Y(HOT."4")+Q("H2".L Figure 7.COLD.INT).COLD)*Y(HOT. -R("H2". TABLE QC(COLD.4.."4")+Q("H2"."C2"."3")+Q("H1".3.INT) Cold side heat transferred 1 2 3 4 5 C1 76.5 /.COLD) upper bound on heat transfer between streams C1 C2 W H1 588. H2c.93 588."C2"."C2".COLD. S / COLD cold streams / C1.* Define cold."4")+Q("H1"."5"). R(HOT.00 747. R("H1".2. * and those which are binary BINARY VARIABLES Y(HOT. Y(HOT. H1a.INT)) =E= QC(COLD. R("H2"."3") =E= QH("H2". H1a."4").72 W 125.Z."C1".COLD))).93 250.INT)) =L= U(HOT."W"."1")+Q("S"."4")-R("H2".COLD) EQUATIONS OBJ defines the objective function S. * Define a table having more than 2 dimensions * Remember defaults are taken as 0. H2b. R("S"."2")+Q("H2".INT). Z =E= SUM(HOT.L.

COLD) upper bound on heat transfer between streams C1 C2 W H1 588. a set COLD is defined as the cold streams {C1.00 127. It is often desired to declare constants.0 using the GAMS statement: Scalar UPPER defines an upper bound /100. S / COLD cold streams / C1. when the feed temperatures for the set of cold streams {C1.8. 38/. a constant UPPER is declared and assigned the value 100. 116. Tables have a dimension of two or greater and declare inter-related parameters. Note that the elements in the set are defined within the slashes (/). 116. Similarly an array of scalars. a variable U is declared. Data Statements: Scalars. For instance. U can be declared as a 2-dimensional table whose elements are entered in GAMS using the TABLE statement: TABLE U(HOT.93 250. W} are 60. The set name is the first word in the line. respectively.3. C2.14 H2 762. W / INT interval / 1.84 250. Parameters and Tables.00 747.5 /. termed a parameter can be declared.14 S 0.00 .5} defines the intervals in the heat cascade.2. Any character strings following the set name and preceding the first slash are documentation. C2. For example. Parameters are defined for sets whose elements are the names in the array.4. In Example 10. and 38°C. C2.2. W} and the set INT = {1. These sets are defined by the statement: SETS HOT hot streams / H1.Likewise. CD-G-15 .93 588. a parameter TENTER is declared using the statement: Parameter TENTER entering cold stream temp /60.0/. H2.4. which can be referred to in the equation definitions.3. On inspection.68 0.

with sets as their elements). This is shown for the set of equations. H1-W. Set declarations and assignments 2.k is declared R(HOT. and the binary variable yi. the equation definition must do so as well. Variables can be declared over sets (that is. When table cells are left blank. rather than declare nine equations and define each equation to express the maximum heat transferred between its match (H1-C1. A model declaration.COLD. spacing between the elements is greater or equal to one space.INT). Variable bound declarations (optional) 5.The format for the table declaration is flexible. In Example 10.j. QMATCH(HOT.COLD).j is declared Y(HOT. For example. Display statements (optional) Variable Declarations. when the declaration specifies that the equation utilizes sets. File Format. etc. Variable declarations and assignments 4. It is recommended that the TAB key not be used when constructing tables as text editors save tab spaces differently. Qi. they are assigned the default value of zero.). H1-C2. Equation Definitions. Input files that include either set and data statements must be organized as follows: 1. with an equation defined to provide an upper bound on heat transferred in a match: CD-G-16 .COLD) can be declared. the variable Ri. the set of equations. H2-C1. and subsequently. defined to encompass all matches between the elements in HOT and COLD. Equation declarations 6.INT). The first term in an equation definition statement is the equation name.8.COLD).k is declared Q(HOT. Hence. Equation definitions 7. Sets allow equations to be declared for all (∀) elements in a set. Equation Declarations. with an appropriate solve statement 8. Data (or constant) declarations and assignments 3. often creating parsing problems for the compiler. QMATCH(HOT.

SUM(COLD.Q(HOT. A number of set specific functions are available in GAMS. which defines the heat balance for the stream of steam in interval 1. Compilation errors.COLD))). Until the compilation errors are corrected. The above statement sums y over all of the elements in both sets HOT and COLD.INT))=L= U(HOT. Syntax errors. When it is necessary to refer to a specific element in a set. 2. Many errors are usually reported in the output file the first time an input file is run. For example.COLD)*Y(HOT. GAMS is unable to execute the model."C2".QMATCH(HOT. All errors are written in the output file. DEBUGGING Two types of errors are encountered: errors during compilation and errors during execution. Compilation errors indicate that the input file contains statements that are not recognized by the compiler. 4. CD-G-17 . R("S". the following statement defines constraint S in Figure 7: S. Z =E= SUM(HOT. rerunning the input file after several errors have been corrected. Common compilation errors include: 1. 3.COLD). This is shown in the objective function Z: OBJ.COLD). such as failure to end a statement with a semi-colon. Incorrect references to a variable name.Y(HOT.. quotation marks are used."1"). Since errors further down in the input file are often a result of an error earlier in the file. which sums over all of the elements in a given set. it is recommended that one proceed from the top of the file downwards.COLD. SUM(INT.."1")+Q("S". Left and right parentheses not matching.."1") =E= QH("S". The most commonly used function is SUM.

consider slackening or removing some of the constraints. During compilation. Finally. In this case. The semi-colon following the statement defining equation B1 is omitted. Qs is omitted in the variable declaration statement. GAMS detects and flags the undeclared variable Qs. adding row numbers in the left-hand column.1 in Figure 2 with the following modifications: 1. However. If not. In addition. for an NLP. GAMS does not check the solve statement because the other errors are identified. When the solver reports the problem is infeasible. Also. a brief description of the errors is provided. Then. Inspect whether different initial conditions or stricter bounds avoid premature termination of the algorithm. the error occurs because QS is omitted from the variable declaration. shown in Figure 8. Consider the input file CASC. GAMS copies the input file to the output file. 2. It is usually more difficult to correct these errors because they are related to the optimization algorithm. the solver may not be able to locate a feasible solution. Check the optimization formulation and its transcription into the GAMS input file. check whether the equations can be modified/transformed to avoid this error. 3. three errors are flagged. it is recommended that the user: 1. GAMS is unable to parse statement B1 from statement B2. and re-running GAMS until a feasible solution is obtained. Is the formulation correct? Has the formulation been copied correctly to the input file? Are all of the variables and equations that use sets correctly stated? 2. The flags are normally directly below the statement at which GAMS anticipates that the error occurs. Examine equations shown to be CD-G-18 . 4. such as a divide by zero. Execution errors. re-introduce constraints that have been removed or slackened. When the solver performed an illegal operation. Consider adding or altering the bounds. If so. because the semi-colon is omitted. Execution errors occur when the program compiles successfully and a solver is attempting to locate the optimum solution. the formulation is likely to be inconsistent and the model should be re- examined. In the corresponding output file. When compilation errors are encountered. a dollar sign ($) followed by an error number is indicated. When trying to resolve execution errors. At the end of the file. check whether the problem is an LP or an MILP. attempting to discern why infeasibility is reported.

R1 =G= 0 15 B2. after the solve statement. R4 =G= 0. Output file generated from incorrect input file for Example 10.5 =E= 0.B3. It may be useful to observe the level (final) values for specific variables after the first iteration.T4. 10 T3. 3 4 EQUATIONS 5 OBJ. 1 VARIABLES 2 Qcw. 9 T2.. R2. Z .T2. R3-R4+75 =E= 0.B2. R4-Qcw-15 =E= 0.skip to find a new statement looking for a '.T5.. **** $257 140 Unknown symbol 257 Solve statement not checked because of previous errors 409 Unrecognizable item . 11 T4.. Try to provide an initial feasible solution.. infeasible in the output file. 22 SOLVE CASCADE USING LP MINIMIZING Z. R3.T3.B1.T1.B4. immediately before the solve statement: OPTION iterlim = 1 In addition.5 =E= 0. Z =E= Qs..4.. **** $409 16 B3. CD-G-19 . R1-R2+2. 12 T5. 19 B6. Qs =G= 0. R2-R3-82.' or a key word to get started again **** 3 ERROR(S) 0 WARNING(S) Figure 8. R1. 6 7 OBJ . To stop the solver after one iteration. **** $140 8 T1.B5. R2 =G= 0.. Qcw =G= 0. Check whether these equations can be modified or removed to improve the likelihood of convergence.. the following statement is added to the input file.. add appropriate display statements for those variables to be tabulated in the output file. 18 B5.. 20 21 MODEL CASCADE /ALL/.. 13 14 B1. 17 B4. R4. Qs-R1+30 =E= 0. R3 =G= 0.B6..

25. and A. CD-G-20 . D. C. Nonlinear and Mixed-Integer Optimization: Fundamentals and Applications. Oxford (1995). GAMS: A User’s Guide: Release 2. A.. GAMS-The Solver Manuals. A. Oxford University Press. GAMS Development Corporation.REFERENCES Brook. Washington. Floudas. Kendrick. Meeraus. DC (1996). Scientific Press (1992).