# Introduction to GAMS IDE by McCarl _amp; Gillig by dffhrtcv3

VIEWS: 2 PAGES: 26

• pg 1
```									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
Formulation of a General Problem

Nature of the problem:

   A Texas farmer grows 3 crops (corn, wheat, cotton) using land
and labor resources.

   Net incomes from growing corn, wheat, and cotton are \$109/acre,
\$90/acre, and \$115/acre.

   An acre of corn requires an acre of land and 6 hours of labor, an
acre of wheat requires an acre of land and 4 hours of labor, an
acre of cotton requires an acre of land and 8 hours of labor.

   The farmer owns 100 acres of land and 500 hours of labor.

   The farmer wants to maximize net incomes from growing crops.
Set Definition
In algebraic modeling, we commonly have subscripts.
In GAMS, the corresponding items are sets. A set definition has several
potential parts.

SET    ItemName         optional explanatory text for item
/ element1        optional explanatory text for element ,
element2         optional explanatory text for element / ;
SET or SETS         to start
ItemName            a unique name     optional explanatory text for item
/                  opening slash
Element1 name    optional explanatory text for element
, or line feed   to separate elements
Element2 name    optional explanatory text for element
, or line feed   to separate elements
…
/                  closing slash
;                   a closing ;
Set Definition

Defined set names    Explanatory Text

Element names
Data Entry

Data are entered via four different types of GAMS
commands

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:

Basic format:
SCALAR     ItemName   optional text   / value / ;

Example:
SCALAR     LandAvailable Total Land   / 100 / ;
Data Entry – PARAMETER command
Basic format:
PARAMETER        ItemName      optional text
/ element1     value ,
element2      value value2 /    ;
Example:
PARAMETER
Revenue(Crop)                  Revenues from crop production
/ Corn          109
Wheat          90
Cotton         115 /
ResourceAvailable (Resource)   Resource availability
/ Land         100
Labor         500 /      ;
Data Entry – TABLE command
Basic format:
TABLE   ItemName(set1dep,set2dep) optional text
set2elem1       set2elem2
set1element1   value11       value12
set1element2   value12       value22        ;

Example:

Elements from
Crop 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:

PARAMETER CalcRevenue(Crop)       Calculate revenues by crop ;
CalRevenue(Crop) = Revenue(Crop) * Production.L(Crop) ;

PARAMETER TotRevenue       Calculate revenues from all crops ;
TotRevenue = SUM(crop,Revenue(Crop) * Production.L(Crop) )
;

 Xc * Yc
c
Summation Digression

         X       j
j

SUM( index of summation , names(index) )

SUM(j, X (j) )

 X            ji
j       i

SUM( index1 , SUM( index2 , names( index1,index2 )))

SUM( j, SUM(i, X (j,i) ) )

or SUM( (j,i), X (j,i) )
Formulation – Variable Declarations
Basic format:

VARIABLE        VarName1(setdependency)   optional text

VarName2(setdependency)   optional text
… ;

Example:
Formulation – Equation Declarations
Basic format:

EQUATION        EquName1(setdependency)   optional text

EquName2(setdependency)   optional text
… ;

Example:
Formulation – Equation Declarations
General Structure:
DeclaredEquationName(SetDependency)..

LHSalgebra
EquationRelationType
RHSalgebra                                     ;

where

DeclaredEquationName            was in an equation declaration with this
setdependency.
LHSalgebra and RHSalgebra can contain any mixture of variables, parameters etc.
EquationRelationType            tells equality or inequality nature.
;                               are mandatory
Formulation – Equation Declarations

DeclaredEquationName
LHSalgebra
RHSalgebra

EquationRelationType
Model Specification

 Model Specification

MODEL statements are used to identify models that will be
solved. 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 model
and identifies the variable to be optimized along with the
direction of optimization

SOLVE FarmIncome USING LP MAXIMIZING Profit          ;
Solution Reports – the standard GAMS solution format

marginal values
of resources

Reduced
costs:
marginal cost
if a non-basic
variable is
forced to enter
solutions.
The single dot “.” represents zeros; INF = infinity
Solution Reports – use DISPLAY command

DISPLAY Profit .L, Production.L, ResourceEq.M, and ResourceUse ;

for a variable using .L

for an equation using .M

for parameters => nothing
Solution Reports – .L and .M syntax

We used the syntax .L and .M to address optimal solution variable and

Variable.L(SET)     gives optimal solution levels
Variable.M(SET)     gives optimal reduced costs

Equation.L(SET)     gives optimal equation levels (RHS – SLACK)

Note that to display SLACK values => OPTION SOLSLACK =1 ;
Solution Reports – slack option

w/o solslack option

w solslack option

w/ solslack option

What does this mean?
Solution Reports – computing reports from solution variables

PARAMETER
TotalValue(Crop)      Total value by crop ;
TotalValue(Crop) = Revenue(Crop) *Production.L(Crop) ;

DISPLAY TotalValue;
Solution Reports
OPTION ItemName:Decimals:RowItems:ColumnItems

OPTION TotalValue:1:0:1 ;
DISPLAY TotalValue;

Decimals       number of decimal places to be included
RowItems       number of indices displayed within rows
ColumnItems    number of indices displayed within columns
Solution Reports
OPTION places of decimals: # of index on R: # of index on C

OPTION ValueUse:1:1:1 ;
DISPLAY ValueUse;

OPTION ValueUse :1:0:2 ;
DISPLAY ValueUse;
References
McCarl, B. A. Basic GAMS class.
(http://agecon.tamu.edu/faculty/mccarl/mccarl.htm).

```
To top