Sie sind auf Seite 1von 47

Overview

GAMS/GAMSIDE

Formulation

First Look at GAMS and GAMSIDE


An Introduction

Pei Huang

1 Department of Agricultural Economics

Texas A&M University

Based on materials written by Gillig & McCarl and improved upon by many previous lab instructors
Special thanks to Mario Andres Fernandez

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

1 / 19

Overview

GAMS/GAMSIDE

Formulation

Outline
1

Overview
Information
Topics

Introduction to GAMS/GAMSIDE
GAMS Language
GAMSIDE

Formulation of a Simple Problem


An Example
Model Specications in GAMS
GAMS Output
GAMS Project

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

2 / 19

Overview

GAMS/GAMSIDE

Formulation

Info

Oce: AGLS 386


Email: peihuang@tamu.edu or petephuang@gmail.com
Oce hour: Open door policy or by appointment
Class time: 8:00am - 9:00am, Thursday. We may have more sessions
in a week whenever Dr. McCarl is traveling. I will email you when
there is a change.
Total 10-12 sessions

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

3 / 19

Overview

GAMS/GAMSIDE

Formulation

Info
Purpose: Connect lecture materials to practical programming in
GAMS.
You will do Handson exercises, plus additional model exposure in lab
but no assigned.
6 assignments
Equally weighted
Usually one week after assignment, by 5 pm
Printed / electronic copy

For FULL CREDIT use good modeling practices


Descriptive variable names ( demand and  inputs not  x and  y )
Use descriptive text
Organize programs for a clear ow
I need to see that you understand the problem, not just programming

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

4 / 19

Overview

GAMS/GAMSIDE

Formulation

Topics

First Look at GAMS and GAMSIDE


Formulation of A General Problem
Model Inspection & Error Messages
Power of GAMS
Good Modeling Practices

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

5 / 19

Overview

GAMS/GAMSIDE

Formulation

Topics

First Look at GAMS and GAMSIDE


Formulation of A General Problem
Model Inspection & Error Messages
Power of GAMS
Good Modeling Practices

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

5 / 19

Overview

GAMS/GAMSIDE

Formulation

Topics

First Look at GAMS and GAMSIDE


Formulation of A General Problem
Model Inspection & Error Messages
Power of GAMS
Good Modeling Practices

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

5 / 19

Overview

GAMS/GAMSIDE

Formulation

Topics

First Look at GAMS and GAMSIDE


Formulation of A General Problem
Model Inspection & Error Messages
Power of GAMS
Good Modeling Practices

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

5 / 19

Overview

GAMS/GAMSIDE

Formulation

Topics

First Look at GAMS and GAMSIDE


Formulation of A General Problem
Model Inspection & Error Messages
Power of GAMS
Good Modeling Practices

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

5 / 19

Overview

GAMS/GAMSIDE

Formulation

Topics

Conditionals
GAMS Check: Pre/Post Solution Analysis
Examining A Model for Flaws
Report Writing
Comparative Analysis: Multiple Submissions and Loops
Non-linear Programming Problems

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

6 / 19

Overview

GAMS/GAMSIDE

Formulation

Topics

Conditionals
GAMS Check: Pre/Post Solution Analysis
Examining A Model for Flaws
Report Writing
Comparative Analysis: Multiple Submissions and Loops
Non-linear Programming Problems

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

6 / 19

Overview

GAMS/GAMSIDE

Formulation

Topics

Conditionals
GAMS Check: Pre/Post Solution Analysis
Examining A Model for Flaws
Report Writing
Comparative Analysis: Multiple Submissions and Loops
Non-linear Programming Problems

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

6 / 19

Overview

GAMS/GAMSIDE

Formulation

Topics

Conditionals
GAMS Check: Pre/Post Solution Analysis
Examining A Model for Flaws
Report Writing
Comparative Analysis: Multiple Submissions and Loops
Non-linear Programming Problems

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

6 / 19

Overview

GAMS/GAMSIDE

Formulation

Topics

