Home

GAMS for Solving Mathematical Programming Problems

image

Contents

1. time you wish to change the file storage directory Summary steps for using GAMS cont 4 QN Define a project name and location Put it in a directory you want to use Choose a suitable subdirectory and create a subdirectory with the name of the project In turn call your project by that name so that it is called project gpr where gpr stands for GAMS project Create or open an existing file of GAMS instructions Prepare the file so you think it is ready for execution Run the file with GAMS by clicking on the run button Open and navigate around the output A GAMS Program INPUTS SETS declaration assignment of members DATA Parameters Tables Scalars declaration assignment of values A GAMS program cont VARIABLES declaration assignment of type Assignment of bounds and or initial values OPTIONAL A GAMS program cont EQUATIONS declaration definition MODEL and SOLVE Statements DISPLAY Statement OPTIONAL Equations in GAMS Two types of equations in GAMS 1 Define parameters 2 Model equations may be inequalities Not indexed Objective is a single value Z sum a 1 x 1 Indexed Examples RG sum c j x 1 R item sum city c city x 1tem city Example problem Minimize transportation costs min KAS i j SL x Sa supplylimit at plant i j 2 x gt b satisfy demand at market j See http www gams com docs ex
2. 2 031 034 041 VIS For Cplex 10 0 Cplex 10 0 1 GAMS Link 31 Presolve found the problem infeasible or unbounded Rerunning with presolve turned off Dual infeasible or unbounded Switching to primal to aid diagnosis Model has an unbounded ray ERRORS WARNINGS IN VARIABLE x 3 1 error s 1 Unbounded variable x A 121 1 d start 430 L C Documents and IE gamside amp Microsoft PowerPoin 2 sog S OR 4 07PM E gamside C Documents and Settings kooten UVICMy Documents Classes Programming GAMS Programs sclasscexamples us 2 181 xl Wu File Edit Search Windows Utilities Help l x Compilation ERRORS WARNINGS IN VARIABLE x 3 Equation Listing St 1 error s 1 Unbounded variable Equation Column Listing 5 LOWER LEVEL UPPER MARGINAL Column Model Statistics SI EQU OBJ 1 000 Solution Repot St SolEQU OBJ Objective function SolVAR EQU CON Constraint LOWER LEVEL UPPER MARGINAL l INF 10 000 10 000 2 500 2 INF 3 000 3 000 0 500 LOWER LEVEL UPPER MARGINAL VAR z INF 26 500 INF Z objective value M R x activities start 430 L C Documents and G5 gamside 5 Microsoft PowerPoin 2 esd S ON 4 11PM HH gamside C Documents and Settings kooten U IC My Documents Classes Programming GAMS Programs class examples gs i8 x Me File Edit Search Windows Utilities Help 18 x
3. mid size LPs and small NLPs but not larger models but in this case they cannot even solve a small LP e GAMS is a preferred platform because of its power to solve even the smallest and extremely large problems with millions of constraints m
4. this example in GAMS and Excel Max Z 3 X 2x 0 5x s t X LX kt Kaz 10 Xi Ka amp s3 Xi Ka 2 0 Three equations x is not constrained free The GAMS setup and solution are provided on the next slides 26 GAMS Model Title McCarl amp Spreen Chapter 3 Example SETS i index 1 1 3 j index2 1 2 PARAMETER b j rhs constraint values TRO D SUE TABLE a j i Table of technical constraints PARAMETER c i coefficients in obj TENES 2E S Ry VARIABLES Z objective value X 1 activities EQUATIONS OBJ Objective function CONG Constraint 9 OBJ z E sum c 1 x 1 CONQ sum i a J 1 x 1 L bq MODEL McSpreen all lo 1 0 x lo 2 0 SOLVE McSpreen using LP maximizing z E gamside C Documents and Settings kooten UVICVMy Documents Classes Programming EES xi e File Edit Search Windows Utilities Help D Dre OU A IV jrobIlelIm 8 x BEE McSreen Chap3 example gms McSteen_Chap3_example lst Compilation SOLVE SUMMARY Equation Listing St Equation MODEL McSpreen OBJECTIVE z Column Listing 5 TYPE LP DIRECTION MAXIMIZE Column SOLVER CPLEX FROM LINE 48 Model Statistics S Solution Report St SOLVER STATUS 1 NORMAL COMPLETION SolEQU MODEL STATUS 3 UNBOUNDED SolVAR OBJECTIVE VALUE 26 5000 RESOURCE USAGE LIMIT 0 015 1000 000 ITERATION COUNT LIMIT 2 10000 GAMS Cplex Apr 21 2006 WIN CP CP 22
5. Compilation Equation Listing S Equation Column Listing Sif Column Model Statistics SI z Solution Repot St SolEQU SolvAR Loco o o EXECUTION TIME V R z objective value VAR x activities LOWER LEVEL 6 500 3 500 INF REPORT SUMMARY LOWER LEVEL UPPER MARGINAL INF 26 500 INF Notice that GAMS provides a solution UPPER MARGINAL INF INF INF 2 000 UNBND NONOPT 0 INFEASIBLE 1 UNBOUNDED UNBND 0 000 SECONDS 2 Mh WINZZZ 145 Apr Z1 s pap d start e 30 L C Documents and us gamside amp Microsoft PowerPoin 2 esdi WP 412m Now consider the solution in Excel Consider both the PRIMAL and the DUAL PRIMAL Max 2 3x 2x 0 5 x St DUAL Min S t X X 4 x3 lt 10 X4 Xj lt 3 XX 20 R 10y 3 yz Y t Yo 23 Yi Ka SE yi 0 5 yi y22 0 Any attempt to solve either the Primal or the Dual problem within Excel resulted in The SET CELL values do not converge Attempts to solve it as a NLP rather than LP did not help in this regard Excel does not appear able to solve this simple LP Actually since the problem is unbounded it gives infinite values in the cells that are to be changed Recall Unbounded PRIMAL means an infeasible DUAL and vice versa Final Comments Excel does not appear to be a reliable solver e Neither can Matlab solve the above problem Matlab and Excel are generally okay for
6. GAMS for Solving Mathematical Programming Problems G Cornelis van Kooten REPA Group University of Victoria Powerful software for solving LP QP NLP IP MIP MINLP and CGE models Easy to use when setting up large problems much easier than Excel Matlab etc More powerful than Excel Matlab Maple and other packages for solving very large linear and non linear programs Enables researcher to access a variety of powerful solvers using the same written code Solvers include Minos CPLEX ConOpt Lindo XA and any other commercial and non commercial solver that 1s available Excellent documentation e g McCarl s User Manual at www gams com Numerous sample programs available in model library at http www gams com modlib modlib htm GAMSIDE Windows graphical interface to run GAMS GAMS General Algebraic Modeling System plus m IDE Integrated Development Environment Summary steps for using GAMS 1 Install GAMS amp IDE on your computer making an icon 2 Open the IDE through the icon 3 Create a project by going to the file selection in the upper left corner What is a project GAMSIDE employs a Project file 1 to identify a location where all saved files are to be placed to place files elsewhere use save as dialogue and where GAMS looks for files when executing and 2 to which project files program option files and output files are saved Recommended you define a new project every
7. ample htm SETS 1 plants Seattle San Diego market NY Chicago Kancity PARAMETERS a 1 capacity at plant 1 Seattle 350 san Diego 600 b demand at market j NY 325 Chicago 300 Kancity 275 TABLE dQ j distance in 000s miles NY Chicago Kancity Seattle 23 I 1 8 San Diego 25 1 8 1 4 SCALAR f freight cost in per 000s miles 8 PARAMETER c ij transport cost in k per unit c i j f d i j 1000 VARIABLES x ij shipment quantities 7 total costs in k Positive variable n EQUATIONS supply i supply limit at plant 1 demand j satisfy demand at market J cost objective function is to minimize cost cost z E sum i j c i J x i supply i sum j x i j L a i demand j sum i x ij G DUT MODEL transport all SOLVE transport using LP minimizing z DISPLAY x l x m Specify upper and lower bounds in lieu of constraints x up 50 Same as an x lt 50 constraint y lo 2 20 y 20 constraint Note reference to index 2 cows up 3 200 x up 3 cows lt 200 50 constraint Report Writing in GAMS DISPLAY can be used after SOLVE statement in GAMS to print out calculation results 1 variable name followed by L value of solution for that variable 2 variable name followed by M reduced cost associated with that variable 3 equation name followed by L left hand side value of equation 4 equat
8. de Oninclude and Offinclude turn the echo print of the include file in the LST file on and off default is on Example from grid model PARAMETER inflow h hourly inflow of water m3 per s Include inflow PARAMETER demand h hourly demand for electricity Include demand2003 PARAMETER wpower h hourly wind power MW Include wpowers Data are found in inflow gms demand2003 gms and Wpowers gms 21 Comma Separated Value CSV Files Spreadsheets and other programs e g Matlab can read and write CSV files o Commas separate fields o Text items can be in quotes Sondelim tells GAMS that entries which follow are in CSV format offdelim tells GAMS to turn off use of CSV format Examples using CSV format SETS K indexk K1 K3 J indexj J1 J2 J3 TABLE CSVEX1 K J Data in csv Format Sondelim dummy J1 J2 J3 Note use of dummy as K1 16 34 12 the placeholder in a table K2 3 11 5 see also below K3 52 16 4 Offdelim 23 Alternatively an external file can contain the table SETS K index k K1 K3 J index J J1 J3 TABLE CSVEX2 K J data 1n csv format Sondelim Include externalcsvdatafile Soffdelim 24 The file externalcsvdatafile gms contains dummy J1 J2 J3 Kl 16 34 12 K2 3 11 5 K3 52 16 4 Note dummy is needed in the csv format to use up the space over the set elements defining the table rows in the first row first column Consider
9. ion name followed by M shadow price dual variable associated with equation Dual slack variables RHS of equation associated L value Example displays level and marginal values of X and shadow price of CONI DISPLAY X L X M CONI M PUT option and Report Writing Define output file name and identify where output 1s to be written If no path is given default is project subdirectory and file 1s file name with put extension file Output D work output txt Set page width Output pw 5000 Number of decimal places in output file Output nd 0 Solve modelname using LP maximizing z Now comes the writing component A comma is needed to create a comma separated value file and a 1s used to indicate a carriage return PUT option cont put Output put Solver status modelname solvestat put Model status modelname modelstat put Objective value z put Period Price Ouantity loop t put t tl price l t quan l t put putclose Output Note how the index t needs to be identified 1n the loop with a tl as opposed to only 1 An example of how to write output is provided in the next two slides for an electricity grid model 3 gamside C Documents and Settingskooten U IC My Documents Energy Alberta paper Alberta grid gpr C Documents aust Es Wes File Edit Search Windows Utilities Help 8 x s y m5 we Ay OUntpRt writing secti
10. on emissions l h sum p total l p h emfactor p maxefficiencyip 0 2778 cost l p h fuelcost l p h cOMcost p peakcosttotal l sum h cost l peak h peakcap l fixedcost peak 1e6 total all l h sum p total l p h file result result txt result pw 10000 put result Alberta Electricity Grid Model put result Run on system date using source file system ifile put Model status energy modelstat put Solver status energy solvestat put Objective z l Peak capacity peakcap l Fixed cost of wind fixedcost wind Wind capacity capacity wind put mon POWER OUTPUT BY SOURCE MW rr wl wl wl my my mn yn COST S PER My T nm nm m UPPER RESERVOIR t e ii d Be LOWER RESERVOIR mt put Hour m Total m Coal m Gas H Peak n Wind m w 4 b z S82d nssmi 3 d start euo L C Docu 3 Microsof as gamside 2 D EI S 999 di Gg 9 37AM 3 gamside C Documents and Settingskooten U IC My Documents Energy Alberta paper Alberta grid gpr C Documents aus Es iw File Edi Search Windows Utilities Help Alberta model2 gms put Objective z l Fixed cost of wind fixedcost wind Wind capacity capacity wind POWER OUTPUT BY SOURCE MWj COST ai PER My m rr g Wi i Wi e rr m rr T rr LOWER RESERVOIR Hour rr Ma rr Total rr m rr Coal rr s rr H
11. ydro rr m rr Demand load m rr put put Wind mor M rr Hydro mor Wi Yo lume mm e n Wi Ontf low Inflow COZ Output Volume f put h tl total all l h total l dgas h total l wind h D H cost l coal h cost l peak h wer cost 1l loop h mor cost l hydro h volume li h UU reflov l h emissions 1 th fs inflow h volumez li ih put putclose 4 mede IEEE start eu 0 L C Docu 5 Microsof 25 gamside e D EI z m or ee total l coal h SU total l total l hydro h cost l dgas h wind h Peak capacity peakcap l m m m v mv m wv ov m m d D d UPPER RESERVOIR mor Gas mom Peak net Wind mum Coal rt Gas d a Peak T EU PumpF low s Wi mor mor demand h m or peak h mor D mor d outflow l h 999 idi g 3 36am Calling external Files from within GAMS m Include externalfilename where externalfilename can include full path or just file name if located in the current working directory as declared in GAMS project The file to include consists of GAMS code m The master GAMS file treats the statements in the include file as a continuation of the program code precisely at the SInclude point m Other commands for including external files are Batinclude Libinclude Sysinclu

Download Pdf Manuals

image

Related Search

Related Contents

Samsung GT-I9506 Priručnik za korisnike    listbib-doc.  Manuel d`utilisation  vol.7 - JET 一般財団法人 電気安全環境研究所  DENVER_MT-758_MPEG4,_English_IB_  

Copyright © All rights reserved.
Failed to retrieve file