GAMS Tutorial - Quick Reference
GAMS Tutorial - Quick Reference
To Begin:
• Download the GAMS Software from https://www.gams.com/download/ by first
requesting for a Demo License on the same page (scroll down the page, fill out
some information and submit).
SETS
• Also known as an index. Used within parameters, variables, and equations. Acts
as the ‘i’ in a ‘for’ loop for equations.
• Can consist of any alphanumeric combination, e.g. n1, n2, n3, bus1, bus2, bus;
• Defined as:
Set
i set of buses
/ bus1, bus2, bus3 /;
OR
i / bus1, bus2, bus3 / set of buses;
where ‘i’ is the set name, ‘buses’ is a comment, and ‘bus1, bus2, bus3’ are
elements of set
• The command alias is useful for defining another instance of the same set.
o use alias(i,j); if, within equations you will be needing to define
power from ‘i’ to all other buses in set ‘j’
• Can also define subsets
o Set Loadbus(i) /bus2/; where elements must be a subset of
set i.
PARAMETERS
• Data inputs are incorporated using the PARAMETER definitions, e.g. P and Q for
load buses, system base power, etc.
• Three entry types are possible
o SCALAR
o TABLE
GAMS TUTORIAL – Quick Reference
o PARAMETER
• Scalar - useful for constants, e.g. PI, BaseMVA
Scalar
pi /3.141592654/ you can add a comment here;
Parameter
D(i,b,t) load bus real power demand (MW)
/
1.base.t1 3.82
1.base.t2 4.01
1.base.t3 4.21
1.base.t4 4.42
/;
D(i,b,t) defines the set over which parameter exists, and / … /; defines the
data
• Table - useful for two dimensional data (to be read in an easy to read format)
TABLE Gen(i,Head) generator data
PMin PMax QMin QMax A B C
* MW MW MVAR MVAR
VARIABLES
• These are the unknown variables of the model - to be solved, e.g. voltage, angle
• In most cases they are defined over a set, e.g. voltage at each bus, with the
exception of the objective function
• Can be defined as
o Variables
o Positive Variables
o Binary Variables
GAMS TUTORIAL – Quick Reference
o Integer Variables
Examples-
P(i,j,b,t) power flow from i to j
Sedg(k,q,i,b,t) energy supply from DG (MW)
Seint(i,b,t) energy supply from intertie (MW)
Sess(i,b,t) energy supply from substation (MW)
;
EQUATIONS
• Must define equation name, then the equation
• Can be run over a set, e.g. a substation sizing equation for each possible
substation site
• Can also run over a specific element within set, but a separate equation needs to
be defined for each instance.
• Variables used in equations must be of the same set as defined in declarations or a
subset thereof.
• Defined as:
Equations
costobj objective function (minimize costs)
pflows power flow equations
VLim voltage limits
;
• Other useful items
• Summations - sum over a set, e.g. sum((i,t), p(i,t)) will
sum p over all values of i and t
• Conditionals - denoted by $ after set name, useful to restrict equations,
e.g. sum over connected buses
MODEL
Define the model by a unique name
Model DISPATCH
/ List the equations here /
;
Model PLANNING /all/;
SOLVER
Solve PLANNING using MIP minimizing Cost;
PLANNING is the name of your model (whatever name you want to give it), and
MIP is your model type (as necessary, e.g. LP for linear program, NLP for non-
linear program, MIP for mixed integer linear program.) and then the objective
function for minimization / maximization
OTHER
• Display statements
• PUT statements
GAMS TUTORIAL – Quick Reference