Introduction to GAMS: Formulation of a general problem

29
Introduction to GAMS: Formulation of a general problem Prof. Boyan Bonev Ivanov, Ph.D. Email: [email protected] Institute of Chemical Engineering-BAS

description

Introduction to GAMS: Formulation of a general problem. Prof. Boyan Bonev Ivanov, Ph.D. Email: [email protected] Institute of Chemical Engineering-BAS. What is GAMS?. Formulation of a General Problem. Formulation of a General Problem. Formulation of a General Problem. STEPS - PowerPoint PPT Presentation

Transcript of Introduction to GAMS: Formulation of a general problem

Page 1: Introduction to GAMS: Formulation of a general problem

Introduction to GAMS:Formulation of a general problem

Prof. Boyan Bonev Ivanov, Ph.D.

Email: [email protected]

Institute of Chemical Engineering-BAS

Page 2: Introduction to GAMS: Formulation of a general problem

What is GAMS?

Page 3: Introduction to GAMS: Formulation of a general problem

Formulation of a General Problem

Page 4: Introduction to GAMS: Formulation of a general problem

Formulation of a General Problem

Page 5: Introduction to GAMS: Formulation of a general problem

Formulation of a General Problem

STEPS1. SET definitions (crop)2. Data entry (Ccrop, acrop,resource,bresource)3. Variable specifications4. Equation specificationsa. declarationb. algebraic structure5. Model statement6. Solve statement

Page 6: Introduction to GAMS: Formulation of a general problem

Set Definition

In algebraic modeling, we commonly have subscripts.In GAMS, the corresponding items are sets. A set definition has severalpotential parts.

SET ItemName optional explanatory text for item/ element1 optional explanatory text for element ,element2 optional explanatory text for element / ;

S={a,b,c} Set S /a,b,c/In general, the syntax in GAMS for simple sets is as follows:

set set_name ["text"] [/element ["text"] {,element ["text"]} /]{,set_name ["text"] [/element ["text"] {,element ["text"]} /] ;

Page 7: Introduction to GAMS: Formulation of a general problem

Set Definition

set cq "nutrients" / N, P2O5 / ;

set cq "nutrients" / N P2O5 / ;

set cq "nutrients" / N “Text 1” P2O5 “Text 2” / ;

set cq "nutrients“ / N “Text 1” P2O5 “Text 2” / ;

Page 8: Introduction to GAMS: Formulation of a general problem

Set Definition

Set f "final products" /yncrude "refined crude (million barrels)" lpg "liquified petroleum gas(million barrels)" ammonia "ammonia (million tons)" coke "coke (million tons)" sulfur "sulfur (million tons)" /;

set t "time“ /1991 * 2000 /;

setss "Sector" / manuf agri services government /r "regions" / north eastcoast midwest sunbelt / ;

Page 9: Introduction to GAMS: Formulation of a general problem

Set Definition

Defined set names Explanatory Text

Element names

Page 10: Introduction to GAMS: Formulation of a general problem

Data Entry

Data are entered via four different types of GAMScommands

1) Scalar – for items that are not set dependent

2) Parameters – for items that are vectors (can be multidimensional)

3) Tables – for items with 2 or more dimensions

4) Parameters – direct assignment

Page 11: Introduction to GAMS: Formulation of a general problem

Data Entry – SCALAR command

Scalar commands:

In general, the syntax in GAMS for a scalar declaration is:

scalar(s) scalar_name [text] [/signed_num/] { scalar_name [text] [/signed_num/]} ;

Scalars rho "discount rate" / .15 / irr "internal rate of return" life "financial lifetime of productive units" /20/;

Basic format:

SCALAR ItemName optional text / value / ;

Example:

SCALAR LandAvailable Total Land / 100 / ;

Page 12: Introduction to GAMS: Formulation of a general problem

Data Entry – PARAMETER command

In general, the syntax in GAMS for a parameter declaration is:parameter(s) param_name [text] [/ element [=] signed_num {,element [=] signed num} /] {,param_name [text] [/ element [=] signed_num {,element [=] signed num} /]} ;

Basic format:

PARAMETER ItemName(Set) optional text / element1 value , element2 value value2 / ;

Example:

PARAMETERRevenue(Crop) Revenues from crop production / Corn 109 Wheat 90 Cotton 115 /ResourceAvailable (Resource) Resource availability / Land 100 Labor 500 / ;

Page 13: Introduction to GAMS: Formulation of a general problem

Data Entry – PARAMETER command

Set i "steel plants“ / hylsa "monterrey" hylsap "puebla" / j "markets" / mexico-df, monterrey, guadalaja / ;

parameter dd(j) “distribution of demand” / mexico-df 55, guadalaja 15 / ;

