Anatomy of a GAMS Model

Download Report

Transcript Anatomy of a GAMS Model

Anatomy of a GAMS Model
Miles K. Light
University of Colorado
Preliminaries:
GAMS Program Anatomy:
All GAMS programs are TEXT.
Save GAMS programs as:
program.gms (input)
program.gms:
Input file
Output from GAMS comes as a listing
file:
program.lst (output)
program.lst:
Output file
Preliminaries:
The INPUT File:
GAMS programs use the following
Structure:
1.
Make the Definitions
2.
Define the Data
3.
Write the Model Algebra
4.
Solve the model
program.gms:
Define Variables:
X = Rice, Y = Oil
PX = Price1,PY = Price2
Insert the Data:
PX = 20; PY = 35;
Write the Algebra:
X = ..
Y = ..
Solve
Preliminaries:
Model Setup: Definitions
program.gms:
$title: Breakfast Optimization
Set
Keyword:
$title
set
Description:
Main model
description
Defines the data
domain
scalar
A preset value
parameter
A preset vector
variable
equation
Endogenous value
determined in
optimization
Equation definition
I
/eggs, toast/;
Scalar
a
Eggs to toast ratio / 2 /;
Parameter
b(I)
Supply /eggs 3,
toast 2/;
Variable
phi(I) Optimal use of inputs;
Equation
obj
Objective function;
Preliminaries:
program.gms (cont.):
Model execution:
… top half of model …
Keyword:
Model
.iterlim
Solve
.l
Description:
Tell GAMS which
equations define
the model
Maximum iterations
are allowed
Tell GAMS to solve
the model
Level value
.up
Upper limit for
variable
.lo
Lower limit
.m
Shadow Value of
Constraint
model static
phi(i).l
phi(i).lo
phi(i).up
/obj/;
= 2.0;
= 0.0;
= 100;
static.iterlim = 2000;
solve static using lp;
parameter
marginals(i) ;
marginals(i) = phi.m(i);
Practice:
$title: Breakfast Optimization: Make best use of Breakfast inputs – to maximize
breakfast happiness
Practice:
Set
Scalar
Parameter
Variable
Equations
obj..
I
/eggs, toast/;
a
c
Preferred Eggs to toast ratio / 2 /,
Maximum items you can eat at one time / 5 /;
b(I)
r(i)
Supply (in refrigerator)
/eggs 3, toast 6/,
Marginal Benefit from eating / eggs 2, toast 1 /;
phi(i)
z
Optimal use of food inputs
Value of objective function (happiness);
obj
const(i)
totfood
Objective function
Constraint
Total food intake;
z =E= sum(i, r(i) * phi(i));
Preliminaries:
Exercise #1:
The Soft Suds Brewing and Bottling Company:
Soft Suds is planning for the 2010 New Year's party. There was to be a big party at the
_____ house in Yerevan, and Gus Guzzler, the manager, knew that Soft Suds would be
called upon to supply the refreshments. However the raw materials were not ordered and
could not be obtained before the party. So there are fixed-supplies for inputs.
Gus took an inventory of the available supplies and found the following:
Malt
Hops
Yeast
75 units
60 units
50 units
Soft Suds produces two types of pick-me-ups: light beer and dark beer, with the following
specifications:
Malt
Hops
Light
Beer
2
3
2
2.00
Problem: Maximize profits given
input requirements, supplies, and
prices.
Dark
Beer
3
1
5/3
1.00
Use Linear Programming
Yeast
Price:
Preliminaries:
Exercise #2:
Problem: Copy the ‘ TRNsport’ model from the
GAMS library.
-- Impose a “toll” of 20% on the
Seattle—Chicago trade route.
-- Compute the new shipping quantitites
Use Linear Programming