You are on page 1of 29

Workshop 08 – Introduction to Process

Optimization In GAMS®

Jorge Mario Gómez R., Ph.D.


Associate Professor
OPTIMIZATION OF CHEMICAL
PROCESSES WORSHOP
Contents
GAMS®
Workshop 08 – Introduction to Process Optimization In GAMS®
• Introduction to optimization in GAMS®
• GAMS Structure
• Precedents in GAMS optimization
• Syntax of an input file (name.gms)
• Trucks problem
• Problem
• Problem formulation
• Solution
• Bonus
References
GAMS®
Introduction to Optimization in GAMS®

• General Algebraic Modeling System (GAMS)


• Modeling system for mathematical programming and optimization.
• Free licence limited to 300 variables and 300 constraints.
• A large amount of availiable solvers.
• It has a large library with a lot of examples.
• It allows to solve most of the problems that arise in optimization.
• Intuitive transcription of the “paper” formulation into the GAMS code.
• http://www.gams.com

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
GAMS® Structure

Compilation and
Input GAMS file expansion in Output GAMS file
(NAME.gms) (NAME.lst)

Solver

• Common language through platforms and versions.


• Easy application of different solvers.
• Sintax and logic revision previous to solving.
• Easy interpretation of the output files.
• Almost none interaction of the user and the solver.

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
GAMS® Structure

• Problem formulation:
min 𝐹(𝑥, 𝑦)
𝑥,𝑦
s. t. ℎ 𝑥, 𝑦 = 0
𝑔 𝑥, 𝑦 ≤ 0
𝑥 𝜖 ℝ, 𝑦 𝜖 ℤ
• Sorts of problems: Solvers
LP: CPLEX, XPRESS, CBC.
MIP: CPLEX, XPRESS, CBC.
NLP: CONOPT, IPOPT, KNITRO, MINOS.
MINLP: DICOPT, BONMIN,SCIP.

• Focus:
It takes advantage of the power of the existing solvers.
Less emphasis in the building of algorithms.
More emphasis in the formulation of the model and its refinement.
Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042
GAMS®
GAMS® Structure

“…This task requires the following elements:


Sets
Parameters
Variables
Constraints
Objective function…” Page 1 in [1]

Parts of an optimization problem  Input in GAMS


• Sets indexes  SET
• Given data  PARAMETERS
• Decision variables  VARIABLES
• Constraints  EQUATIONS
• Objective function  EQUATION

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Syntax of in Input File

Essential parts of a *.gms file

SETS Problem sets;


PARAMETERS Problem parameters;
VARIABLES Problem variables;
EQUATIONS Problem equations;

-------------------------------------------------------------
Problem formulation The objective function and the constraints are
formulated here;
-------------------------------------------------------------

MODEL name of the model /equations included in the model/;

SOLVE name of the model USING sort of problem MINIMIZING/MAXIMIZING


objective variable;
Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042
GAMS®
Syntax of in Input File

• All declarations finish with a “;”.


• “EQUATIONS” stands for equality and inequality constraints
o =E= equal than.
o =G= greater or equal than.
o =L= less or equal than.
• Take a look at the GAMS User’s Guide at Google for information about
Mathematical functions. For example: Exponentiation
o power(x,n); 𝑥 𝜖 ℝ, 𝑛 𝜖 ℤ → 𝑥 ∗ 𝑥 ∗ ⋯ ∗ 𝑥 𝑛 𝑡𝑖𝑚𝑒𝑠
o x**m; 𝑥 > 0, 𝑚 𝜖 ℝ → exp 𝑚 ∗ ln 𝑥
o sqr(x); 𝑥 𝜖 ℝ → 𝑥 ∗ 𝑥 2 𝑡𝑖𝑚𝑒𝑠
• Variable attributes: x.LO, x.UP, x.L.
o These attributes are used to define the variable bounds and their
initialization, except for the objective variable variable_funobj.

• Comments with ‘*’ at the begining of the line


Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042
GAMS®
Syntax of in Input File

