Power of GAMS AGEC 641 Lab, Fall 2011 Mario Andres Fernandez Based on material written by Gillig and McCarl. Improved upon by many previous lab instructors. Special thanks to Yuquan “Wolfgang” Zhang Power of GAMS • Algebraic Modeling Context Changes Expandability of Models Adding Conditionals • Adding Report Writing/Self Documenting Nature • Small to Large Model Development • Model Library • Use by Others SETS Process 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/; SETS Process /MakeChair MakeTable MakeLamp Resource /PlantCap Labor Production process Chair production Table production Lamp production / Resource item used Production Capacity Labor used by process/; Context Changes The same algebraic model can be used in multiple contexts often with the same or very similar structure. TABLE ResourceUse(Resource,Process) Resource used Corn Wheat Cotton Land 1 1 1 Labor 6 4 8 ; PARAMETERS Revenue(Process) Revenues from process / Corn 109, Wheat 90, Cotton 115 / ResourceAvailable(Resource) Resource availability / Land 100, Labor 500 / ; TABLE ResourceUse(Resource,Process) Resource used MakeChair MakeTable MakeLamp PlantCap 2 3 1.1 Labor 1 2 0.5 ; PARAMETERS Revenue(Process) Revenues from process / MakeChair 11, MakeTable 10, MakeLamp 12/ ResourceAvailable(Resource) Resource availability / PlantCap 12, Labor 5 / ; Context Changes One has to revise data and their set elements for consistency; yet, other structures remain Crop production problem Expand the Scope Instead of growing 3 crops, now a farmer also wants to grow soybeans. One needs only to modify an element in PROCESS set, resource usage data, and revenues. SETS Process /Corn Wheat Cotton Soybeans Resource /Land Labor Production process Corn production Wheat production Cotton production Soybeans production / Resource item used Land used by process Labor used by process/ ; Expand the Scope (cont) Other data and the model structure remains the same TABLE ResourceUse(Resource,Process) Resource used Corn Wheat Cotton Soybeans Land 1 1 1 1 Labor 6 4 8 4 ; PARAMETERS Revenue(Process) Revenues from process production / Corn 109 Wheat 90 Cotton 115 Soybeans 95 / ResourceAvailable(Resource) Resource availability / Land 100 Labor 500 / ; Augmenting Existing Models If wheat is used for farmer consumption, it must be grown in at least 10 units (acres). Modification includes adding data on minimum land use, and equation specification on minimum land use. PARAMETERS Revenue(Process) Revenues from process production / Corn 109 Wheat 90 Cotton 115 Soybeans 95 / ResourceAvailable(Resource) Resource availability / Land 100 Labor 500 / MinLand(Process) Minimum land requirement / Corn 0 Wheat 10 Cotton 0 Soybeans 0 / ; Augmenting Existing Models (cont) Other data and the model structure remains the same EQUATIONS Objective ResourceEq(Resource) MinLandReq(Process) Maximize farm income Resource constraint Minimum land requirement; MinLandReq(Process).. ResourceUse(“Land”, Process)*Production(Process) =G= MinLand(Process); Self-Documenting Nature • Can you figure out what context the example below is from? • Can you figure out what context the example below is from? Self-Documenting Nature One can include comments in the code by • Using * in the first character position. The remaining characters in the line to be ignored but printed on the output file. • Setting off by $ONTEXT and $OFFTEXT. Small to Large Modeling • GAMS expandability allows the same model structure, calculations, and report writing to be used with SETS with few elements vs. SETS with many items. • Using a small data set allows up to examine the model structure and function easier and better. • To expand, one uses SmallStocks(Stocks) = YES; Model Library Modelers can find a number of sources of models from which they can expand or take insights. Use By Others • Create a “t” folder under the project directory • When finished running data.gms, GAMS will save all the information in \t\a1 • To solve the model, GAMS retrieves information saved in \t\a1. When finished solving mymodel.gms, GAMS will save all information including solutions in \t\a2 where it is ready to be used later Non-linear and Other Problem Forms Set declarations Parameter declarations Data Variable declarations Equation declarations Model Specifying algebraic structure Model specifications SOLVE Ex USING LP MAXIMIZING Z; Solve specifications SOLVE Ex USING MIP MAXIMIZING Z; SOLVE Ex USING NLP MAXIMIZING Z; Hands On 3 • Fix errors in Handson3error.gms and send an electronic copy of the correct *.gms file. Hand in a hard copy of *.lst file (from “Solution Report” to the end).