introduction to gams: good modeling practices prof. boyan bonev ivanov, ph.d. email:...

42
Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: [email protected] Institute of Chemical Engineering-BAS

Upload: eugene-davis

Post on 27-Dec-2015

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS

Introduction to GAMS:Good modeling practices

Prof. Boyan Bonev Ivanov, Ph.D.

Email: [email protected]

Institute of Chemical Engineering-BAS

Page 2: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS

What is GAMS?

Page 3: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS

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

Page 4: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS

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.

Page 5: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS

$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

Page 6: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS

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?

Page 7: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS

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

Page 8: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS

$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.

Page 9: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS

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

Page 10: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS

Improve Readability

Do you prefer this?

Or, …

Page 11: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS

Improve Readability

Page 12: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS

Improve Readability

Page 13: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS

Improve Readability

Начало на коментар

Край на коментар

Page 14: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 15: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 16: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 17: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 18: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 19: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 20: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 21: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 22: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 23: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 24: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 25: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 26: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 27: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 28: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 29: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 30: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 31: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 32: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 33: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 34: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 35: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 36: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 37: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 38: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 39: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 40: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS
Page 41: Introduction to GAMS: Good modeling practices Prof. Boyan Bonev Ivanov, Ph.D. Email: bivanov@bas.bgbivanov@bas.bg Institute of Chemical Engineering-BAS