Download presentation
Presentation is loading. Please wait.
Published byEugene Davis Modified over 9 years ago
1
Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
2
What is GAMS?
3
Good Modeling Practices Why worry and What can be done? The effort often determines how EASILY it is to reuse or repair a model at a later time or how EASILY a colleague can work with that code. Several actions are possible: ! Use longer names or descriptions ! Include comments on nature and source of data ! Include as much raw data as possible ! Do not use * as a set specification ! Use sets to aid in readability ! Format files to improve model readability
4
Good Modeling Practices GAMS allows 31 character long names and 80 characters of explanatory text defining each of the following items: SETS PARAMETERS TABLES SCALARS VARIABLES EQUATIONS MODELS It is wise to make GAMS code to be self documenting by using descriptive character names and make sure that there is no item that goes undefined (e.g. all names are somewhat apparent and all items have explanatory text). Enter units, sources, and descriptions. Check for completeness with $ONSYMLIST.
5
$ONSYMLIST example $ONSYMLIST controls the complete listing of all symbols that have been defined and their text, including pre-defined functions and symbols, in alphabetical order grouped by symbol type. The symbol listing in the listing file. The default in GAMS is $OFFSYMLIST
6
Using Longer Names One can radically affect readability by altering the names of SET, PARAMETERS, etc. Consider the following examples: They use the same algebras but are given different names. Which model tells you more and which would you want to face 5 years later?
7
Including Comments Questions often asked when looking at a set of data are: ! Where did the data come from? ! What characteristics such as units, and year of applicability do those data possess? Such questions certainly apply to a TABLE of data in GAMS code. It is nice to go beyond the GAMS 80 character description by putting several lines of description identifying exactly what document a data set is from including sources, page numbers, table number, years, units, etc. This can be done by " Using an asterisk * in the first character position " Setting off by a $ONTEXT and $OFFTEXT " Setting off by a $EOLCOM
8
$ONTEXT $OFFTEXT Example Here is an example of using the * and the $ONTEXT $OFFTEXT block in a program. Texts or statements in between $ONTEXT $OFFTEXT are ignored by GAMS but they are printed on the output file. Every $ONTEXT must have a matching $OFFTEXT in the same file.
9
Improve Readability Format the code for readability using spacing and indents. ! Align item names, descriptions, and definitions ! Indent in sums, loops, and ifs to delineate terms ! Use blank lines to set things off ! Do not split variables between lines in equations, but rather keep them together with all their index positions
10
Improve Readability Do you prefer this? Or, …
11
Improve Readability
13
Начало на коментар Край на коментар
42
References http://www.pse.ice.bas.bg:8080/WWW_Systems_enginee rig_laboratory/Distance_learning_systmeng/Distance_sys tmeng_LT.htm
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.