Vous êtes sur la page 1sur 33

Introduction to GAMS:

Model inspection & Error messages

Dhazn Gillig
&
Bruce A. McCarl

Department of Agricultural Economics


Texas A&M University
Model Inspection

Are you sure that you know EXACTLY what is in the model?

GAMS can cause one to lose touch with the exact optimization
model being solved, especially when one has a big complicated
data set containing many data calculations.

Thus, when setting up a model one may need to look at individual


equations and variables. GAMS permits this through the use of
model element displays using

! LIMROW and LIMCOL options

! GAMSCHK
Model Inspection – Limrow / Limcol

LIMROW controls the number of rows listed in the equation listing


LIMCOL controls the number of columns listed in the variable listing

If we want more or less variables or equations we can do this by


altering the LIMROW and LIMCOL options

To eliminate => OPTION LIMROW = 0;


OPTION LIMCOL = 0;

To expand => OPTION LIMROW = 100 ; (or any other number)


OPTION LIMCOL = 100 ;
Limrow / Limcol – Transportation problem illustration

Min Cost of shipping goods from S to D

minimization of total cost across all possible


shipment routes
Limited outgoing shipments from each S point i

Minimum demand constraint at each D point j

Nonnegative shipments
Limrow / Limcol – Transportation problem illustration
Limrow / Limcol – Transportation problem illustration
For equations we get something like
Limrow / Limcol – Transportation problem illustration
Limrow / Limcol – Transportation problem illustration
Limrow / Limcol – Transportation problem illustration
For variables we get something like
Limrow / Limcol – Transportation problem illustration
Model Inspection – Limrow / Limcol

Unfortunately, for large models the LIMROW/ LIMCOL option


can generate very substantial output files. An alternative way
of displaying models called GAMSCHK will be discussed in the
next class.
Common Error Messages
What to do when ERRORS STRIKE and GAMS stops running?
Not to worry, when GAMS detects errors, it inserts coded error messages
inside the echo print in the *.LST file. All errors are marked with four
asterisks **** at the beginning of a line. One can use
to find where errors occur and fix them.
Common Error Messages
Double click on Red Color Lines in the process window,
causes the cursor to jump to location in *.gms file where
error occurs.

Note: always concentrate on


fixing the first or first few errors
and ignore the others since
many subsequent errors may
result from a previous error.
Common Error Messages

Double click on Black Color Lines in the process window,


then a cursor will jump to a *.lst file where the error is listed.
Common Error Messages
To have error messages displayed
immediately following an error line,
go to GAMS 20.7 directory and open
gmsprm95.txt (for window) or
gmsprmNT.txt (for NT), then type
errmsg = 1
errmsg controls the location in the
listing file (*.lst) of error messages.

Alternatively,
errmsg = 0
error messages at the end of
*.lst file
errmsg = 2
no error messages
Common Error Messages

Note that in every equation all the subscripts (SETS) must be


handled in every term. This means

! they either must be summed over, or

! they must appear in the equation definition

Not obeying this will cause errors as on next pages.


Common Error Messages
Set is under control already.

Source set is used in conflicting ways. By appearing in the equation


specification (.. Command) SupplyBal(Source).. this defines these
equations for all elements of the set “Source”, but then how can you
sum over this. The answer is that you cannot and GAMS gives an error.
Simultaneously, Destination set is not controlled. How do you FIX this?
Common Error Messages
Uncontrolled set entered as constant

Here the set Source is not operated over in a sum or the ..


specification. So what is GAMS to do – give an error message.
Common Error Messages
Now for some other common errors
Floating entry ignored

We have made an error in typing of a table. We have not aligned the data
under a column set name so GAMS does not know which data column a
number goes with and issues an error.
Common Error Messages
Dimension different

We defined Transport with 2 dimensions but used it with one dimension in


the SupplyBal.
Common Error Messages
Duplicate names

We already defined TransCost as a parameter and then we used it again in


equation specification. GAMS will object to these multiple declarations.
Common Error Messages
Omitted set elements

We forgot to include “San Diego” element in Source set, but this “San
Diego” is used later in the PARAMETERS. Therefore, an error arises.
Common Error Messages
Mismatched parentheses

(A)

(B)

We had an excess number of close “)” in (A) but we had an excess number of
open “(“ in (B). We can use to check for parenthesis.
Common Error Messages
Entering improper nonlinear expressions

The CostSum equation contains nonlinear terms beyond the capacity of


the solver being used. In SOVLE statement, we define to solve this
problem as a LP problem.
Common Error Messages
Using undefined data

We declared a TransCost as a parameter but we did not declare numerical


values to the TransCost and it is used in the CostSum equation.
Common Error Messages
No variable, parameter, or equation definition

A CostSum equation is used but it has not been declared.


Common Error Messages
Insufficient semi colon

We forgot to terminate the EQUATIONS statement with the semi colon.


Common Error Messages
Domain violation for element = inconsistent elements of a set

We misspelled “New Yor” element of Destination set.


Common Error Messages
‘=’ or ‘..’ operator expected

The algebraic structure of equations must be specified by using .. notation.


Here we omitted the “..” in CostSum equation.
Common Error Messages
Unknown symbol

We named a model “Tranpor”, but then later we solve the model called
“Transport”. Obviously, misspelled in the MODEL statement.
More Help on Error Messages

Double click on a
topic to view details
Hands On
Learning Objectives (handson4.gms):

1. Learn how to inspect a model structure using OPTION


LIMROW and LIMCOL

2. Learn how to find and fix errors

Things To Do

1. Please run handson2.gms and then fix errors and re-run the problem.

2. Please open handson3.gms and save it as handson4.gms. Alter your


objective function from

to

Then run handson4.gms and inspect the model using OPTION


LIMROW and LIMCOL. Is there anything wrong with the model
structure or solutions?
References
McCarl, B. A. Basic GAMS class.
(http://ageco.tamu.edu/faculty/mccarl/mccarl.htm).

Vous aimerez peut-être aussi