$title THE TRANSPORTATION PROBLEM
** First, indices are declared and defined.
** Index I is used to refer to the three origins.
** Index J is used to refer to the three destinations.
** Note how the symbol `*' is used to list sets members in a compact way.
SETS
I index of shipping origins /I1*I3/
J index of shipping destinations /J1*J3/;
** Vectors of data (U(I) and V(J)) are defined as parameters
** Data are assigned to vector elements
PARAMETERS
U(I) the amount of good to be shipped from origin I
/I1 2
I2 3
I3 4/
V(J) the amount of good to be received in destination J
/J1 5
J2 2
J3 2/;
** The C(I,J) data matrix is defined as a table
** Data are assigned to matrix elements
TABLE C(I,J) cost of sending a unit from origin I to destination J
   J1 J2 J3
I1 1  2  3
I2 2  1  2
I3 3  2  1;
** The optimization variables are declared.
** First, the objective function variable (z) is declared.
** Next, the remaining variables with controlling indices are declared.
VARIABLES
z objective function variable
x(I,J) the amount of product to be shipped from origin I to destination J;
** The types of variables are given in the following sentence.
** In the transportation problem, all the variables are positive except
** the objective function variable.
POSITIVE VARIABLE x(I,J);
** The objective function equation is declared.
** The remaining six equations are declared, in a compact way,
** as two index-dependent equations.
EQUATIONS
COST objective function equation
SHIP(I) shipping equation
RECEIVE(J) receiving equation;
** The following sentences formulate the above declared equations.
** All the constraints are equality constraints (=E=).
** The first one defines the objective function equation as a summation.
** The second equation group represents three
** different single equations depending on index I.
** The left-hand-side is a sum in J of the unknowns x(I,J), and
** the right-hand-side is a previously defined vector of data.
** Similarly to SHIP constraints, the RECEIVE constraints are defined.
COST .. z =E= SUM((I,J), C(I,J)*x(I,J)) ;
SHIP(I) .. SUM(J, x(I,J)) =E= U(I) ;
RECEIVE(J) .. SUM(I, x(I,J)) =E= V(J) ;
** The next sentence names the model and list its constraints.
MODEL transport /COST,SHIP,RECEIVE/;
** The next sentence directs GAMS to solve the transportation model using
** a linear programming solver lp to minimize the objective function.
SOLVE transport USING lp MINIMIZING z;