Parameter a(i) / seattle = 350, san-diego = 600 / b(i) / seattle 2000, san-diego 4500 / ;

Set i "steel plants“ / seattle "monterrey" san-diego "puebla" /

Page 14: Introduction to GAMS: Formulation of a general problem

Data Entry – TABLE command

In general, the syntax in GAMS for a table declaration is:

table table_name [text] EOL element { element } element signed_num { signed_num} EOL {element signed_num { signed_num} EOL} ;

sets i "plants" / inchon,ulsan,yosu / m "productive units" atmos-dist "atmospheric distillation unit" steam-cr "steam cracker" aromatics "aromatics unit" hydrodeal "hydrodealkylator" / ;

Table ka(m,i) "initial cap. of productive units (100 tons per yr)" inchon ulsan yosuatmos-dist 3702 12910 9875steam-cr 517 1207aromatics 181 148hydrodeal 180 ;

Page 15: Introduction to GAMS: Formulation of a general problem

Data Entry – TABLE command

Basic format:TABLE ItemName(set1dep,set2dep) optional text set2elem1 set2elem2Set1element1 value11 value12

Set1element2 value12 value22 ;

Example:

Elements fromCrop set (2nd set)

Elements from Resource set (1st set)

Page 16: Introduction to GAMS: Formulation of a general problem

Data Entry – Direct assignment

Basic format:

PARAMETER ItemName(set1dep,set2dep) optional text ; ItemName(set1dep,set2dep) = some expression ;

Example:

Page 17: Introduction to GAMS: Formulation of a general problem

Summation Digression

Page 18: Introduction to GAMS: Formulation of a general problem

Formulation – Variable Declarations

Basic format:

VARIABLE VarName1(setdependency) optional text VarName2(setdependency) optional text … ;

Example:

Page 19: Introduction to GAMS: Formulation of a general problem

Formulation – Variable Declarations

variables k(t) capital stock (trillion rupees) c(t) consumption (trillion rupees per year) i(t) investment (trillion rupees per year) utility utility measure ;

VARIABLE TYPES

Page 20: Introduction to GAMS: Formulation of a general problem

Formulation – Variable Declarations

variables k(t) capital stock (trillion rupees) c(t) consumption (trillion rupees per year) i(t) investment (trillion rupees per year) utility utility measure ;

positive variables k(t) capital stock (trillion rupees) c(t) consumption (trillion rupees per year) ;

negative variables i(t) investment (trillion rupees per year);

binary variables utility utility measure ;

Page 21: Introduction to GAMS: Formulation of a general problem

EQUATION DECLARATIONS

THE SYNTAX

Equation[s] eqn_name text {, eqn_name} ;

AN ILLUSTRATIVE EXAMPLE

Page 22: Introduction to GAMS: Formulation of a general problem

EQUATION DEFINITIONS

THE SYNTAX

eqn_name(domain_list).. expression eqn_type expression ;

AN ILLUSTRATIVE EXAMPLE

equations obj ;obj.. phi =e= phipsi + philam + phipi - phieps ;

Variables phi, phipsi, philam, phipi, phieps ;

Page 23: Introduction to GAMS: Formulation of a general problem

EQUATION DEFINITIONS

SCALAR EQUATIONS

dty.. td =e= sum(i, y(i)) ;

INDEXED EQUATIONS

dg(t).. g(t) =e= mew(t) + xsi(t)*m(t) ;

bd(j,h).. b(j,h) =e= dd(j,h) - y(j,h) ;yd(j,h).. y(j,h) =l= sum(i, p(i,j)*x(i,j)) ;

ARITHMETIC OPERATORS IN EQUATION DEFINITIONS

dem(i) .. y(i) =e= ynot(i)*(pd*p(i))**thet(i) ;

Page 24: Introduction to GAMS: Formulation of a general problem

EQUATION DEFINITIONS

EXPRESSIONS IN EQUATION DEFINITIONS

Page 25: Introduction to GAMS: Formulation of a general problem

Model Specification

" Model Specification

MODEL statements are used to identify models that will besolved. They involve 2 steps

step 1: gives the name of the model

step 2: specifies the names of the equations that will be included in the model enclosed in slashes / / or the word ALL

MODEL FarmIncome /EQ1, EQ2, EQ3/ ;

MODEL FarmIncome /ALL/ ;

Page 26: Introduction to GAMS: Formulation of a general problem

Solve Specification

" Solve Specification

SOLVE causes GAMS to apply a solver to the named modeland identifies the variable to be optimized along with thedirection of optimization

SOLVE FarmIncome USING LP MAXIMIZING Profit ;

Page 27: Introduction to GAMS: Formulation of a general problem

CLASSIFICATION OF MODELS

Page 28: Introduction to GAMS: Formulation of a general problem

ORGANIZATION OF GAMS PROGRAMS