power of gams - department of agricultural...
TRANSCRIPT
Outline Features Library Tips
Power of GAMS
Pei Huang1
1Department 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 / 17
Outline Features Library Tips
Outline
1 Why should we use GAMS?
2 GAMS Features
3 Model Library
4 Operating Tips
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 2 / 17
Outline Features Library Tips
Why should we use GAMS?
Algebraic modeling
Context changesExpandability - Expanding scopeExpandability - Augmenting existing models
Self-documenting nature
Small to large modeling
GAMS solvers
Model library
Use by others
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 3 / 17
Outline Features Library Tips
Why should we use GAMS?
Algebraic modeling
Context changesExpandability - Expanding scopeExpandability - Augmenting existing models
Self-documenting nature
Small to large modeling
GAMS solvers
Model library
Use by others
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 3 / 17
Outline Features Library Tips
Why should we use GAMS?
Algebraic modeling
Context changesExpandability - Expanding scopeExpandability - Augmenting existing models
Self-documenting nature
Small to large modeling
GAMS solvers
Model library
Use by others
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 3 / 17
Outline Features Library Tips
Why should we use GAMS?
Algebraic modeling
Context changesExpandability - Expanding scopeExpandability - Augmenting existing models
Self-documenting nature
Small to large modeling
GAMS solvers
Model library
Use by others
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 3 / 17
Outline Features Library Tips
Why should we use GAMS?
Algebraic modeling
Context changesExpandability - Expanding scopeExpandability - Augmenting existing models
Self-documenting nature
Small to large modeling
GAMS solvers
Model library
Use by others
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 3 / 17
Outline Features Library Tips
Why should we use GAMS?
Algebraic modeling
Context changesExpandability - Expanding scopeExpandability - Augmenting existing models
Self-documenting nature
Small to large modeling
GAMS solvers
Model library
Use by others
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 3 / 17
Outline Features Library Tips
Why should we use GAMS?
Algebraic modeling
Context changesExpandability - Expanding scopeExpandability - Augmenting existing models
Self-documenting nature
Small to large modeling
GAMS solvers
Model library
Use by others
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 3 / 17
Outline Features Library Tips
Context Changes
ExampleSETSProcess Production process
/Corn Corn production
Wheat Wheat production
Cotton Cotton production
/
Resource Resource item used
/Land Land used by process
Labor Labor used by process
/;
ExampleSETSProcess Production process
/MakeChair Chair production
MakeTable Table production
MakeLamp Lamp production
/
Resource Resource item used
/Cap Max Production Capacity
Labor Labor used by process
/;
Context changes but the model structure is the SAME! Only elementsin sets are changed.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 4 / 17
Outline Features Library Tips
Context Changes
ExampleSETSProcess Production process
/Corn Corn production
Wheat Wheat production
Cotton Cotton production
/
Resource Resource item used
/Land Land used by process
Labor Labor used by process
/;
ExampleSETSProcess Production process
/MakeChair Chair production
MakeTable Table production
MakeLamp Lamp production
/
Resource Resource item used
/Cap Max Production Capacity
Labor Labor used by process
/;
Context changes but the model structure is the SAME! Only elementsin sets are changed.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 4 / 17
Outline Features Library Tips
Context Changes
ExampleSETSProcess Production process
/Corn Corn production
Wheat Wheat production
Cotton Cotton production
/
Resource Resource item used
/Land Land used by process
Labor Labor used by process
/;
ExampleSETSProcess Production process
/MakeChair Chair production
MakeTable Table production
MakeLamp Lamp production
/
Resource Resource item used
/Cap Max Production Capacity
Labor Labor used by process
/;
Context changes but the model structure is the SAME! Only elementsin sets are changed.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 4 / 17
Outline Features Library Tips
Context Changes
ExampleTABLE ResourceUse(Resource,Process)
Resource usedCorn Wheat Cotton
Land 1 1 1Labor 6 4 8 ;
PARAMETERRevenue(Process)
Revenues from process production
/Corn 109Wheat 90Cotton 115 /
ResourceAvail(Resource)
Resource availability
/Land 100Labor 500 /;
ExampleTABLE ResourceUse(Resource,Process)
Resource usedMakeChair MakeTable MakeLamp
Cap 2 3 1.1Labor 1 2 0.5 ;
PARAMETERRevenue(Process)
Revenues from process production
/MakeChair 11MakeTable 10MakeLamp 12 /ResourceAvail(Resource)
Resource availability
/Cap 12Labor 5/;
Context changes but the model structure is the SAME! The only partmodi�ed is the data.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 5 / 17
Outline Features Library Tips
Context Changes
ExampleTABLE ResourceUse(Resource,Process)
Resource usedCorn Wheat Cotton
Land 1 1 1Labor 6 4 8 ;
PARAMETERRevenue(Process)
Revenues from process production
/Corn 109Wheat 90Cotton 115 /
ResourceAvail(Resource)
Resource availability
/Land 100Labor 500 /;
ExampleTABLE ResourceUse(Resource,Process)
Resource usedMakeChair MakeTable MakeLamp
Cap 2 3 1.1Labor 1 2 0.5 ;
PARAMETERRevenue(Process)
Revenues from process production
/MakeChair 11MakeTable 10MakeLamp 12 /ResourceAvail(Resource)
Resource availability
/Cap 12Labor 5/;
Context changes but the model structure is the SAME! The only partmodi�ed is the data.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 5 / 17
Outline Features Library Tips
Context Changes
ExampleTABLE ResourceUse(Resource,Process)
Resource usedCorn Wheat Cotton
Land 1 1 1Labor 6 4 8 ;
PARAMETERRevenue(Process)
Revenues from process production
/Corn 109Wheat 90Cotton 115 /
ResourceAvail(Resource)
Resource availability
/Land 100Labor 500 /;
ExampleTABLE ResourceUse(Resource,Process)
Resource usedMakeChair MakeTable MakeLamp
Cap 2 3 1.1Labor 1 2 0.5 ;
PARAMETERRevenue(Process)
Revenues from process production
/MakeChair 11MakeTable 10MakeLamp 12 /ResourceAvail(Resource)
Resource availability
/Cap 12Labor 5/;
Context changes but the model structure is the SAME! The only partmodi�ed is the data.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 5 / 17
Outline Features Library Tips
Comparison
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 6 / 17
Outline Features Library Tips
Expandability - Expanding Scope
ExampleSETSProcess Production process/Corn Corn productionWheat Wheat productionCotton Cotton productionSoybean Soybeans production /
Resource Resource item used/Land Land used by processLabor Labor used by process/;
TABLE ResourceUse(Resource,Process) Resource usedCorn Wheat Cotton Soybean
Land 1 1 1 1Labor 6 4 8 4 ;
PARAMETERRevenue(Process) Revenues from process production/Corn 109Wheat 90Cotton 115Soybean 95 /
ResourceAvail(Resource) Resource availability/Land 100Labor 500 /;
Instead of growing 3crops, now a farmer alsowants to grow soybeans.One needs only to modifyan element in Processset, ResourceUse table,and Revenue parameter.
Other data and themodel structure remainsthe SAME!
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 7 / 17
Outline Features Library Tips
Expandability - Augment Existing Models
ExamplePARAMETERRevenue(Process) Revenues from process production/Corn 109Wheat 90Cotton 115Soybean 95 /
ResourceAvail(Resource) Resource availability/Land 100Labor 500 /
MinLand(Process) Minimum land requirement/Corn 0Wheat 10Cotton 0Soybean 0 /;
EQUATIONSObjective Maximize farm incomeResourceEq(Resource) Resource constraintMinLandReq(Process) Minimum land requirement ;
MinlandReq(Process)..ResourceUse(“Land”,Process)*Production(Process)=g= MinLand(Process) ;
Modi�cation includesadding data on minimumland use, and equationspeci�cation onminimum land use.
Other data and themodel structure remainsthe SAME!
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 8 / 17
Outline Features Library Tips
Self-documenting Nature
GAMS allows one to add explanatory text when naming SETS,PARAMETERS, TABLES, VARIABLES, EQUATIONS, but it is agood habit to name them with easy-understanding words instead ofsimple letters.
Which form between the examples below clearly shows the context ofitself?
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 9 / 17
Outline Features Library Tips
Self-documenting Nature
GAMS allows one to add explanatory text when naming SETS,PARAMETERS, TABLES, VARIABLES, EQUATIONS, but it is agood habit to name them with easy-understanding words instead ofsimple letters.
Which form between the examples below clearly shows the context ofitself?
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 9 / 17
Outline Features Library Tips
Self-documenting Nature
Always remember commenting your code. Comments can not onlyhelp others who read your code, but also help yourself for futurereferences.
Comment a line: asterisk �*�
Comment multiple lines: put comments between $ONTEXT and$OFFTEXT
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 10 / 17
Outline Features Library Tips
Small to Large Modeling
GAMS expandability allows the same model structure, calculations,and report writing to be used with SETS with few elements vs. SETSwith many items.
Using a small data set allows up to examine the model structure andfunction easier and better. Then later one can use the same algebrafor a large problem.
Use subsetsUse small group of scenarios (1 or 2)Use aggregate regions
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 11 / 17
Outline Features Library Tips
Small to Large Modeling
GAMS expandability allows the same model structure, calculations,and report writing to be used with SETS with few elements vs. SETSwith many items.
Using a small data set allows up to examine the model structure andfunction easier and better. Then later one can use the same algebrafor a large problem.
Use subsetsUse small group of scenarios (1 or 2)Use aggregate regions
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 11 / 17
Outline Features Library Tips
Small to Large Modeling
GAMS expandability allows the same model structure, calculations,and report writing to be used with SETS with few elements vs. SETSwith many items.
Using a small data set allows up to examine the model structure andfunction easier and better. Then later one can use the same algebrafor a large problem.
Use subsetsUse small group of scenarios (1 or 2)Use aggregate regions
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 11 / 17
Outline Features Library Tips
GAMS Solvers
GAMS integrates many solvers that can solve most optimizationproblems.
Specify the solver in the SOLVE statement
Example
SOLVE MyProblem using LP maximizing Z ;
SOLVE MyProblem using MIP maximizing Z ;
SOLVE MyProblem using NLP maximizing Z ;
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 12 / 17
Outline Features Library Tips
GAMS Solvers
GAMS integrates many solvers that can solve most optimizationproblems.
Specify the solver in the SOLVE statement
Example
SOLVE MyProblem using LP maximizing Z ;
SOLVE MyProblem using MIP maximizing Z ;
SOLVE MyProblem using NLP maximizing Z ;
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 12 / 17
Outline Features Library Tips
Model Library
GAMS has been used as a standard in optimization models in many�elds.
Models exist from experienced users that address similar problems
Textbook
Fixing Models Book
GAMS Library
GAMS Newsletter
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 13 / 17
Outline Features Library Tips
Model Library in GAMS
Models are available through the GAMS library which is directlyincluded in the IDE.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 14 / 17
Outline Features Library Tips
Use by Others
Two �les: data.gms andmymodel.gms.
Create a �t� folder (or any othernames) under the projectdirectory.
Type the content in the red boxbefore running data.gms.
When �nished running data.gmswhich includes all of data,GAMS will save all theinformation in \t\a1 where it isready to be used.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 15 / 17
Outline Features Library Tips
Use by Others
Two �les: data.gms andmymodel.gms.
Create a �t� folder (or any othernames) under the projectdirectory.
Type the content in the red boxbefore running data.gms.
When �nished running data.gmswhich includes all of data,GAMS will save all theinformation in \t\a1 where it isready to be used.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 15 / 17
Outline Features Library Tips
Use by Others
Two �les: data.gms andmymodel.gms.
Create a �t� folder (or any othernames) under the projectdirectory.
Type the content in the red boxbefore running data.gms.
When �nished running data.gmswhich includes all of data,GAMS will save all theinformation in \t\a1 where it isready to be used.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 15 / 17
Outline Features Library Tips
Use by Others
Two �les: data.gms andmymodel.gms.
Create a �t� folder (or any othernames) under the projectdirectory.
Type the content in the red boxbefore running data.gms.
When �nished running data.gmswhich includes all of data,GAMS will save all theinformation in \t\a1 where it isready to be used.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 15 / 17
Outline Features Library Tips
Use by Others
To solve the model,GAMS retrievesinformation on data thatwas saved in \t\a1.
Type the content in thered box before runningmymodel.gms.
When �nished solvingmymodel.gms, GAMS willsave all informationincluding solutions in\t\a2 where it is ready tobe used later, say, reportwriting.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 16 / 17
Outline Features Library Tips
Use by Others
To solve the model,GAMS retrievesinformation on data thatwas saved in \t\a1.
Type the content in thered box before runningmymodel.gms.
When �nished solvingmymodel.gms, GAMS willsave all informationincluding solutions in\t\a2 where it is ready tobe used later, say, reportwriting.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 16 / 17
Outline Features Library Tips
Use by Others
To solve the model,GAMS retrievesinformation on data thatwas saved in \t\a1.
Type the content in thered box before runningmymodel.gms.
When �nished solvingmymodel.gms, GAMS willsave all informationincluding solutions in\t\a2 where it is ready tobe used later, say, reportwriting.
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 16 / 17
Appendix
Heads On 3
Fix errors in Handson3error.gms and send an electronic copy of thecorrect *.gms �le via email.
Hand in a hard copy of *.lst �le (from �Solution Report� to the end).
Pei Huang | Texas A&M University | AGEC 641 Lab Session, Fall 2013 17 / 17