Conditionals
GAMS Check: Pre/Post Solution Analysis
Examining A Model for Flaws
Report Writing
Comparative Analysis: Multiple Submissions and Loops
Non-linear Programming Problems

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

6 / 19

Overview

GAMS/GAMSIDE

Formulation

Topics

Conditionals
GAMS Check: Pre/Post Solution Analysis
Examining A Model for Flaws
Report Writing
Comparative Analysis: Multiple Submissions and Loops
Non-linear Programming Problems

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

6 / 19

Overview

GAMS/GAMSIDE

Formulation

What is GAMS?

Generalized Algebraic Modeling System

A programming language for setting up and solving mathematical


programming optimization models
All-In-One Package that allows one 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

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

7 / 19

Overview

GAMS/GAMSIDE

Formulation

What is GAMS IDE?

Integrated Development Environment

A graphical interface to create, debug, edit and run GAMS les


Download the free version from GAMS website
http://www.gams.com/download/

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

8 / 19

Overview

GAMS/GAMSIDE

Formulation

A simple problem
Suppose we wish to solve the optimization problem

max 3Xbread + 10Xmeat + 18Xwine


s.t.

Objective

1.5Xbread + 6Xmeat + 8Xwine 20 Money


5Xbread + 10Xmeat + 30Xwine 60 Time
Xbread

0.8

Xbread , Xmeat , Xwine

Variables:

Sustenance

Xbread , Xmeat , Xwine

Equations
Objective
Constraints: Money, Time, Sustenance

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

9 / 19

Overview

GAMS/GAMSIDE

Formulation

Using GAMS

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

10 / 19

Overview

GAMS/GAMSIDE

Formulation

Using GAMS
Variable specications
Objective function

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

10 / 19

Overview

GAMS/GAMSIDE

Formulation

Using GAMS
Variable specications
Objective function
Considered variables

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

10 / 19

Overview

GAMS/GAMSIDE

Formulation

Using GAMS
Variable specications
Objective function
Considered variables

Equation specications
Declaration

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

10 / 19

Overview

GAMS/GAMSIDE

Formulation

Using GAMS
Variable specications
Objective function
Considered variables

Equation specications
Declaration
Algebraic structure
specication

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

10 / 19

Overview

GAMS/GAMSIDE

Formulation

Using GAMS
Variable specications
Objective function
Considered variables

Equation specications
Declaration
Algebraic structure
specication

Model statement

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

10 / 19

Overview

GAMS/GAMSIDE

Formulation

Using GAMS
Variable specications
Objective function
Considered variables

Equation specications
Declaration
Algebraic structure
specication

Model statement
Solve statement

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

10 / 19

Overview

GAMS/GAMSIDE

Formulation

Variable Specication
Types of variables

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

Variable

Unrestricted variables

Positive Variable

Nonnegative

Binary Variable

0 or 1

Integer Variable

0, 1, 2, . . . , 9999

11 / 19

Overview

GAMS/GAMSIDE

Formulation

Variable Specication
Types of variables
Variable

Unrestricted variables

Positive Variable

Nonnegative

Binary Variable

0 or 1

Integer Variable

0, 1, 2, . . . , 9999

GAMS requires variables


in each problem to be
identied.

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

11 / 19

Overview

GAMS/GAMSIDE

Formulation

Variable Specication
Types of variables
Variable

Unrestricted variables

Positive Variable

Nonnegative

Binary Variable

0 or 1

Integer Variable

0, 1, 2, . . . , 9999

GAMS requires variables


in each problem to be
identied.
The objective function
together has to be dened
as a variable.

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

11 / 19

Overview

GAMS/GAMSIDE

Formulation

Variable Specication
Types of variables
Variable

Unrestricted variables

Positive Variable

Nonnegative

Binary Variable

0 or 1

Integer Variable

0, 1, 2, . . . , 9999

GAMS requires variables


in each problem to be
identied.
The objective function
together has to be dened
as a variable.
Variable names can be up
to 64 characters and can
have explanatory text.

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

11 / 19

Overview

GAMS/GAMSIDE

Formulation

Equation Specication

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

12 / 19

Overview

GAMS/GAMSIDE

Formulation

