Fatih Pense's Blog

Linear Programming with GAMS example (Operations Research)

Monday, April 3rd, 2023


The Bing&Bang Company has two factories on China and South Korea. Each of these factories produces the same two products and then sells them to distributors within its own country. The orders from distributors have already been received for the next two months (November and December). The quantity of orders requested are shown in table. (The company is not forced to completely meet these orders)

Each factory has 20 production days available in November and 23 production days available in December to produce and ship these products. Inventories are completely exhausted at the end of October, but each factory has enough inventory capacity to hold 1,000 units total of the two products (if an excess amount is produced in November for sale in December). In either factory, the cost of holding inventory is $3 per unit of product 1 and $4 per unit of product 2.

Each factory has the same two production processes, each of which can be used to produce either of the two products. The production cost per unit produced of each product is shown in below table for each process in each factory (Factory 1 is located in China, Factory 2 is located in South Korea).

The production rate for each product (number of units produced per day devoted to that product) is presented below.

The net sales revenue (selling price-shipping costs) the company receives when a factory sells the products to customers who are located in the same country is $83 per unit of product 1 and $112 per unit of product 2. However, a factory can also make a shipment to respond the need of the other factory. In this case, an extra shipping cost of $9 per unit of product 1 and $7 per unit of product 2 is incurred.

Company makes decision to solve problems such as how much of each product should be produced by each production process in each factory during each month, as well as how much each factory should sell of each product in each month and how much each factory should ship of each product in each month to the other factory’s customers. The aim is to maximize the total profit (Σ net sales revenue- Σ the production costs, inventory costs, and extra shipping costs). Construct a generalized algebraic (closed) form model for the linear programming problem

Note that the model must be constructed with closed form (using the notations Σ ve ∀) and do not attempt to solve the model. Decision variables and parameters must be described/explained in the solution.

Solve the question using GAMS.



  • : Product type (1,2)
  • : Process (1,2)
  • : Factory (1-China,2-South Korea)
  • : Month (November,December)


  • : Demand for product type t, for factory f, on month m (GAMS: demand)
  • : Production rate for product type t, process type p, for factory f(GAMS: production_rate)
  • : Production cost for product type t, process type p, for factory f (GAMS: production_cost)
  • : Available days for month m (GAMS: available_days)
  • : Shipping cost for product type t (GAMS: shipping_cost)
  • : Selling price for product type t (GAMS: selling_price)
  • : Inventory cost for product type t (GAMS: inventory_cost)


Inventory Constraint

Inventory should be less than or equal to 1000 for each factory(f) and month(m)

Production constraint

Production is limited to production rate parameter multiplied by available days on that month. For each product type(t), processing type(p), factory(f) and month(m)

Demand constraint

Sum of produced product (P), remaining inventory from previous month(I), minus amount of product left for inventory(I), plus received shipped products from other factory(R) , should be less than or equal to demand(D). For each product type(t), factory(f) and month(m)

Shipment Equality constraint

Amount of products with type t, shipped from one factory should be equal to the products received from another factory for each month.

Objective function

Σ net sales revenue_

- Σ the production costs

- inventory costs

- extra shipping costs

GAMS code

t 'product type (Math notation: t)' /1, 2/
p 'produced by production process  (Math notation: p)' /1,2/
m 'months'/November, December/
f 'which factory' /China, SouthKorea/
demand(t,f,m) 'demand of product type (t), which factory(f), produced in which month(d)'/
1.China.November 3600
1.China.December 6300
1.SouthKorea.November 4900
1.SouthKorea.December 4200
2.China.November 4500
2.China.December 5400
2.SouthKorea.November 5100
2.SouthKorea.December 6000
production_rate(t,p,f) '(t) of product type , (p)  process type, (f)  which factory' /
1.1.China 100
1.2.China 140
1.1.SouthKorea 130
1.2.SouthKorea 110
2.1.China 120
2.2.China 150
2.1.SouthKorea 160
2.2.SouthKorea 130
production_cost(t,p,f) 'The production cost per unit produced of each product: (a) of product type , (b)  process type, (f)  which factory'/
1.1.China 62
1.2.China 59
1.1.SouthKorea 61
1.2.SouthKorea 65
2.1.China 78
2.2.China 85
2.1.SouthKorea 89
2.2.SouthKorea 86
available_days(m) 'available days in month' /
November 20
December 23
shiping_cost(t) 'for product type t'/
1 9
2 7
selling_price(t) 'for product type t'/
1 83
2 112
inventory_cost(t)'for product type t'/
1 3
2 4
inventory inventory /1000/
PR(t, p, f,m ) 'produce'
I(t, f, m) 'store at inventory at the end of m'
S(t, f, m) 'ship to other place from this factory f'
R(t, f, m) 'receive from other factory to this factory f'
Objective..  Z =E=
*Σ net sales revenue
sum( (t,f,m), selling_price(t)* ( sum( p ,
 PR(t, p, f,m )) + I(t, f, m-1) - I(t, f, m) -S(t,f,m)  + R(t,f,m) )  )
* - Σ the production costs
 - sum((t,p,f) , production_cost(t,p,f) * sum(m, PR(t, p, f,m )) )
* - inventory costs
 - sum( (t,f,m) ,inventory_cost(t) * I(t, f, m) )
* - extra shiping costs
 - sum( (t,f,m) ,shiping_cost(t) * S(t, f, m) )
DemandMax(t,f,m).. sum( p , PR(t, p, f,m )) + I(t, f, m-1) - I(t, f, m) -S(t,f,m)  + R(t,f,m) =L= demand(t,f,m)     ;
ProductionMax(t,p,f,m).. PR(t, p, f,m )  =L= available_days(m) * production_rate(t,p,f);
InventoryMax(f,m).. sum(t, I(t,f,m)) =L= inventory;
ShippingEqual1(t,m).. S(t, 'China', m ) =E= R(t, 'SouthKorea', m );
ShippingEqual2(t,m).. S(t, 'SouthKorea', m ) =E= R(t, 'China', m );
*DISPLAY  P.l , S.l , S.l ;