0% found this document useful (0 votes)
51 views

GAMS Tutorial - Quick Reference

This document provides an overview of the components of a GAMS program: [1] Sets, Parameters, Variables, Equations, Models, and Solver instructions are the main components. [2] It describes how to define Sets, Parameters, Variables, and Equations - including example code. [3] The last section briefly outlines other GAMS features like Display statements, comments, and text blocks.

Uploaded by

Namira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

GAMS Tutorial - Quick Reference

This document provides an overview of the components of a GAMS program: [1] Sets, Parameters, Variables, Equations, Models, and Solver instructions are the main components. [2] It describes how to define Sets, Parameters, Variables, and Equations - including example code. [3] The last section briefly outlines other GAMS features like Display statements, comments, and text blocks.

Uploaded by

Namira
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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

• Useful information on GAMS programming and tutorials are available at:


https://www.gams.com/latest/docs/

GAMS PROGRAM COMPONENTS


• SET (index) definition
• PARAMETERS and SCALARS
• VARIABLE definitions
• INITIAL CONDITIONS (if applicable)
• EQUATION definition
• MODEL definition
• SOLVE instructions
• DISPLAY instructions

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 - useful for multi-dimensional index dependent parameters, e.g. bus


loads for a given time
o Can assign a single value to each set combination, e.g. load at bus1 during
year1, load at bus2 during year2, load at bus2 during year1, load at bus3
during year3, etc.
o Indices are separated by period, value by space.

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

1 100 500 -20 300 1.0 8.50 5


2 50 250 -20 150 3.4 25.50 9
4 100
6 100
;

o Need to define a Header set


o Each data column must be right justified

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

• $Ontext and $Offtext


• Comments are denoted by *

You might also like