SOLVE name of the model USING sort of problem MINIMIZING/MAXIMIZING


objective variable

lp For linear programming


qcp For quadratic constraint programming
nlp For nonlinear programming
dnlp For nonlinear programming with discontinuous derivatives
mip For mixed integer programming
rmip For relaxed mixed integer programming
miqcp For mixed integer quadratic constraint programming
minlp For mixed integer nonlinear programming
rmiqcp For relaxed mixed integer quadratic constraint programming
rminlp For relaxed mixed integer nonlinear programming
mcp For mixed complementarity problems
mpec For mathematical programs with equilibrium constraints
cns For constrained nonlinear systems

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Syntax of in Input File

SOLVE name of the model USING sort of problem MINIMIZING/MAXIMIZING


objective variable

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Syntax of in Input File

SOLVE name of the model USING sort of problem MINIMIZING/MAXIMIZING


objective variable

Default solver for


nlp is ipopt;

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem - Problem

Before starting!!! Create a new project (File/Project/New Project).

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem - Problem

A tracking company has borrowed $600.000 for new equipment and is


contemplating three kinds of trucks. Truck A costs $10.000, truck B $20.000,
and truck C $23.000. How many trucks of each kind should be ordered to
obtain the greatest capacity in ton-mile per day base on the following
data?

• Truck A requires one driver per day and produces 2.100 ton-miles per
day
• Truck B requires two drives per day and produces 3.600 ton-miles per
day
• Truck C requires two drives per day and produces 3.780 ton-miles per
day
• There is a limit of 30 trucks and 145 drives.

Reference [1], Problem 1.8, Page 29.

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem – Problem Formulation

Sets:
𝑇 = 𝐴, 𝐵, 𝐶 Let be 𝑇 the set containing the types of truck. Index 𝑡

Scalars
𝐶_𝑡𝑜𝑡: Maximum resources, [$]
𝑀𝑎𝑥_𝑡: Maximum of trucks, [-]
𝑀𝑎𝑥_𝑑: Maximum of drivers, [-]

Parameters
𝑇_𝑐𝑜𝑠𝑡 𝑡 : Purchase cost by truck type, 𝑡 ∈ 𝑇 [$]
𝑇_𝑑𝑟𝑖𝑣𝑒𝑟 𝑡 : Drivers required for each type of truck, 𝑡 ∈ 𝑇 [-]
𝑇_𝑝𝑟𝑜𝑑 𝑡 : Production by truck type, 𝑡 ∈ 𝑇 [ton-miles per day]

Variables:
𝑁 𝑡 ∈ ℤ+ : Number of trucks by truck type, 𝑡 ∈ 𝑇 [-]
𝑍: Total production per day, [ton-miles/day]

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem – Problem Formulation

Constraints:
𝐷𝑚𝑎𝑥_𝑒𝑞: Maximum drivers; [-]
𝑇_𝑑𝑟𝑖𝑣𝑒𝑟 𝑡 ∗ 𝑁 𝑡 ≤ 𝑀𝑎𝑥_𝑑
𝑡∈𝑇
𝑇𝑚𝑎𝑥_𝑒𝑞: Maximum of trucks; [-]
𝑁 𝑡 ≤ 𝑀𝑎𝑥_𝑡
𝑡∈𝑇
𝐶𝑚𝑎𝑥_𝑒𝑞: Maximum cost; [$]
𝑇_𝑐𝑜𝑠𝑡 𝑡 ∗ 𝑁 𝑡 ≤ 𝐶_𝑡𝑜𝑡
𝑡∈𝑇

Objective function:
𝑃𝑟𝑜𝑑_𝑡𝑜𝑡: Total Maximum production, [ton-miles per day]
max 𝑍 = 𝑇_𝑝𝑟𝑜𝑑 𝑡 ∗ 𝑁 𝑡
𝑡∈𝑇

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem – Solution

Sets:
𝑇 = 𝐴, 𝐵, 𝐶 Let be 𝑇 the set containing the types of truck.

