## The GAMS Model

The same model modeled in GAMS. The use of concise algebraic descriptions makes the model highly compact, with a logical structure. Internal documentation, such as explanation of parameters and units of measurement, makes the model easy to read.

```
Sets
i canning plants / Seattle, San-Diego /
j markets / New-York, Chicago, Topeka / ;
Parameters
a(i) capacity of plant i in cases
/ Seattle 350
San-Diego 600 /
b(j) demand at market j in cases
/ New-York 325
Chicago 300
Topeka 275 / ;
Table d(i,j) distance in thousands of miles
New-York Chicago Topeka
Seattle 2.5 1.7 1.8
San-Diego 2.5 1.8 1.4 ;
Scalar f freight in dollars per case per thousand miles /90/ ;
Parameter
c(i,j) transport cost in thousands of dollars per case ;
c(i,j) = f * d(i,j) / 1000 ;
Variables
x(i,j) shipment quantities in cases
z total transportation costs in thousands of dollars ;
Positive variables x ;
Equations
cost define objective function
supply(i) observe supply limit at plant i
demand(j) satisfy demand at 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 ;
```

#### Sets

```
Sets
i canning plants / Seattle, San-Diego /
j markets / New-York, Chicago, Topeka / ;
```

GAMS lets you specify indices in a straightforward way: declare and name the set (here, I and J), and enumerate their elements.

#### Parameters

```
Parameters
a(i) capacity of plant i in cases
/ Seattle 350
San-Diego 600 /
b(j) demand at market j in cases
/ New-York 325
Chicago 300
Topeka 275 / ;
```

Here data are entered as indexed parameters A(I) and B(J), and values simply are listed.

GAMS lets you place explanatory text (shown in lower case) throughout your model, as you develop it. Your comments are automatically incorporated into the output report, at the appropriate places.

#### Table

```
Table d(i,j) distance in thousands of miles
New-York Chicago Topeka
Seattle 2.5 1.7 1.8
San-Diego 2.5 1.8 1.4 ;
```

Data can also be entered in convenient table form. GAMS lets you input data in their basic form - transformations are specified algebraically.

#### Scalar

`Scalar f freight in dollars per case per thousand miles /90/ ;`

A constant simply can be declared as a SCALAR, and its value specified.

#### Data manipulation

```
Parameter
c(i,j) transport cost in thousands of dollars per case ;
c(i,j) = f * d(i,j) / 1000 ;
```

When data values are to be calculated, you first declare the parameter (i.e. give it a symbol and, optionally, index it), then give its algebraic formulation. GAMS will automatically make the calculations.

#### Variables

```
Variables
x(i,j) shipment quantities in cases
z total transportation costs in thousands of dollars ;
Positive variables x ;
```

Decision variables are expressed algebraically, with their indices specified. From this general form, GAMS generates each instance of the variable in the domain.

Variables are specified as to type: FREE, POSITIVE, NEGATIVE, BINARY, or INTEGER. The default is FREE.

The objective variable (z, here) is simply declared without an index.

#### Equations

```
Equations
cost define objective function
supply(i) observe supply limit at plant i
demand(j) satisfy demand at 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) ;
```

Objective function and constraint equations are first declared by giving them names. Then their general algebraic formulae are described. GAMS now has enough information (from data entered above and from the algebraic relationships specified in the equations) to automatically generate each individual constraint statement - as you can see in the output report below. An extensive set of tools enables you to model any expression that can be stated algebraically: arithmetic, indexing, functions and exception-handling log (e.g. if-then-else and such-that constructs).

=E= indicates 'equal to'

=L= indicates 'less than or equal to'

=G= indicates 'greater than or equal to'

#### Model Statement

```
Model transport /all/ ;
```

The model is given a unique name (here, TRANSPORT), and the modeler specifies which equations should be included in this particular formulation. In this case we specified ALL which indicates that all equations are part of the model. This would be equivalent to MODEL TRANSPORT /COST, SUPPLY, DEMAND/ . This equation selection enables you to formulate different models within a single GAMS input file, based on the same or different given data.

#### Solve Statement

```
Solve transport using LP minimizing z ;
```

The solve statement (1) tells GAMS which model to solve, (2) selects the solver to use (in this case an LP solver), (3) indicaties the direction of the optimization, either MINIMIZING or MAXIMIZING , and (4) specifies the objective variable.