Transcript Introduction to GAMS and 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
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
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?
G eneralized A lgebraic M odeling S ystem • 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
20 5 *
1. Variable specifications 2. Equation specification Declaration Algebraic structure specification 3. Model statement 4. Solve statement 6
Variable specifications 8
Variable Positive Variable Binary Variable Integer Variable Unrestricted variables Nonnegative 0 or 1 0, 1, 2, …, 9999 9
• GAMS requires variables in each problem to be identified. In the example, we have variables
, and bread
(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
• Algebraic form involves use of a special syntax to tell the exact form of the equation
Indicates an equality constraint 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. N ame the model 2. S pecify equations that will be included in the model in slashes / / 14
Solve Statement 15
Causes GAMS to apply a solver to the model and use the data defined
SOLVE Consumption Utility; USING LP Maximizing SOLVE Consumption USING LP Minimizing Disutility ; SOLVE Consumption USING MIP Maximizing Utility;
LP Max LP Min Mixed Integer Programming SOLVE Consumption USING NLP Utility; Maximizing Non-linear Programming 16
• 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!
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
refer to bounds.
Equations : values under
and are from RHS and relational type of equations.
RHS RHS RHS AX=b =L= -INF RHS AX =G= RHS INF AX AX≤b AX≥b
• *.gpr: GAMS project file.
• *.gms: GAMS file where to write program codes.
• *.lst: GAMS output file generated AFTER model runs.
the • *.log: GAMS log file generated WHILE model runs.
Hands On 1
• Feeding Problem
05 Protein 0 .
00 Unit A
0 Non negative • Create HandsOn1.gms
*.lst file (from with “ * your name code. Turn in an electronic copy of *.gms file and a hard copy of solution report to the end).
” on the first line of the • What if the corn price goes up to $6? Turn in a hard copy of *.lst file (from solution report to the end).