Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: [email protected] Institute of Chemical Engineering-BAS
Dec 27, 2015
Introduction to GAMS:Good modeling practices
Prof. Boyan Bonev Ivanov, Ph.D.
Email: [email protected]
Institute of Chemical Engineering-BAS
What is GAMS?
Good Modeling Practices
Why worry and What can be done?
The effort often determines how EASILY it is to reuse or repair amodel at a later time or how EASILY a colleague can work with thatcode.
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
Good Modeling Practices
GAMS allows 31 character long names and 80 characters ofexplanatory text defining each of the following items:
SETS PARAMETERS TABLESSCALARS VARIABLES EQUATIONSMODELS
It is wise to make GAMS code to be self documenting by usingdescriptive character names and make sure that there is no itemthat goes undefined (e.g. all names are somewhat apparent and allitems have explanatory text). Enter units, sources, anddescriptions. Check for completeness with $ONSYMLIST.
$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 inthe listing file. Thedefault in GAMS is$OFFSYMLIST
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?
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 ofapplicability 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 byputting several lines of description identifying exactly whatdocument 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
$ONTEXT $OFFTEXT Example
Here is an example ofusing the * and the$ONTEXT $OFFTEXTblock in a program.
Texts or statementsin between $ONTEXT$OFFTEXT areignored by GAMS butthey are printed onthe output file.
Every $ONTEXT musthave a matching$OFFTEXT in thesame file.
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, butrather keep them together with all their index positions
Improve Readability
Do you prefer this?
Or, …
Improve Readability
Improve Readability
Improve Readability
Начало на коментар
Край на коментар
References
http://www.pse.ice.bas.bg:8080/WWW_Systems_engineerig_laboratory/Distance_learning_systmeng/Distance_systmeng_LT.htm