General Algebraic Modeling Systems (Model Answers)
General Algebraic Modeling Systems (Model Answers)
Modeling Systems
( Model Answers)
A. Set declaration and
Definition
Questions:
*********
1. Declare and define the following sets in
GAMS:
Set S = {a,b,c}
Set m M ,
m = ξ{Egypt, Lebanon, Kuwait}
2. Include in the above example two
approaches describing or documenting the two
set.
SET
S First three letters / a, b, c / ;
______________________________________________
SET S First three letters /
a first letter
b second letter
c third letter / ;
SET
m subset of Arab Countries
/ Egypt , Lebanon, Kuwait / ;
______________________________________________
SET m subset of the Arab Countries /
Egypt Country of Egypt
Lebanon Country of Lebanon
Kuwait State of Kuwait /
;
3. Define the following sets in a compact GAMS form.
Set T = {1990,1992,1993,1994,1995}
Set MC = {MC1,MC2,…….MC10}
SETS
MACINES / MC1*MC10 /
GENERAL / A1BC*A20BC /
DIFFERENT / A01BC* A20BC / ;
4. Identify illegality in the following GAMS statement:
SET
Illegale1 / A15BC*A10BC /
Illegale2 / A1X1* A9X9 /
Illegale3 / A1* B9 /;
_____________________________________________________
SET C countries
/ Egypt, Italy , Nederland /
P Ports
/ Alexandria, Port-Said, Venis, Genewa, Amesterdam, Roterdam /
*Two dimensional set to associate Ports with countries.
SET PTOC(P,C) Port to country relationship
/ Egypt . (Alexandria, Port-Said)
Italy . (Venis , Genewa )
Nederland . (Amesterdam, Roterdam )
/ ;
7. Multiple set names and sparse matrix. In the following input output
matrix, develop a mapping set to identify non empty cells of the
matrix using GAMS.
Agriculture Industry Services
Agriculture 10 20
Industry 30
Services 15 40
________________________________________________________
----------------------------------------------------------------------------------
URBAN RURAL
GOV 400 350
PRV 1000 700 ;
2. Given the following quantity of government and private sector
labors by household area (in Thousands).
Government Sector Private Sector
Urban Household area 400 1000
Rural Household Area 350 700
Enter the labor data in a GAMS model using both set, parameter
and Table GAMS reserved words.
-----------------------------------------------------------------------
SETS
l Labor by category / GOV, PRIV /
h Household type / URBAN, RURAL / ;
PARAMETER A(l,h)
/ GOV. URBAN 400
GOV.RURAL 350
PRV. URBAN 1000
PRV.RURAL 700
/ ;
3. Given the following quantity of government and private sector labors by
household area and skill level (in Thousands) :
Government Sector Private Sector
Urban Household area(Skilled) 400 1000
Rural Household Area (skilled) 350 700
Urban Household area ( unskilled) 400 1000
Rural Household Area (unskilled) 350 700
SKILL UNSKILL
GOV.URBAN 400 400
GOV.RURAL 350 350
PRV.URBAN 1000 1000
PRV.RURAL 700 700 ;
---------------------------------------------------------------------------
1. Given the following data items in the form of matrix, vector and scalar.
Sets:
l Labor by Sector / GOV, PUB, PRIV /
h Household type / URBAN, RURAL / ;
TABLE LABOR (l,h) number of workers in thousands.
URBAN RURAL
GOV 200 150
PUB 20 30
PRV 300 250 ;
PARAMETER W(h) wage rate by household area /
URBAN 30 , RURAL 25 / ;
SCALAR GR average growth rate (in percent) of labor by sector
and Household Area / 2 / ;
a) Compute the new number of labor by Sector and Household area given the
annual growth rate GR in percent (%).
b) Compute the total wage income by sector using the labor matrix and the
wage rate by household category.
Solution:
********
Parameter NLAB(l,h) new labor number by category ;
NLAB(l,h) = GR* LABOR(l,h) ;
Parameter WLAB(l) Wage by labor sector ;
WLAB(l) = SUM (h, W(h) *NLAB(l,h)) ;
------------------------------------------------------------------------------------
2. Convert the following mathematical specifications or equations to a
GAMS Format:
TOTCm = ∑iCim
COUNT= ∑i∑j Aij
EMP= ∑t Lt Mt
OUTPUT= ∏i INPUT(i) **SHARE(i)
Using Sets , Parameters , Tables , SUM and PROD reserved
GAMS key words.
Solution:
**********
TOTC(m) = SUM(i, C(i,m) ) ;
Probability Functions
Exponential(b)
Normal(μ,σ)
Uniform(m,n)
These are functions used to generate
random deviates – based on Mont Carlo
Methods – pertaining to a specific
probability density function
(negative exponential , Normal and
uniform ditributions).
5. Given the following sets and parameters:
SETS
L Labor by category / GOV, PUB, PRV /
S Labor by Skill / SKILLED, UNSKILL /
H Household type / URBAN, RURAL / ;
PARAMETER LABOR(L,S,H) labor by category skill and household type
/ GOV.SKILLED.URBAN 100, GOV.SKILLED.RURAL 150
PUB.SKILLED. URBAN 200, PUB.SKILLED.RURAL 120
PRV.SKILLED. URBAN 250, PRV.SKILLED.RURAL 180
GOV.UNSKILL.URBAN 100, GOV.UNSKILL.RURAL 150
PUB.SKILL. URBAN 200, PUB.SKILL.RURAL 120
PRV.UNSKILL. URBAN 250, PRV.UNSKILL.RURAL 180
/ ;
Use the two GAMS reserved words “DISPLAY” and “OPTION” to design
a transparent output report to display the LABOR parameter.
Solution:
********
Display “ Labor Number by Category”, LABOR;
Display “ ************************” ;
Option 3 , 2 , 1 ;
3 = Number of decimal points ******. ***
2 = Number of indexes appearing as Row
1 = Number of indexes Appearing as Columns
-----------------------------------------------------------------------
Labor Number by Category
************************
******* ******* ******* ********
*****.******
*****.****** 200.000
*****.******
Part D: Variables and Equations
1. Determine the type of decision variables in GAMS and the way of their
Declaration and bounding.
----------------------------------------------------------------------------------------
Variable types and bounds in GAMS
Keyword BOUNDS
LO UP
FREE (default) -INF +INF
POSITIVE 0 +INF
NEGATIVE -INF 0
BINARY 0 1
INTEGER 0 100
----------------------------------------------------------------------------------
VARIABLES
Z(P,I) Process Level
X(C,I,J) Shipment of final product
PHI Total Cost ;
Positive Variables Z,X ;
Free Variables PHI ; ( We can exclude this statement since free
variables is the default)
2. Explain the following GAMS statements:
Assignment Statement to bound Variables
Example 1:
X.UP(C,I,J) = 1000 ; PHI.UP = INF ;
XX.UP(“CAIRO”, “ALEX”) = 200 ;
Example 2:
C.LO(T) = 0.01 ;
Example 3:
C.L(T) = 4*CINIT(T)
Example 4:
C.FX(“Period-1”) = 1 ;
Example 5:
C.FX(“1985”) = 1 ; C.LO(T) = 0.01 ;
C.LO(T) = 0.01 ; C.FX(“1985”) = 1;
Other Examples:
Variable status ;
quantity.up(production,markets)=1000 ;
Solution:
PARAMETERS
Y(R) Income of each region (m LE )
INCOME (s) Income of cities (m LE)
/ CAIRO 100 , ALEX 70
ASWAN 50 , LUXOR 30 /
For each region R compute the summation over the S cities such that
CORR(R,S) exists.
---------------------------------------------------------------------
Solution:
Y(R) = SUM(S $ CORR(R, S), INCOME (s)) ;
3. Given the following GAMS statements:
* Declaration and definition of set and model parameters
Set t / 2000 * 2005 /
Parameter
pop(t) / 2000 90 /
Growth(t) / 2000 2, 2001 2.1
2002 2.2, 2003 2.3
2004 2.4, 2005 2.5 / ;
Compute population size during the period (2000 – 2005) using
GAMS-LOOP statement, Given that pop(t) is the population size and
Growth(t) is the annual population growth Rate(%).
-----------------------------------------------------------
Solution:
if ( f < = 0,
P( i ) = -1 ;
P( i ) = P( i ) **2 ;
Else
P( i ) = P ( i )**3 ;
);
Good Luck
Motaz Khorshid