#### Transcript Introduction to GAMS and GAMSIDE

# 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?

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**

*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 Positive Variable Binary Variable Integer Variable Unrestricted variables Nonnegative 0 or 1 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**

=E= =L=

**Explanation**

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

### Solve Statement

Causes GAMS to apply a solver to the model and use the data defined

**SOLVE statement**

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

**Notes**

LP Max LP Min Mixed Integer Programming SOLVE Consumption USING NLP Utility; Maximizing Non-linear Programming 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 upper*

and are from RHS and relational type of equations.

21

### GAMS Output

Type .LO

### =E=

.UP

.L

### RHS RHS RHS AX=b =L= -INF RHS AX =G= RHS INF AX AX≤b AX≥b

22

### GAMSIDE Project

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

the 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 Vitamin

*Corn*

*Hay*

*Soybeans*

1 .

00 Unit A

*Corn*

,

*Hay*

,

*Soybeans*

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

24