MATLAB and GAMS: Interfacing Optimization and Visualization
Software
Abstract:
This document briefly describes a link between GAMS and MATLAB, both
of which the user is assumed to have already.
The software gives MATLAB users the ability to use all the
optimization capabilities of GAMS, and allows visualization of GAMS
models directly within MATLAB.
The most recent version can be downloaded directly from
http://www.cs.wisc.edu/~ferris/matlab.html
Current documentation
(for version 008) is available only as a pdf file.
Note that this version includes the ability to do execution time
over-writing of parameters, and uses a slightly different scheme for
passing parameters from MATLAB to GAMS. It is only available for PC,
linux and solaris boxes.
Original version of the documentation:
Mathematical Programming Technical Report 98-19, November 1998.
Two alternatives for interfacing MATLAB and GAMS
There are two possible ways to interface between Matlab and GAMS.
The first mechanism is provided as a download below and allows you to pass
data to and from a gams program via parameters to a "gams mex interface".
This can be invoked for example as:
In this setting "qp.gms" is a GAMS file that contains a few extra lines
to facilitate the read-in of Q and the write-out of the solution x.
Examples are given in the documentation found above on this page.
The second mechanism is to use the GDXMRW facilities that are available
and documented as
GDXMRW download.
Essentially two mex procedures are provided that read and write a gdx file.
A GAMS program can then use built in GAMS procedures to read and write these
same gdx files. The invocation in GAMS would be something like:
- qsp = full2sp(Q,'par');
- writegdx('q.gdx','par','Q',qsp);
- system('gams qp');
- xsp = readgdx('x.gdx','x');
- x = sp2full(xsp,'par');
The writegdx call creates a file q.gdx containing the data that is in the matlab matrix Q. The file qp.gms would read this in using "$gdxin" or execute_load. More details can be found at
GDX documentation.
The readgdx routine reads the file x.gdx that was created by the qp.gms file
into a matlab matrix x. Some helper utilities sp2full and full2sp are
provided that help manipulate the input and output data structures (that are
basically in i,j,val format) to have the correct (dense) matlab matrix
structure.
Download and installation instructions
All the files needed to
download
this link are available on
the ftp site of the Computer Sciences Department at the University of Wisconsin.
Several examples of the use of this link are found in this "zip" file,
along with instructions for installation. It is suggested that the
archive file "matgams.zip" is unzipped ("unzip matgams.zip") in a new
directory.
If you download and use this software, please acknowledge use by
citing the above technical report in your work.
Previously used versions are also still downloadable but without any
support provided.
-
Current version should work for solaris (64), windows (32 and 64) and
lnx (32 and 64).
-
2007: This worked for 32 and some 64 bit versions of Matlab (7.3).
-
2005: This worked for 32 bit versions of Matlab (7.0, 7.1 and 7.2).
-
2003: This worked for
versions of MATLAB prior to version 7, and is no longer supported. If
you wish to use this, you should you the original documentation as
provided above.
For windows users, the above zip file contains the dll for
version 6.5 of Matlab. It seems the dll is not backwards
compatible.
For users of version 6 to 6.49, a dll that appears
to work can be found in this
zip archive.
A version 5 matlab "gams.dll" can be found in this
zip archive. This comes as is, and no bug fixing or support
will be provided.
To use these versions, just unzip the 2003 archive and use the resulting
gams.dll in place of the version 6.5 dll that comes with that
distribution.
Example output
Sample output from a tomotherapy example can be found in
PDF form.
These pictures are associated with a project described in:
David M. Shepard, Michael C. Ferris, Gustavo Olivera and Thomas R. Mackie
Optimizing the Delivery of Radiation to Cancer Patients.
Mathematical Programming Technical Report 98-07, June 1998.
This file is large since it contains a bunch of postscript figures.
Compressed versions are also available for download:
UNIX compress,
ZIP archive.