Equation Specication
Name each equation in
the model.

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

12 / 19

Overview

GAMS/GAMSIDE

Formulation

Equation Specication
Name each equation in
the model.
Specify the algebraic
structure.

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

12 / 19

Overview

GAMS/GAMSIDE

Formulation

Equation Specication
Name each equation in
the model.
Specify the algebraic
structure.
Two dots following each
equation name

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

12 / 19

Overview

GAMS/GAMSIDE

Formulation

Equation Specication
Name each equation in
the model.
Specify the algebraic
structure.
Two dots following each
equation name
The specic forms of
constraints

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

Syntax

Constraint forms

=e=

equal

=l=

less than or equal

=g=

greater than or equal

12 / 19

Overview

GAMS/GAMSIDE

Formulation

Model Statement
Name the model
Specify equations that will
be included in the model
in slashes /

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

13 / 19

Overview

GAMS/GAMSIDE

Formulation

Model Statement
Name the model
Specify equations that will
be included in the model
in slashes /

Examples

Model Consumption1 /All/


;
Model Consumption2 /
objective, money, time/;

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

13 / 19

Overview

GAMS/GAMSIDE

Formulation

Solve Statement
Examples

SOLVE Consumption USING


LP Maximizing Utility;
SOLVE Consumption USING
LP Minimizing Disutility
;
SOLVE Consumption USING
MIP Maximizing Utility;
SOLVE Consumption USING
NLP Maximizing Utility;

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

14 / 19

Overview

GAMS/GAMSIDE

Formulation

Heads Up for Semi-colons


Each declaration must
terminate with a ;.
Statements may be
several lines long or may
contain several elements.
Omission would lead to
(many) Syntax Errors!

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

15 / 19

Overview

GAMS/GAMSIDE

Formulation

GAMS Output

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

16 / 19

Overview

GAMS/GAMSIDE

Formulation

GAMS Output

Output navigation

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

16 / 19

Overview

GAMS/GAMSIDE

Formulation

GAMS Output

Output navigation
Objective function
solution

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

16 / 19

Overview

GAMS/GAMSIDE

Formulation

GAMS Output

Output navigation
Objective function
solution
Equation solutions

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

16 / 19

Overview

GAMS/GAMSIDE

Formulation

GAMS Output

Output navigation
Objective function
solution
Equation solutions
Variable solutions

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

16 / 19

Overview

GAMS/GAMSIDE

Formulation

GAMS Project

*.gpr: GAMS project le


*.gms: GAMS le where to write program codes BEFORE the model
runs
*.lst: GAMS output le generated AFTER the model runs
*.log: GAMS log le generated WHILE the model runs

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

17 / 19

Overview

GAMS/GAMSIDE

Formulation

GAMS Project

*.gpr: GAMS project le


*.gms: GAMS le where to write program codes BEFORE the model
runs
*.lst: GAMS output le generated AFTER the model runs
*.log: GAMS log le generated WHILE the model runs

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

17 / 19

Appendix

Heads On 1
Sove the feeding problem using GAMS

min 3Xcorn + 4Xhay + 5Xsoybeans


s.t.

Cost/lb

0.01Xcorn + 0.07Xhay + 0.03Xsoybeans 0.05 Protein


0.02Xcorn + 0.14Xhay + 0.1Xsoybeans 0.09 Vitamin A

1
2
3

Xcorn + Xhay + Xsoybeans

=1

Unit

Xcorn , Xhay , Xsoybeans

Non negative

Set up the model in GAMS and solve it.


Solve the model when the corn price increases to $6?
Solve the model when the minimum requirement of vitamin A is set to
zero?

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

18 / 19

Appendix

Requirements

Create HandsOn1.gms with  * your name on the rst line of the code.
A good programming habit: make comments in your code.
Turn in an electronic copy of *.gms le for Part 1 via email.
Turn in a hard copy of *.lst le (from Solution Report to the end) for
ALL three parts.
You can work as a group with no more than three people.
The hands on is due by 5:00pm, September 12.

Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013

19 / 19

Das könnte Ihnen auch gefallen