Lecture 1
Lecture 1
Lecture 1
1/72
Agenda
1. Motivation
3. First steps
6. Homework 1
2/72
What is GAMS?
3/72
Theory with numbers?
Traditionally in economics:
▶ Theory & Empirics
▶ Theory "lacks" quantification of proven causalities (only
qualitative messages).
▶ Empirics needs large amounts of (accessible) data, data
generation also needs time, ex post view.
5/72
Scientific software comparison chart
6/72
Moving to GAMS
GAMS...
▶ automates the process of going from a mathematical
statement of the problem to the solution.
▶ transforms the mathematical representation to representations
required by specific solver engines.
▶ models and solves complex linear, nonlinear and integer
programming problems.
7/72
Optimization via freshman’s calculus
8/72
Moving to GAMS
Freshman calculus:
▶ One (or few) variable(s).
▶ (Non-)linear objective function.
▶ Sometimes the variable(s) are constrained to an interval, or
depend on equality side-constraints.
9/72
Advantages of GAMS
10/72
Some data sources
11/72
2. This week’s agenda
Monday:
▶ Motivation & Background GAMS
▶ First steps & Basics GAMS Studio
Tuesday:
▶ Solution homework (& recap)
▶ Fundamentals in linear programming (LP)
Wednesday:
▶ Solution homework (& recap)
▶ GAMS & Excel Interface
Thursday:
▶ Solution homework (& recap)
▶ Open session (questions, further exercises)
▶ Outlook: research possibilities & course design
12/72
3. First steps: GAMS syntax, basics and a 1st example
13/72
Cake production
14/72
Structure of a GAMS model
15/72
Input file
16/72
Structure of a GAMS model
17/72
Cake production model
18/72
Variables
19/72
Variable types
20/72
Variable attributes
21/72
Equations
22/72
Quick Note: Declaration vs. Definition
23/72
Equation types
24/72
Quick Note: " = " vs. " =E= "
25/72
Model statement
26/72
Solve statement
28/72
Cake production model
29/72
Graphical representation
feasible – A point
(x1 ; x2 ) is feasible if
it satisfies the con-
straints.
feasible region – Set
of all points which
are feasible.
30/72
Geometric solution
The optimal
solution is x1 = 5
and x2 = 22.5.
The baker’s profit is
20x1 + 30x2 = 775.
31/72
GAMS solution & listing file
32/72
Structure listing file
34/72
SolVar
35/72
File types
36/72
Further GAMS Syntax: Sets
37/72
Further GAMS Syntax: Data
38/72
Further GAMS Syntax: Parameters
39/72
Further GAMS Syntax: Tables
40/72
Further GAMS Syntax: Direct Assignment
41/72
Summary
42/72
Further indications
43/72
Further indications
44/72
Exponentiation
▶ x**n
▶ x must be positive
▶ n can be any number
▶ power(x,n)
▶ positive or negative value of x
▶ n must be integral
45/72
Summations
46/72
Products
47/72
Maximum over index
48/72
Display statement
49/72
If statements
▶ Dollar operator
▶ $ (condition) can be read as ‘such that condition is valid’
▶ Example:
▶ "If (b > 1.5) then a = 2" becomes
▶ a$(b > 1.5) = 2 ;
▶ very useful to handle exceptions
▶ If-Else
▶ elseif is optional and can be used as often as needed
▶ no declaration and no definition of equations inside if, but e.g.
solve to solve models multiple times
50/72
Tutorials and helpful material
51/72
4. Basics GAMS Studio - Welcome Page
52/72
New, Open, Save, Settings, Model Library
53/72
Clicking highlights the word
54/72
Strg + F — search & replace
55/72
Distraction free mode
56/72
Help & F1 – Index & Descriptions
57/72
Help & F1 – Index & Descriptions
58/72
Run the model
59/72
Run the model – Process Log
60/72
Run the model – Process Log
61/72
Run the model – Process Log
62/72
Reading the solution – Listing File & Navigation
63/72
Run and create a GDX File
64/72
Open / Close: Project Explorer, Process Log, Help
65/72
5. Scalar vs. Vector Format
▶ when using the vector format, one can easily change the input
data without changing the model structure
=⇒ Let‘s try to formulate our cake production model in vector
format!
66/72
Debugging tipps
67/72
Homework 1
68/72
Homework 1a
Open the cake example using vector format from today’s meeting.
How do results change if cake A requires also 1kg, and cake B 5kg
of ground almonds, given that 50kg of ground almonds are
available?
69/72
Homework 1b
The machine tool department of Delta Company was a bottleneck
to the company’s production capacity. The department had five
basic types of machine tools and worked two forty-hour-per-week
shifts. The number of machines of each type is shown in Table 1.
The machine tool department was scheduled to run six separate
jobs in a coming week. The number of units involved in each job
are given in Table 2. From previous experience, the department
knows about the hours of machine time needed per unit of job 1 to
6. This is displayed in Table 3.
Table 1: Number of machine tools
Type Number
A 12
B 8
C 15
D 6
E 2
70/72
Table 2: Number of units required
71/72
Table 3: Hours machine time per unit
Job
Machine type
1 2 3 4 5 6
A 10 3 15 3 5 6
B 12 2 20 2 6 5
C 8 4 22 3 7 4
D 9 6 16 6 8 7
E 15 5 20 6 10 8
With this given data, prepare the 1st part of the model delta.gms
including the definition of the needed sets, variables, parameters
and a table. We will continue with the 2nd part tomorrow.
72/72