introduction to gams: formulation of a general problem prof. boyan bonev ivanov, ph.d. email:...
TRANSCRIPT
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
1. SET definitions (crop)
2. Data entry (Ccrop, acrop,resource,
bresource)
3. Variable specifications
4. Equation specifications
a. declaration
b. algebraic structure
5. Model statement
6. Solve statement
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"]} /] ;
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” / ;
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 / ;
Set Definition
Defined set names Explanatory Text
Element names
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
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 / ;
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 / ;
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" /
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 ;
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)
Data Entry – Direct assignment
Basic format:
PARAMETER ItemName(set1dep,set2dep) optional text ; ItemName(set1dep,set2dep) = some expression ;
Example:
Summation Digression
Formulation – Variable Declarations
Basic format:
VARIABLE VarName1(setdependency) optional text VarName2(setdependency) optional text … ;
Example:
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
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 ;
EQUATION DECLARATIONS
THE SYNTAX
Equation[s] eqn_name text {, eqn_name} ;
AN ILLUSTRATIVE EXAMPLE
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 ;
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) ;
EQUATION DEFINITIONS
EXPRESSIONS IN EQUATION DEFINITIONS
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/ ;
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 ;
CLASSIFICATION OF MODELS
ORGANIZATION OF GAMS PROGRAMS
References
http://www.pse.ice.bas.bg:8080/WWW_Systems_engineerig_laboratory/Distance_learning_systmeng/Distance_systmeng_LT.htm