intro1.pdf

(227 KB) Pobierz
Welcome to GAMS 1
Jesper Jensen
TECA TRAINING ApS
jensen@tecatraining.dk
This version: September 2006
1 This material is the copyrighted intellectual property of Jesper Jensen. Written permission must be
obtained from the author before any use of the material involving fees or charges, however indirect, e.g.,
course fees.
924639061.001.png
Getting started with GAMS
Welcome to the programming language GAMS. The purpose of this chapter is to get you started
using GAMS on your own computer. We will assume that you know how to use standard
programs on a computer, e.g. a word processor such as Microsoft Word, but experience with
GAMS or programming is not necessary.
The chapter begins with an introduction to the key features of GAMS. We will then show how
you install GAMS on your PC, and how you work with GAMS in practice. By the end of the
chapter, you will have GAMS installed on your own PC and you will be able to run a small
existing GAMS program. This gives you a good starting point for proceeding with the
development of economic equilibrium models in GAMS.
If you have already used GAMS, you may find that you are familiar with most of the material in
this chapter. You can then either quickly browse the chapter or simply skip it.
We will focus on the aspects of GAMS relevant to modelers interested in economic general
equilibrium models. GAMS can be used for many, many other types of applications, but we
deliberately skip these details here. Also, this introduction aims to help beginners and therefore
ignores details that expert modelers may find useful or important.
Key features of GAMS
GAMS stands for G eneral A lgebraic M odeling S ystem. Basically, it is a language that allows you
to develop and work with complicated models. The language does require an initial investment of
time before you become familiar with the system, but the returns could be large and you will
quickly be able to work with your own advanced economic models. You do not have to be a
specialist in software design, operations research, or mathematics. All it takes is an interest in
working with a computer, a solid background in applied economic theory and a commitment to
invest time in learning the language.
Here are some of the advantages of using GAMS for economic equilibrium models:
A key feature of GAMS is access to a large set of existing solution algorithms. That is, as a
modeler you should only focus on the formulation of a good model and then leave it to state-of-
the-art solvers to solve it. This also implies that you can try different solvers without changing the
model representation.
Another feature is independence between model formulation and the model data. That is, GAMS
allows you to formulate your model without direct reference to a specific data set and you can
therefore use the same model code with different data sets or different aggregations of the same
data set. Your model may increase dramatically in size with a new data set, but the model
formulation remains the same.
Learning GAMS also provides you with the advantage of any other language: It opens a whole
new world and allows you to talk to others facing similar challenges. The options are many: You
can discuss model code and ask for help, you can read your colleagues’ work and you can benefit
from ideas embodied in the large set of pre-existing models. 2
2 The GAMS installation procedure automatically installs a model library with GAMS models. Also, many
research projects based on GAMS models have their own web sites where you can download a copy of
their code.
2
The model representation in GAMS closely follows the way you would write the model using
mathematical symbols. Not only does this help you and your colleagues to remember and
understand what your model is about. It also allows you to change code in both a simple and safe
manner. If you have experiences with programming, I am sure you value a language that reduces
the risks of errors and, when errors occur, help you detect and eliminate them.
Flexibility with respect to both computer type and user interface implies that you can use GAMS
in a way that suits your habits best. We will focus on GAMS installed on a PC, but the same code
can also be run on a large mainframe computer. Also, you can edit your code in one editor, for
example, the built-in GAMS-IDE editor, and later switch to another editor, e.g., Emacs (on
computers running Unix) or Epsilon (an advanced Emacs-style programming editor for PCs
running Windows and Linux).
A final feature of GAMS is that it can be used together with many other programs. For example,
many find Microsoft Excel convenient for entering data and for reporting results in nicely
formatted tables and figures. This can easily be done with the built-in GDX-utility (GDX stands
for G AMS D ata E x change). You can also interface with other programs, such as the plotting
program GNUPlot, by using utilities developed and contributed by other GAMS modelers. 3
The choice is yours, but I strongly believe in the advantages GAMS offers relative to other
alternatives such as Microsoft Excel, GEMPACK and Gauss. In any case, I recommend that you
choose a programming language that allows you to focus on model development and economic
analysis, unless you are really interested in subtle details about solution algorithms. Also, I
recommend that you choose a language that both reduces the scope of errors and help you
identify and learn from the errors you, like anyone else, will make.
Installation of GAMS
GAMS comes with an easy-to-use installation procedure. The procedure installs the full GAMS
system and everything is included in one file with the name setup.exe . 4
Perhaps you already have a copy of GAMS on a distribution CD. In this case, the setup.exe
file can be found in the \systems\win directory.
If you do not have a distribution CD, you can download the most recent GAMS system from the
GAMS home page www.gams.com under “Download Current GAMS System”. If you enter your
Email address and name, GAMS automatically sends you an Email with a link to the
setup.exe file and a user name and a password you will need to access the file. Follow the
link, enter the provided user name and password and save the setup.exe file on your PC, for
example on your desktop.
Now you should be ready to install the program. Simply locate and run (double-click) the
setup.exe file, for example using the Windows Explorer. 5 The setup program first asks you
3 More details can be found at www.gams.com under ”Contributed Software”.
4 Any reasonably recent PC will be large and fast enough to run most models. Before you install GAMS,
make sure that you have a couple of hundred megabytes of free space on the hard disk for the GAMS
system and for the models and data you are going to work on.
5 You need to have the rights to install programs on your PC. Contact your system administrator if the
computer prevents you from installing GAMS.
3
 
