This repository contains a small, but helpful collction of MATLAB functions that allow reading output, writing input and transforming data to facilitate working with GAMS models.
- MATLAB (all 201x versions should work)
- GAMS (must include the GDXMRW interface, providing the
rgdx
andwgdx
functions)
-
Put file
GAMS.m
anywhere into your MATLAB path, e.g. inC:\Users\%username%\Documents\MATLAB
-
Verify that the main directory of your local GAMS installation is in the MATLAB path (e.g.
C:\GAMS\win64\24.5
, depending on your installed version). To test this, you can typehelp rgdx
within MATLAB. This should yield a help message, not an error. Detail: make sure that this directory is below the line of the directory that points to the fileGAMS.m
. You can check this by typinghelp GAMS
and check whether the output starts like this:%GAMS Interface class to call GAMS models from within Matlab % This class can be used for quick scenario generation and result % [...]
% read input data from any source or - for sake of an example -
% create it in MATLAB programmatically
cities = GAMS.set('cities', {'New York City' 'Los Angeles' 'Washington D.C.'})
population = GAMS.param('population', [8046 3884 659]*1e3, cities.uels);
% write both to a GDX file
GAMS.putGDX('input.gdx', cities, population);
$gdxin input.gdx
Set cities;
Param pop(cities);
$load cities pop
[... remaining model code ...]
% after running the model using 'gams model.gmx -gdx=output.gdx'
growth = GAMS.getGDX('output.gdx', 'growth');
% plot it
bar(growth.val);
ylabel('Annual population growth (%)');
xticklabels(growth.uels{1}); % matching labels automatically
% or export to a spreadsheet
GAMS.putXLS('growth.xlsx', growth)
A pretty verbose technical documentation is hosted on ReadTheDocs, including a short syntax primer on GAMS. The three numbered folders contain accompanying code examples that range from an independent GAMS model to one that is coupled tightly to a MATLAB data handling object, providing a scaffold for one's own models.
Copyright (C) 2011-2014, 2016 Johannes Dorfner
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/