Documents
User Generated
Resources
Learning Center

# GAMS (PowerPoint)

VIEWS: 86 PAGES: 29

• pg 1
```									GAMS: General Algebraic Modeling System
Part2

Tanya Borisova and Xiaobing Zhao For Graduate Seminar ARE 696 by Dr. Fletcher
Tatiana.Borisova@mail.wvu.edu

Plan for Today
 

GAMS model library Transportation Problem
 

new market (Morgantown) contract on supply



Definition Comparison of the results with and without the contract – 2 ways



higher freight costs for the smaller plant – 2 ways to define Population for subsequent years

 

Population Model


Useful Features (if we have time)

 

Alias statement Large tables If-else, for, and while statements

presentation is based on

and GAMS User‟s Guide

Lets start!


Transportation problem

GAMS Model Library
• Collection of programs • You can begin with existing models and modify them




 




Agricultural Economics Applied General Equilibrium Economic Development Energy Economics Finance Forestry



  




Management Science and OR Micro Economics Recreational Models Statistics International Trade Macro Economics

Transportation Problem
 



Start GAMS Open new project, save it to the desktop (any name) Open Transportation Problem from the Model Library


type “Trnsport”





Save the file to the desktop (“Program1”, use “Save as” in “File” menu) What changes should we make to add a new market to the system? (Morgantown)

New Market
(program 1)


Add a new market – MorgantownWV
  

New member of set j Demand = 40 (hypothetical) Distances:  Seattle – Morgantown = 2.2 thousands miles


San Diego – Morgantown = 2.1 thousands miles



Write a comment to your program using
 

“*” – one-line comment “\$Ontext … \$Offtext” – multiple-lines comment



Save the file, Run

Results


What is the model status?



What plant supplies to Morgantown? How many cases?
What are the minimal transportation costs? What story do the marginal values for equations tell?







How will the costs change if we “force” Seattle plant to supply 10 cases to Morgantown?

Contract on Supply
(program 2)
 

Save your program as Program2, write comments contract on delivery of 10 cases from Seattle to Morgantown
x.fx(“Seattle”, “Morgantown”) = 10;



Turn off echo print
\$Offlisting – After defining model title, starting on the first position in the line



Turn off equation and column listing
option limrow = 0, limcol = 0;



How do the minimal transportation costs change?

Result comparison



Compare the costs and shipment patterns with and without the contract




save Solve results in a parameter multi-dimensional parameters, Loop statement

Save Solve Results in a New Parameter (program 3)


Save your program as Program3, write comments Delete the contract definition from the model After the Solve statement, declare new Parameters RES1(i,j) and cost1 and assign them the values x.L(i,j) and z.L; Define the contract Give another Solve statement Declare new Parameters RES2(i,j) and cost2, and assign them the value of x.L(i,j) and z.L Compare cost1, cost2, RES1 and RES2 (Display statement)

 

  



Solve Results: Multi-Dimensional Parameters and Loop Statement
(program 4)

Loop(ControllingSetName, Commands);


Loop: repeat the set of commands for all elements of the controlling set Save your program as Program4, write comments Delete the end of your program starting with the first Solve statement Type instead: (new slide)

 



You have this line

Freight Costs depend on Plant Size
(program 5)
 

If producer is small, freight costs are higher \$-operator: GAMS‟ way to say „only if‟ f(i) = 90\$(a(i)>500); f(i)\$(a(i)>500) = 90; - dollar on the right - dollar on the left

f(i) will be 90 only if plants i produces more than 500

Dollar-operator (cont.)


Dollar on the left:

f(i)\$(a(i)>500) = 90;

- “f(i), such that a(i)>500, equals 90” - meaning if (a(i) > 500), then f(i) = 90 - no assignment is made unless the logical condition is satisfied



Dollar on the right:
- “f(i) = 90 if a(i)>500”

f(i) = 90\$(a(i)>500);

- meaning if (a(i) > 500), then f(i) = 90, else f(i) = 0

- assignment is always made.



no variables can be used do define logical condition for GAMS technical reasons.

Dollar-operator (cont.)
 

Save your program as Program5, write comments Transportation costs are higher for a smaller producer
 




Comment out declaration of Scalar f Add f(i) to the set of Parameters Make freight costs higher by \$5/case if the plant produces less than 500 cases Print the values of parameter f (Display statement)

Dollar-operator with Subsets
(program 6)




One can define subsets containing part of the elements of another set using a Set statement

Dollar-operator with Subsets (cont.)


smalli(i) = “True” for all i that are members of smalli, and “False” otherwise

Dynamic models: Leads and Lags
(program 7)


Simplified population example




Population grows with time population(t) = a*population(t-1)





Lag: relationship between time periods T and T-1 Lead: relationship between time periods T and T+1

Open a new file, save as program7, write a comment

ORD and CARD
(program 8)


Population(t) = a**t, t = 1, 2, …



ORD: gives the relative position of a member in a set


Example: ORD(“1975”) = 1 ORD(“1976”) = 2 Example: CARD(T) = 30



CARD: the total number of elements in the set


Open a new file, save it as program8, write comments

Alias Statement
(program 9)




give another name to a previously declared set Alias (t,tp); Example:


Open new file, save it as Program9, write comments

Large Tables

FOR statement
(program 10)


Example


Open new file, save it as Program10, write a comment to the program

WHILE statement
(program 11)


Example


Open new file, save it as Program11, write comments
Numerical relationship operator

Numerical Relationship Operators

IF-ELSE STATEMENT
(program 12)


Example


Open new file, save it as Program12, write a comment

```
To top