for the name and the location of the directory in which GAMS is installed. If GAMS is not
already installed on your computer, you can simply accept the default choice. If GAMS is already
installed and you want to keep two different versions of GAMS, choose a different name and
location for the new version of GAMS.
The installation procedure will also ask you for a license file. If you do not have a license file,
choose No . You can always copy a license file later without having to reinstall the entire system.
Even without a license file, you can use GAMS but only to solve small models. 6
If you have a license file that you want to be part of your GAMS system, answer Yes . Then
browse your files and find the file you want to use. The file name is always gamslice.txt . If
you have bought a GAMS system and have received a floppy disk with a license file, locate your
floppy disk drive. If you have a license file on a CD, locate the CD drive and then the directory
with the license file. Once found, open the file and the installation program will copy it to the
GAMS system.
Choose Finish at the end to complete the installation of your GAMS system. This should
launch the GAMS-IDE interface and your screen should show the following: 7
6 This is also called demonstration mode. If you have a license file but it has expired GAMS will also work
in demonstration mode only.
7 IDE stands for I ntegrated D evelopment E nvironment.
4
924639061.002.png
If GAMS-IDE does not start automatically, open GAMS-IDE through the icon on your desktop or
via the program menu.
Working with GAMS
You are now ready to use GAMS. To work with GAMS, first you need to choose an editor to
work with your code. You use the editor to enter your GAMS code and to save a file with a name
of your choice and the extension GMS . The GMS file, also called the input file, is then submitted to
the GAMS system, which compiles and executes the GAMS code. GAMS creates an output file
with the name you chose for the input file followed by the extension LST . This latter file is
sometimes called the listing file.
There is generally two ways to do this. Many beginners choose to use GAMS-IDE editor, the
Windows-style editor that comes with the GAMS system. When you enter code in GAMS-IDE,
it automatically saves a file with the extension GMS when you submit the code to the GAMS
system. GAMS-IDE also automatically opens the resulting listing file.
The other way is to use a programming editor of your choice. Some would call this the traditional
way as this was the only way to use GAMS before GAMS-IDE was developed. Again, you use
the editor to enter your GAMS code. After saving the input file, you submit your GAMS code via
a DOS-prompt window. 8 You then return to your editor and open the listing file that GAMS has
created. 9
The GAMS-IDE editor
Introduction
Here we will focus on the GAMS-IDE editor. Before we introduce the editor however, we will
first do a bit of housekeeping. First, create a project directory on your hard disk. You can do this
in Windows Explorer. For example, add a directory at the root of your hard disk (C:\) called
Modeling . Within this directory you can then add subdirectories each time you want to work on
a new model. This way you know exactly where your model files are and you separate your
GAMS work from the GAMS system files and all other files stored on your computer.
Second, develop a backup system. And use it. For example, save your GAMS code under a new
name every time you have introduced major changes. If there are errors in your new code, you
can always get back to your starting point by opening the previous file. Also, make sure that you
backup your files on an external media so that you can recover your work in case your computer
breaks down or gets stolen. In practice this will also help you clean up your modeling directories
as you probably want to delete the sometimes large listing files and any temporary files before
you backup one or more modeling directories.
8 GAMS must be added to the system path before you can call GAMS from a DOS-prompt. In Windows
XP, choose System on the Control Panel and then Environment Variables on the Advanced tab.
This opens a window with system variables at the bottom. Select Path , click Edit and add first a ; and
then the location of the GAMS system directory to the end of the value field (e.g.: C:\Program
Files\GAMS22.0 ).
9 This may sound more cumbersome, but once you have the keyboard shortcuts on your fingertips, you
cannot tell the difference and you can furthermore enjoy the features offered by your personal choice of
editor. For example, Epsilon has more advanced editing features and has more options for customization
than GAMS-IDE.
5
Zgłoś jeśli naruszono regulamin