Introduction to GAMS and GAMSIDE

Report
GAMS/GAMSIDE
AGEC 641 Lab, Fall 2011
Mario Andres Fernandez
Based on material written by Gillig and McCarl and improved upon by previous lab
instructors.
Special thanks to Yuquan “Wolfgang” Zhang
1
Overview
1. Introduction to GAMS/GAMSIDE
2. Formulation of a General Problem
3. Model Inspection & Error Message
4. Power of GAMS
5. Examining A Model for Flaws
6. Good Modeling Practices
2
Overview
7. GAMS Check: Pre/Post Solution Analysis
8. Comparative Analysis: Multiple Submissions and Loops
9. Conditionals
10. Output Improvement and Management
11. Topics
3
What is GAMS?
Generalized Algebraic Modeling System
• Programming language for setting up and solving optimization
models
• All-In-One Package that allows to
 Specify the structure of an optimization model
 Specify and calculate data that go into the model
 Solve that model
 Conduct report writing on a model
 Perform a comparative static analysis
4
Formulation of A Simple Problem
Max
St.
3* X bread 10* X meat 18* X wine
1.5 * X bread  6 * X meat  8 * X wine  20
5 * X bread 10* X meat  30* X wine  60
X
bread
 0.8
5
Steps
1. Variable specifications
2. Equation specification
 Declaration
 Algebraic structure specification
3. Model statement
4. Solve statement
6
7
Variable
specifications
8
Variable Specification
Variable
Unrestricted variables
Positive Variable
Nonnegative
Binary Variable
0 or 1
Integer Variable
0, 1, 2, …, 9999
9
Variable Specification
• GAMS requires variables in each problem to be
identified. In the example, we have variables
utility (variable), and bread, meat, and wine
(positive variables)
• max CX should become max Z, where Z=CX.
• Variable name can be up to 64 characters and can
have explanatory text.
10
Equation
specification
Declaration
Algebraic
structure
specification
11
Equation Specification
• Algebraic form involves use of a special syntax
to tell the exact form of the equation
Syntax
Explanation
=E=
Indicates an equality constraint
=L=
Indicates a less than or equal to constraint
=G=
Indicates a greater than or equal to
constraint
12
Model
Statement
13
Model Statement
Identify models to be solved.
1. Name the model
2. Specify equations that will be included in the model in
slashes / /
14
Solve
Statement
15
Solve Statement
Causes GAMS to apply a solver to the model and
use the data defined
SOLVE statement
SOLVE Consumption USING LP Maximizing
Utility;
SOLVE Consumption USING LP Minimizing
Disutility ;
SOLVE Consumption USING MIP Maximizing
Utility;
Notes
LP Max
Mixed Integer
Programming
SOLVE Consumption USING NLP Maximizing
Utility;
Non-linear
Programming
LP Min
16
Semi-Colons ;
• Each command line must terminate with a ;
• Statements may be several lines long or may
contain several elements
• Omission would lead to (many) Syntax Errors!
17
Solution Reports
• When GAMS is run the output is automatically
place in the so called LST file
– Example01.gms  Example01.lst
• LST file contains a number of components
1. The echo print
2. Display of the list of symbols in the GAMS program symlist
3. Display of some equations an variables –
limrow/limcol
4. Report on model size and execution time
5. Model solution and solver characteristics
6. List of user generated display output
18
Solution
Reports
19
GAMS
Output
Variables :
values
under
lower and
upper refer
to bounds.
20
GAMS
Output
Equations :
values under
lower and
upper are from
RHS and
relational type
of equations.
21
GAMS Output
Type
=E=
=L=
=G=
.LO .UP .L
RHS RHS RHS AX=b
-INF RHS AX AX≤b
RHS INF AX AX≥b
22
GAMSIDE Project
• *.gpr: GAMS project file.
• *.gms: GAMS file where to write program
codes.
• *.lst: GAMS output file generated AFTER the
model runs.
• *.log: GAMS log file generated WHILE the
model runs.
23
Hands On 1
• Feeding Problem
Min
3 * Corn  4 * Hay  5 * Soybeans
Cost/lb
s.t.
0.01* Corn  0.07 * Hay  0.03* Soybeans 0.05
Protein
0.02* Corn  0.14* Hay  0.1* Soybeans 0.09
Corn  Hay  Soybeans 1.00
Vitamin A
Unit
Corn, Hay, Soybeans 0
Non - negative
• Create HandsOn1.gms with “* your name” on the first line of the
code. Turn in an electronic copy of *.gms file and a hard copy of
*.lst file (from solution report to the end).
• What if the corn price goes up to $6? Turn in a hard copy of *.lst file
(from solution report to the end).
24

similar documents