Scalars
𝐶_𝑡𝑜𝑡: Maximum resources, [$]
𝑀𝑎𝑥_𝑡: Maximum of trucks, [-]
𝑀𝑎𝑥_𝑑: Maximum of drivers, [-]

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem – Solution
Parameters
𝑇_𝑐𝑜𝑠𝑡 𝑡 : Purchase cost by truck type, 𝑡 ∈ 𝑇 [$]
𝑇_𝑑𝑟𝑖𝑣𝑒𝑟 𝑡 : Drivers required for each type of truck, 𝑡 ∈ 𝑇 [-]
𝑇_𝑝𝑟𝑜𝑑 𝑡 : Production by truck type, 𝑡 ∈ 𝑇 [ton-miles per day]

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem – Solution

Variables:
𝑁 𝑡 ∈ ℤ+ : Number of trucks by truck type, 𝑡 ∈ 𝑇 [-]

Variables:
𝑍: Total production per day, [ton-miles/day]

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem – Solution

Constraints:
𝐷𝑚𝑎𝑥_𝑒𝑞: 𝑡 ∈ 𝑇 𝑇_𝑑𝑟𝑖𝑣𝑒𝑟 𝑡 ∗ 𝑁 𝑡 ≤ 𝑀𝑎𝑥_𝑑
𝑇𝑚𝑎𝑥_𝑒𝑞: 𝑡 ∈ 𝑇 𝑁 𝑡 ≤ 𝑀𝑎𝑥_𝑡
𝐶𝑚𝑎𝑥_𝑒𝑞: 𝑡 ∈ 𝑇 𝑇_𝑐𝑜𝑠𝑡 𝑡 ∗ 𝑁 𝑡 ≤ 𝐶_𝑡𝑜𝑡

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem – Solution

Objective function:
𝑃𝑟𝑜𝑑_𝑡𝑜𝑡: Total Maximum production, [ton-miles per day]
max 𝑍 = 𝑇_𝑝𝑟𝑜𝑑 𝑡 ∗ 𝑁 𝑡
𝑡∈𝑇

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem – Solution

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem – Solution

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem – Solution

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem – Solution

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem – Solution

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS®
Trucks Problem – Solution

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042


GAMS
Bonus 8
In the “Optibeer” brewery are four different kinds of beers: light,
lager, ale and premium. Each kind of beer uses different amounts of
the four main components of beer: water, malt, hops and yeast. Each
kind of beer has a different utility in dollars.
Maximize the revenue of the “Optibeer” brewery based on the fact
that each raw material has certain availability.

Required amount of component in each beer (lb/L)


Light Lager Ale Premium Availability (lb)
Water 7 6 5 4 Unlimited
Malt 1 1 0 3 50
Hops 2 1 2 1 150
Yeast 1 1 1 4 80
Utility ($/L) 6 5 3 7
Adapted from Reference [4]
Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042
GAMS
Practice

The Fresh Milk cooperative supplies milk in gallon jugs from its two
warehouses located in Buffalo (New York) and Williamsport
(Pennsylvania). It has a capacity of 2000 gallons per day at Buffalo and
1600 gallons per day at Williamsport. It delivers 800 gallons/day to
Rochester (New York). Syracuse (New York) requires 1440 gallons/day and
the remainder (1360 gallons) are trucked to New York City. The cost to
ship the milk to each of the destinations is different and is given in the
following table. Establish the shipping strategy for minimum cost.

Parcial 1. 2013-10
Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042
GAMS®
References

[1] E. Thomas F, D. Himmelblau, and L. Lasdon, OPTIMIZATION OF


CHEMICAL PROCESSES, Second Edition. New York: McGraw-Hill, 2001.
[2] Rosenthal, R.E. (2015) A GAMS Tutorial, in GAMS – A User’s Guide

[3] GAMS Homepage. Recovered from http://www.gams.com/

[4] Dantzig G. B., Linear Programming and Extensions, Princeton University


Press, Princeton, New Jersey, 1963, Chapter 3-3.

Department of Chemical Engineering / Process Optimization Workshop / IQUI – 3042

You might also like