24
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

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

  • View
    215

  • Download
    0

Embed Size (px)

Citation preview

1

GAMS/GAMSIDEAGEC 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

2

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

3

Overview

7. GAMS Check: Pre/Post Solution Analysis

8. Comparative Analysis: Multiple Submissions and Loops

9. Conditionals

10. Output Improvement and Management

11. Topics

4

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

5

Formulation of A Simple Problem

XXX winemeatbread*18*10*3

20*8*6*5.1 XXX winemeatbread

60*30*10*5 XXX winemeatbread

8.0X bread

Max

St.

6

Steps1. Variable specifications

2. Equation specification Declaration Algebraic structure specification

3. Model statement

4. Solve statement

7

8

Variable specifications

9

Variable Specification

Variable Unrestricted variables

Positive Variable Nonnegative

Binary Variable 0 or 1

Integer Variable 0, 1, 2, …, 9999

10

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.

11

Equation specification

Declaration

Algebraic structure specification

12

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

13

Model Statement

14

Model StatementIdentify models to be solved. 1. Name the model 2. Specify equations that will be included in the model in

slashes / /

15

Solve Statement

16

Solve StatementCauses GAMS to apply a solver to the model and use the data defined

SOLVE statement NotesSOLVE Consumption USING LP Maximizing Utility;

LP Max

SOLVE Consumption USING LP Minimizing Disutility ;

LP Min

SOLVE Consumption USING MIP Maximizing Utility;

Mixed Integer Programming

SOLVE Consumption USING NLP Maximizing Utility;

Non-linear Programming

17

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!

18

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 components1. The echo print2. Display of the list of symbols in the GAMS program -

symlist3. Display of some equations an variables – limrow/limcol4. Report on model size and execution time5. Model solution and solver characteristics6. List of user generated display output

19

Solution Reports

20

GAMS Output

Variables : values under lower and upper refer to bounds.

21

Equations : values under lower and upper are from RHS and relational type of equations.

GAMS Output

22

GAMS Output

Type .LO .UP .L=E= RHS RHS RHS AX=b=L= -INF RHS AX AX≤b=G= RHS INF AX AX≥b

23

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.

24

Hands On 1• Feeding Problem

• 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).

negative-Non 0,,

Unit 00.1

AVitamin 09.0*1.0*14.0*02.0

Protein 05.0*03.0*07.0*01.0 ..

Cost/lb *5*4*3

SoybeansHayCorn

SoybeansHayCorn

SoybeansHayCorn

SoybeansHayCornts

SoybeansHayCornMin