You are on page 1of 15

Fixing Compilation Errors

The execution of a GAMS program passes through a number of stages, the first of which is the
compilation step. Users watching the execution of a program are sometimes dismayed to get the
message: COMPILATION ERRORS with the message indicating some large number of
errors. These notes cover the process of finding and fixing GAMS compilation errors.
Dont bark up the wrong tree ..................................................................................................... 1
Finding errors ............................................................................................................................. 2
**** ....................................................................................................................................... 2
$ ............................................................................................................................................. 2
Repositioning error messages..................................................................................................... 2
Errmsg ................................................................................................................................... 2
Improperly placed semi colons - error A ................................................................................... 4
Error message proliferation........................................................................................................ 4
Commonly found errors and their cause .................................................................................... 4
Other common errors ................................................................................................................. 6
Excess or insufficient semi colons - error B.......................................................................... 6
Spelling mistakes - error C .................................................................................................... 6
Omitted Set elements - error D.............................................................................................. 7
Domain errors ................................................................................................................... 7
Indexing problems - error E................................................................................................... 7
More domain errors........................................................................................................... 7
Summing over sets already indexed - error F........................................................................ 8
Controlled set .................................................................................................................... 8
Neglecting to deal with sets - error G.................................................................................... 9
Uncontrolled set ................................................................................................................ 9
Mismatched parentheses - error H......................................................................................... 9
Improper equation ".." statements - error I .......................................................................... 10
Entering improper nonlinear expressions - error J .............................................................. 11
Endogenous function ...................................................................................................... 11
Using undefined data - error K ............................................................................................ 11
Initialized ........................................................................................................................ 11
Assigned.......................................................................................................................... 11
Declared .......................................................................................................................... 11
Unknown symbol ............................................................................................................ 11
Improper references to individual set elements - error L .................................................... 12
No variable, parameter, or equation definition - error M .................................................... 13
Duplicate names - error N ................................................................................................... 13
Referencing item with wrong set error O ......................................................................... 14
Alphabetic list of features ........................................................................................................ 14

Dont bark up the wrong tree


Before beginning a discussion of compilation error repair one thing needs mention. GAMS

frequently marks compilation problems in latter parts of the code that are not really errors, but
rather the messages are caused by errors in the earlier code. Case may occur where an omitted
or extra semicolon or parenthesis in otherwise perfectly coded GAMS programs have caused
hundreds of error messages. One should start fixing errors from the top and after fixing several
errors rather than puzzling over obscure and often improper messages, rerun the compilation to
find out if those repairs took to care of later marked errors. It is hardly ever desirable to try to fix
all errors pointed out in one pass.

Finding errors
****
When the screen or LOG shows compilation errors are present users should edit the .LST file
directly or be guided through it by the IDE and look for the cause of the errors. Errors are
marked by lines, which begin with 4 asterisks (****).
For example errsemic.gms one may find lines in the .LST file like the following
3
4
****
5
****

SET PERIODS
TIME PERIODS
ELAPSED
ELAPSED TIME
$140
$36
PRODUCTS
LIST OF PRODUCTS
$140
$36

/T1*T5/;
/1*12/ ;
/WHEAT,STRAWBERRY/;

which indicates errors were found in the 4th and 5th lines of the input file.

$
The **** GAMS compilation error line contains information about the nature of the error. Error
messages are numbered and placed below the place in the line they were encountered and begin
with a $. In the example above, error number 140 occurred in line 4 and was caused by GAMS
finding the word ELAPSED when it was looking for an instruction. In addition, a number 36
error was caused by the second incidence of the word ELAPSED and these errors were generated
again by the same problem in line 5. GAMS also includes a list of the error message numbers
encountered and a brief description of the error at the bottom of the .LST file. In the case above
the following appears at the bottom of the LST file:
Error Messages
36
108
140

'=' or '..' operator expected - rest of statement ignored


Identifier too long
Unknown symbol .

Messages also appear in the LOG file and in the IDE the content of the LOG file is used as a
navigation aid. Also in the IDE procedures are used to reveal exactly where in the source file the
errors arise along with the offering up of the source file indexed to that position and ready for
editing.

Repositioning error messages


Errmsg

It is possible to reposition where the error explanation appears. In particular, the location can be
altered so the error message explanations appear just below the place the error is found mixed in
with the source listing. This is done by using the option errmsg=1 in the GAMS command line.
This can be imposed one of three ways.
One can call GAMS with the command line parameter
gams mymodel errmsg=1

When using the IDE this is placed in the GAMS command box in the upper right hand
corner or if wanted for all models in the file option choice under the execute tab in the
box for GAMS parameters.
One can change the system level defaults by following the customization procedures
entering this line in the file gmcprm95.txt on basic windows machines, which is also
called gmsprmnt.txt on NT machines and gmsprmun.txt on Unix and Linux machines.
The resultant file looks something like
*****************************************************
* GAMS 2.50 Default Parameterfile for Windows NT
*
* Gams Development Corp.
*
* Date : 20 Mar, 1998
*
*****************************************************
* entries required by CMEX, put in by gams.exe:
* SYSDIR
* SCRDIR
* SCRIPTNEXT
* INPUT
errmsg=1
ps=9999
optfile=1

In turn the output looks like the following


6 SET PROCES
PRODUCTION PROCESSES /makechair,maketable,makelamp/
7
RESOURCE TYPES OF RESOURCES
/plantcap,salecontrct/;
8 PARAMETER PRICE(PROCESS)
PRODUCT PRICES BY PROCESS
****
$120
**** 120 Unknown identifier entered as set
9
/makechair 6.5 ,maketable 3, makelamp 0.5/
10
PRODCOST(PROCESS)
COST BY PROCESS
11
/Makechair 10 ,Maketable 6, Makelamp 1/
****
$361
**** 361 Values for domain 1 are unknown - no checking possible
12
RESORAVAIL(RESOURCE) RESOURCE AVAILABLITY
13
/plantcap 10 ,salecontrct 3/;
14 TABLE RESOURUSE(RESOURCE,PROCESS) RESOURCE USAGE
****
$362
**** 362 Values for domain 2 are unknown - no checking possible
15
Makechair
Maketable Makelamp
16
plantcap
3
2
1.1
17
salecontrct
1
-1;
18 POSITIVE VARIABLES PRODUCTION(PROCESS) ITEMS PRODUCED BY PROCESS;

19 VARIABLES
20 EQUATIONS
21
22 OBJT.. PROFIT=E=
****
**** 140 Unknown symbol

PROFIT
TOTALPROFIT;
OBJT OBJECTIVE FUNCTION ( PROFIT )
AVAILABLE(RESOURCE) RESOURCES AVAILABLE;
SUM(PROCESS,(PRICE(PROCESS)*yield(process)
$140

Improperly placed semi colons - error A


What is wrong in the example above? The cause is what is probably the most common GAMS
error for new users -- the placement of semi colons. GAMS commands should be terminated
with a semi colon (;). However, commands can occupy more than one line. In the above case
the original input looked like the following. errsemic.gms

;
;

SET PERIODS

TIME PERIODS

/T1*T5/

ELAPSED

ELAPSED TIME

/1*12/

PRODUCTS

LIST OF PRODUCTS

/WHEAT,STRAWBERRY/

This SET command is meant to continue for several lines, but the semi colon at the end of the
first line terminates it. In turn, GAMS is looking for a command phrase in the second line and
does not recognize the word ELAPSED, so it says UNKNOWN SYMBOL. The error is
repeated at the end of the second line with yet another semi colon. There are two ways of fixing
this. One may get rid of the semi colons in the first 2 lines only leaving a semi colon at the
actual end of the SET declaration (i.e., the end of the third line) or one may enter the word SET
on the second line and third lines.
Note GAMS does not strictly require a semicolon at the end of each command. In particular
when the next line begins with one of the recognized GAMS keywords (SET, PARAMETER,
EQUATIONS etc.) then a semicolon is assumed. However, it is good practice to terminate all
commands with a semicolon. Certainly the lines before all calculations and equation
specifications (.. lines) must have a semicolon.

Error message proliferation


The example also points out another common occurrence. GAMS usually generates multiple
error messages as the consequence of a mistake. Once an error is encountered numerous
messages may appear as the compiler disqualifies all further usages of the item in question
and/or becomes confused. In the case above, subsequent references to the ELAPSED or
PRODUCTS sets would cause errors and the SOLVE statement would be disqualified. Thus,
users should fix the errors starting from the beginning and skip later errors if in doubt of their
validity.

Commonly found errors and their cause


A number of errors are commonly found in GAMS that frequently confuse new users. Here I
present a table of those errors with a brief indication of cause and a hyperlink cross-reference to

longer sections that follow on common causes of such error messages. In using this table, readers
should also look at the GAMS error message text as it may indicate additional causes.
GAMS
Error
Message
8

Potential Causes Discussion

Common Cause of Error

Mismatched parentheses-too many "(" found

36

Missing elements in equation definition

37

51-60

66

71

96

120

C, L

125

140

C, K , M

141

148

149

G,L

170

C, D

171

E, L, O

195

256

I, J, K

257

A-N

Missing equation type ("=L=", "=E="


"=G=") in equation specification
Illegal nonlinear specification
Item which has not been given numerical data
appears in equation
Equation has been declared, but not
algebraically specified with ".." statement
A statement ended and another began but no ;
was included.
Cannot find a set with this name -- often a set
element is referenced without properly being
enclosed in "
Set is already in use in a sum or an equation
definition
GAMS looking for a keyword or declared
element and cannot find it. Check spelling
and declarations.
Parameter without data used, or SOLVE does
not proceed .L, and .M references
Item referenced with more or less indexed
sets than in declaration
The set identified is not indexed either in a
sum or an equation definition
Set element referred to cannot be found in set
defined for this index position, check for
misspelling, omissions, and references to
wrong set
A domain error, Wrong set being referenced
for this index position
Name used here duplicates that of an already
defined item
Something wrong with model specification.
Look for other error messages immediately
after solve statement
Solver not checked. Happens in conjunction
with any GAMS error

340

408

Quotes likely forgotten around a specific set


reference
Mismatched parentheses-too many ")" found

The entry below indicates when one gets error 8 a common cause of that error is discussed
under the common error H section below.

Other common errors


Many types of errors are possible in GAMS. I cannot cover each one. Thus, I list a set of
common errors as well as an indication of what types of GAMS error messages they cause.

Excess or insufficient semi colons - error B


Too few or too many ;'s have been specified. The insufficient case is illustrated above. The
example shorterr.gms provides a case where a semi colon has been omitted where the immediate
first error message appears as below
22
23
24
****
25
****

EQUATIONS
OBJT.. PROFIT=E=
$96

OBJT OBJECTIVE FUNCTION ( PROFIT )


AVAILABLE(RESOURCE) RESOURCES AVAILABLE
SUM(PROCESS,(PRICE(PROCESS)*yield(process)
$2
$195
$96
-PRODCOST(PROCESS))*PRODUCTION(PROCESS)) ;
$409

Error Messages
96

Blank needed between identifier and text


(-or- illegal character in identifier)
(-or- check for missing ';' on previous line)

Normally this error is associated with GAMS error message $96.

Spelling mistakes - error C


Named sets, parameters, equations etc. may be referenced with a different spelling than in their
declaration (i.e., the set CROPS is later referred to as CROP). GAMS identifies set name
misspellings with message $120, set element misspellings with $170 and other misspellings
with $140. The example shorterr05.gms provides a case where the set PROCESS (PROCES),
one of its elements (salecontrt) and RESOURCEUSE (RESOURUS) are misspelled.
7
8
9
****
10
11
12
13
14
15
16
****
17

SET PROCEsS
PRODUCTION PROCESSES /makechair,maketable,makelamp/
RESOURCE TYPES OF RESOURCES
/plantcap,salecontrct/;
PARAMETER PRICE(PROCES)
PRODUCT PRICES BY PROCESS
$120
/makechair 6.5 ,maketable 3, makelamp 0.5/
Yield(process) yields per unit of the process
/Makechair 2
,maketable 6 ,makelamp 3/
PRODCOST(PROCESS)
COST BY PROCESS
/Makechair 10 ,Maketable 6, Makelamp 1/
RESORAVAIL(RESOURCE) RESOURCE AVAILABLITY
/platcap 10 ,salecontrct 3/;
$170
TABLE RESOURUSE(RESOURCE,PROCESS) RESOURCE USAGE

18
19
20
****
21
22
23
24
25
26
27
****

Makechair
Maketable Makelamp
plantcap
3
2
1.1
salecontrt
1
-1;
$170
POSITIVE VARIABLES PRODUCTION(PROCESS) ITEMS PRODUCED BY PROCESS;
VARIABLES
PROFIT
TOTALPROFIT;
EQUATIONS
OBJT OBJECTIVE FUNCTION ( PROFIT )
AVAILABLE(RESOURCE) RESOURCES AVAILABLE;
OBJT.. PROFIT=E=
SUM(PROCESS,(PRICE(PROCESS)*yield(process)
-PRODCOST(PROCESS))*PRODUCTION(PROCESS)) ;
AVAILABLE(RESOURCE).. SUM(PROCESS,RESOURUS(RESOURCE,PROCESS)
$140

Error Messages
120
140
170

Unknown identifier entered as set


Unknown symbol
Domain violation for element

Omitted Set elements - error D


Domain errors
One can forget to include elements in set declarations. In turn, when these elements are
referenced then an error arises (i.e., an error would occur if the element maketable was omitted
from the declaration of set PROCESS but used when data were defined under the PARAMETER
PRICE(PROCESS)) and subsequent sets. GAMS identifies such errors with message $170. The
example shorterr06.gms provides a case where the element maketable is omitted from the set
PROCESS.
6
7
8
9
****
10
11
****
12
13
****
14
15
16
17
****
18
19

SET PROCESS
PRODUCTION PROCESSES /makechair,makelamp/
RESOURCE RESOURCES
/plantcap capacity ,salecontrct contract/;
PARAMETER PRICE(PROCESS)
PRODUCT PRICES BY PROCESS
/makechair 6.5 ,maketable 3, makelamp 0.5/
$170
Yield(PROCESS) yields per unit of the process
/Makechair 2
,maketable 6 ,makelamp 3/
$170
PRODCOST(PROCESS)
COST BY PROCESS
/Makechair 10 ,maketable 6, Makelamp 1/
$170
RESORAVAIL(RESOURCE) RESOURCE AVAILABLITY
/plantcap 10 ,salecontrct 3/;
TABLE RESOURUSE(RESOURCE,PROCESS) RESOURCE USAGE
Makechair
Maketable Makelamp
$170
plantcap
3
2
1.1
salecontrct
1
-1;

Error Messages
170 Domain violation for element

Indexing problems - error E


More domain errors
Parameters, variables, and equations are specified with a particular index order. Errors can be
made where one inadvertently alters that order in subsequent references (i.e.,
RESOURUSE(RESOURCE,PROCESS) is referred to as
RESOURUSE(PROCESS,RESOURCE)). One can also use too many
[(RESOURUSE(RESOURCE,PROCESS,resource)] or too few

[RESOURUSE(RESOURCE)] indices. Cases where the order of sets are changed are marked
with message $171. Cases where more or less indices are used are marked with messages $148.
The example shorterr07.gms provides cases, where permutations of the
RESOURUSE(RESOURCE,PROCESS) are entered and the errmsg=1 option is used to
reposition the messages.
16 TABLE RESOURUSE(RESOURCE,PROCESS) RESOURCE USAGE
17
Makechair
Maketable Makelamp
18
plantcap
3
2
1.1
19
salecontrct
1
-1;
20 POSITIVE VARIABLES PRODUCTION(PROCESS) ITEMS PRODUCED BY PROCESS;
21 VARIABLES
PROFIT
TOTALPROFIT;
22 EQUATIONS
OBJT OBJECTIVE FUNCTION ( PROFIT )
23
AVAILABLE(RESOURCE) RESOURCES AVAILABLE ;
24 OBJT.. PROFIT=E=
SUM(PROCESS,(PRICE(PROCESS)*yield(process)
25
-PRODCOST(PROCESS))*PRODUCTION(PROCESS)) ;
26 AVAILABLE(RESOURCE).. SUM(PROCESS,RESOURUSE(PROCESS,RESOURCE)
****
$171
$171
**** 171 Domain violation for set
27
*PRODUCTION(PROCESS)) =L= RESORAVAIL(RESOURCE);
28 scalar x;
29 x=sum((resource,process),RESOURUSE(RESOURCE,PROCESS,process));
****
$148
**** 148 Dimension different - The symbol is referenced with more/less
****
indices as declared
30 x=sum(resource,RESOURUSE(RESOURCE));
****
$148
**** 148 Dimension different - The symbol is referenced with more/less
****
indices as declared

Summing over sets already indexed - error F


Controlled set
Errors occur when one treats the same SET more than once [(i.e., process is summed over twice
in the expression
sum((resource,process),SUM(PROCESS,RESOURUSE(RESOURCE,PROCESS)));]

or where an equation is defined over a set and one tries to sum over it. For example in the
following case RESOURCE defines the equation and is summed over
resource2(resource,process)=sum(process,RESOURUSE(RESOURCE,PROCESS));

Such errors are marked with message $125. The example shorterr08.gms illustrates such errors
under the use of the errmsg=1 option which repositions the error message explanatory text.
26
****
****
27
28
29
****
****
30
31
****
****

AVAILABLE(RESOURCE).. SUM((PROCESS,RESOURCE),RESOURUSE(RESOURCE,PROCESS)
$125
125 Set is under control already
*PRODUCTION(PROCESS)) =L= RESORAVAIL(RESOURCE);
scalar x;
x=sum((resource,process),SUM(PROCESS,RESOURUSE(RESOURCE,PROCESS)));
$125
125 Set is under control already
parameter resource2(resource,process);
resource2(resource,process)=sum(process,RESOURUSE(RESOURCE,PROCESS));
$125
125 Set is under control already

Neglecting to deal with sets - error G


Uncontrolled set
Errors occur when one does not sum or index over a set referenced within an equation (i.e., in the
example shorterr09.gms the set Process is used occurs but is not summed over or used in
defining the equations). This is marked with message $149.
26
****
****
27
****
****
28
29
****
****
30
31
****
****

AVAILABLE(RESOURCE).. RESOURUSE(RESOURCE,PROCESS)
$149
149 Uncontrolled set entered as constant
*PRODUCTION(PROCESS) =L= RESORAVAIL(RESOURCE);
$149
149 Uncontrolled set entered as constant
scalar x;
x=sum(resource,RESOURUSE(RESOURCE,PROCESS));
$149
149 Uncontrolled set entered as constant
parameter resource2(resource);
resource2(resource)=RESOURUSE(RESOURCE,PROCESS);
$149
149 Uncontrolled set entered as constant

Mismatched parentheses - error H


Parentheses must match up in expressions. An excess number of open "(" parentheses are
marked with $8 while excess closed ")" parentheses are marked with $408 [i.e., cases like SUM
(I,X(I); or SUM (I,X(I))); generate errors] and but other errors can enter. The example
shorterr10.gms illustrates such errors under the use of the errmsg=1 option which repositions the
error message explanatory text.
OBJT.. PROFIT=E=
SUM(PROCESS,((PRICE(PROCESS)*yield(process)
25
-PRODCOST(PROCESS))*PRODUCTION(PROCESS)) ;
****
$8
****
8 ')' expected
26 AVAILABLE(RESOURCE).. SUM(PROCESS,RESOURUSE(RESOURCE,PROCESS)
27
*PRODUCTION(PROCESS))) =L= RESORAVAIL(RESOURCE);
****
$37,408$409
**** 37 '=l=' or '=e=' or '=g=' operator expected
**** 408 Too many ),] or }
**** 409 Unrecognizable item - skip to find a new statement
****
looking for a ';' or a key word to get started again
28 scalar x;
29 x=sum((resource,process),RESOURUSE(RESOURCE,PROCESS)));
****
$408
**** 408 Too many ),] or }
30
****
****

x=sum((resource,process),(RESOURUSE(RESOURCE,PROCESS));
$8
8 ')' expected

Two error prevention strategies are possible when dealing with parentheses.
Many editors, including the one in the IDE, contain a feature that allows one to ask the
program to identify the matching parentheses with respect to the parenthesis that is sitting
underneath the cursor. It is highly recommended that GAMS users employ this feature
during model coding to make sure that parentheses are properly located for the end of
sums, if statements, loops etc.

Alternative characters can be used in place of parentheses. In particular, the symbols { }


or [ ] can be used instead of the conventional ( ). GAMS is programmed to differentially
recognize these symbols and generate compile errors if they do not match up. Thus a
statement such as
x = sum( j, ABS ( TTS (j) ) );
can be restated as
x = sum[ j, ABS { TTS(j) } ];
Such a restatement would provide a visual basis for examining whether the parentheses
were properly matched. It would also generate errors if one did not use the alternative
parenthesis forms in the proper sequence. For example, the following statement would
stimulate compiler errors:
x = sum[ j, ABS { TTS(j} ] );.

Improper equation ".." statements - error I


Each declared equation must be specified with a statement, which contains certain elements.
Omitting the ".." causes error $36. Omitting the equation type ("=L=", "=E=", or "=G=") causes
error $37. Omitting the specification of a declared equation is marked with messages $71 and
$256. The example shorterr11.gms illustrates the first two such errors under the use of the
errmsg=1 option which repositions the error message explanatory text.
25
****
****
****
26
27
28
****
****

OBJT PROFIT=E=
SUM(PROCESS,(PRICE(PROCESS)*yield(process)
$36
36 '=' or '..' or ':=' or '$=' operator expected
rest of statement ignored
-PRODCOST(PROCESS))*PRODUCTION(PROCESS)) ;
AVAILABLE(RESOURCE).. SUM(PROCESS,RESOURUSE(RESOURCE,PROCESS)
*PRODUCTION(PROCESS)) = RESORAVAIL(RESOURCE);
$37
37 '=l=' or '=e=' or '=g=' operator expected

while the example shorterr12.gms illustrates the last two


22 EQUATIONS
OBJT OBJECTIVE FUNCTION ( PROFIT )
23
AVAILABLE(RESOURCE) RESOURCES AVAILABLE
24
notthere one i forgot ;
25 OBJT.. PROFIT=E=
SUM(PROCESS,(PRICE(PROCESS)*yield(process)
26
-PRODCOST(PROCESS))*PRODUCTION(PROCESS)) ;
27 AVAILABLE(RESOURCE).. SUM(PROCESS,RESOURUSE(RESOURCE,PROCESS)
28
*PRODUCTION(PROCESS)) =l= RESORAVAIL(RESOURCE);
29 MODEL RESALLOC /ALL/;
30 SOLVE RESALLOC USING LP MAXIMIZING PROFIT;
****
$71,256
**** 71 The symbol shown has been declared as an equation, but no
****
Symbolic equation (..) was found. hint - look for commas in the
****
Documentation text for the equations. use quotes around the
****
Text or eliminate the commas.
**** 256 Error(s) in analyzing solve statement. More detail appears
****
Below the solve statement above
**** The following LP errors were detected in model RESALLOC:
**** 71 notthere is an undefined equation

Entering improper nonlinear expressions - error J


Endogenous function
One gets messages $51-$60 and $256 containing the word ENDOGENOUS when the equations
contain nonlinear terms beyond the capability of the solver being used (i.e., nonlinear terms do
not work in LP solvers). The example shorterr13.gms illustrates the first two such errors under
the use of the errmsg=1 option which repositions the error message explanatory text.
26 AVAILABLE(RESOURCE).. SUM(PROCESS,RESOURUSE(RESOURCE,PROCESS)
27
*sqr(PRODUCTION(PROCESS))) =L= RESORAVAIL(RESOURCE);
28 MODEL RESALLOC /ALL/;
29 SOLVE RESALLOC USING LP MAXIMIZING PROFIT;
****
$51,256
**** 51 Endogenous function argument(s) not allowed in linear models
**** 256 Error(s) in analyzing solve statement. More detail appears
****
Below the solve statement above
**** The following LP errors were detected in model RESALLOC:
**** 51 in equation AVAILABLE .. VAR argument(s) in function

Using undefined data - error K


Initialized
Assigned
Declared
Unknown symbol
When data items are used which have not been declared (in a TABLE, PARAMETER or
SCALE statement) one gets told they are an unknown symbol via error $140 simply stating
GAMS doesn't know what they are. In addition, when declared items are used which have
not received numerical values, one gets either: 1) message $141 when the items are used in
calculations, or 2) messages $66 and $256 when the items are used in model equations. One
can also get message $141 when referring to optimal levels of variables (i.e., X.L or X.M) when
a SOLVE has not been executed. The example shorterr14.gms illustrates the first two such errors
under the use of the errmsg=1 option which repositions the error message explanatory text. This
example also shows how $141 errors occur for all uses of .L and .M commands when GAMS
stops and the actions undertake by solve are not checked because of earlier compiler
errors.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
****

SET PROCESS
PRODUCTION PROCESSES /makechair,maketable,makelamp/
RESOURCE RESOURCES /plantcap ,salecontrct ;
PARAMETER PRICE(PROCESS)
PRODUCT PRICES BY PROCESS
/makechair 6.5 ,maketable 3, makelamp 0.5/
Yield(process) yields per unit of the process
RESORAVAIL(RESOURCE) RESOURCE AVAILABLITY
/plantcap 10 ,salecontrct 3/;
parameter RESOURUSE(RESOURCE,PROCESS) RESOURCE USAGE
POSITIVE VARIABLES PRODUCTION(PROCESS) ITEMS PRODUCED BY PROCESS;
VARIABLES
PROFIT
TOTALPROFIT;
EQUATIONS
OBJT OBJECTIVE FUNCTION ( PROFIT )
AVAILABLE(RESOURCE) RESOURCES AVAILABLE ;
OBJT.. PROFIT=E=

SUM(PROCESS,(PRICE(PROCESS)*yield(process)
-PRODCOST(PROCESS))*PRODUCTION(PROCESS)) ;
$140

****
21
22
****
****
****
****
23
24
25
26
27
****
****
30
****
****
****
****

140 Unknown symbol


scalar x;
x=sum(PROCESS,Yield(process));
$141
141 Symbol neither initialized nor assigned
A wild shot: You may have spurious commas in the explanatory
text of a declaration. Check symbol reference list.
AVAILABLE(RESOURCE).. SUM(PROCESS,RESOURUSE(RESOURCE,PROCESS)
*PRODUCTION(PROCESS)) =L= RESORAVAIL(RESOURCE);
MODEL RESALLOC /ALL/;
SOLVE RESALLOC USING LP MAXIMIZING PROFIT;
$257
257 Solve statement not checked because of previous errors
solprod(PROCESS)= PRODUCTION.l(PROCESS);
$141
141 Symbol neither initialized nor assigned
A wild shot: You may have spurious commas in the explanatory
text of a declaration. Check symbol reference list.

while shorterr15.gms illustrates what happens when items without numerical value are used in
equations.
16 parameter RESOURUSE(RESOURCE,PROCESS) RESOURCE USAGE;
17 POSITIVE VARIABLES PRODUCTION(PROCESS) ITEMS PRODUCED BY PROCESS;
18 VARIABLES
PROFIT
TOTALPROFIT;
19 EQUATIONS
OBJT OBJECTIVE FUNCTION ( PROFIT )
20
AVAILABLE(RESOURCE) RESOURCES AVAILABLE ;
21
22 OBJT.. PROFIT=E=
SUM(PROCESS,(PRICE(PROCESS)*yield(process)
23
-PRODCOST(PROCESS))*PRODUCTION(PROCESS)) ;
24 scalar x;
25 x=sum(PROCESS,Yield(process));
26 AVAILABLE(RESOURCE).. SUM(PROCESS,RESOURUSE(RESOURCE,PROCESS)
27
*PRODUCTION(PROCESS)) =L= RESORAVAIL(RESOURCE);
28
29 MODEL RESALLOC /ALL/;
30 SOLVE RESALLOC USING LP MAXIMIZING PROFIT;
****
$66,256
**** 66 The symbol shown has not been defined or assigned
****
A wild shot: You may have spurious commas in the explanatory
****
text of a declaration. Check symbol reference list.
**** 256 Error(s) in analyzing solve statement. More detail appears
****
Below the solve statement above
**** The following LP errors were detected in model RESALLOC:
**** 66 RESOURUSE has no data

and shorterr15.gms shows what happens when a solve statement is not present and .L or .M
variable or equation attributes are used in calculations.
29 MODEL RESALLOC /ALL/;
32 solprod(PROCESS)= PRODUCTION.l(PROCESS);
****
$141
**** 141 Symbol neither initialized nor assigned
****
A wild shot: You may have spurious commas in the explanatory
****
text of a declaration. Check symbol reference list.

Improper references to individual set elements - error L


Individual set elements are referenced by entering their name surrounded by quotes. When the
quotes are not entered one gets message $120 and when the item is in the set relevant to this
place without m quotes one gets $340 (i.e., if I have defined X(CROP) with CORN as an
element in CROP, then X(CORN) is wrong, but X("CORN") is right). One also gets errors
assuming this is a new set indicating it has not been dealt with $149 and this is not the set the

item is defined over $171 (a domain error). The example shorterr16.gms illustrates such errors
under the use of the errmsg=1 option which repositions the error message explanatory text.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
****
****
****
****
****
****
****

SET PROCESS
RESOURCE

PRODUCTION PROCESSES /makechair,maketable,makelamp/


TYPES OF RESOURCES
/plantcap capacity ,salecontrct
contract/;
PARAMETER PRICE(PROCESS)
PRODUCT PRICES BY PROCESS
/makechair 6.5 ,maketable 3, makelamp 0.5/
Yield(process) yields per unit of the process
/Makechair 2
,maketable 6 ,makelamp 3/
PRODCOST(PROCESS)
COST BY PROCESS
/Makechair 10 ,Maketable 6, Makelamp 1/
RESORAVAIL(RESOURCE) RESOURCE AVAILABLITY
/plantcap 10 ,salecontrct 3/;
TABLE RESOURUSE(RESOURCE,PROCESS) RESOURCE USAGE
Makechair
Maketable Makelamp
plantcap
3
2
1.1
salecontrct
1
-1;
scalar x;
x=price(makechair);
$120,340$149,171
120 Unknown identifier entered as set
149 Uncontrolled set entered as constant
171 Domain violation for set
340 A label/element with the same name exist. You may have forgotten
to quote a label/element reference. For example,
set i / a,b,c /; parameter x(i); x('a') = 10;

No variable, parameter, or equation definition - error M


When a variable, parameter, or equation is used which has not been declared one gets error
$140. The example shorterr17.gms illustrates such errors under the use of the errmsg=1 option
which repositions the error message explanatory text.
20 POSITIVE VARIABLES PRODUCTION(PROCESS) ITEMS PRODUCED BY PROCESS;
21 VARIABLES
PROFIT
TOTALPROFIT;
22 EQUATIONS
OBJT OBJECTIVE FUNCTION ( PROFIT )
23 ;
24 OBJT.. PROFIT=E=
SUM(PROCESS,(PRICE(PROCESS)*yield(process)
25
-PRODCOST(PROCESS))*PRODUCTION(PROCESS)) ;
26 AVAILABLE(RESOURCE).. SUM(PROCESS,RESOURUSE(RESOURCE,PROCESS)
****
$140
**** 140 Unknown symbol
27
*PRODUCTION(PROCESS)) =L= RESORAVAIL(RESOURCE);
28 MODEL RESALLOC /ALL/;

Duplicate names - error N


Multiple declarations of items with the same name will cause message $195. The example
shorterr18.gms illustrates such errors under the use of the errmsg=1 option which repositions the
error message explanatory text.
8
9
10
11
12
13
14
15
16
17

PARAMETER PRICE(PROCESS)
PRODUCT PRICES BY PROCESS
/makechair 6.5 ,maketable 3, makelamp 0.5/
Yield(process) yields per unit of the process
/Makechair 2
,maketable 6 ,makelamp 3/
PRODCOST(PROCESS)
COST BY PROCESS
/Makechair 10 ,Maketable 6, Makelamp 1/
RESORAVAIL(RESOURCE) RESOURCE AVAILABLITY
/plantcap 10 ,salecontrct 3/;
TABLE RESOURUSE(RESOURCE,PROCESS) RESOURCE USAGE
Makechair
Maketable Makelamp

18
plantcap
3
2
1.1
19
salecontrct
1
-1;
20 POSITIVE VARIABLES PRODUCTION(PROCESS) ITEMS PRODUCED BY PROCESS;
21 VARIABLES
PROFIT
TOTALPROFIT;
22 EQUATIONS
OBJT OBJECTIVE FUNCTION ( PROFIT )
23
RESORAVAIL(RESOURCE) RESOURCES AVAILABLE ;
****
$195
**** 195 Symbol redefined with a different type

Referencing item with wrong set error O


When an item is reference over a different set than it is defined over and that set is not a subset
of the original set one gets a domain error $171. The example shorterr19.gms illustrates such
errors under the use of the errmsg=1 option which repositions the error message explanatory text.
23
AVAILABLE(RESOURCE) RESOURCES AVAILABLE ;
24 OBJT.. PROFIT=E=
SUM(PROCESS,(PRICE(PROCESS)*yield(process)
25
-PRODCOST(PROCESS))*PRODUCTION(PROCESS)) ;
26 AVAILABLE(process).. SUM(resource,RESOURUSE(RESOURCE,PROCESS)
****
$171
**** 171 Domain violation for set
27
*PRODUCTION(PROCESS)) =L= 10;
28 MODEL RESALLOC /ALL/;
29 SOLVE RESALLOC USING LP MAXIMIZING PROFIT;
****
$257
**** 257 Solve statement not checked because of previous errors
30
31 parameter solprod(process) report of production;
32 solprod(resource)= RESORAVAIL(RESOURCE);
****
$171
**** 171 Domain violation for set

Alphabetic list of features


****
$
;
Assigned
Common errors
Declared
Domain error
Domain error
Endogenous function
Errmsg
Error message proliferation
Error repair
Initialized
Mismatched parentheses

Marker for compiler error message.


Marker for number of compiler error message.
Symbol that ends statements and when omitted or used
excessively is common source of error messages.
GAMS concept that data were placed into object by a
calculation or solve.
List of common errors and their cause.
GAMS concept that item was defined by a scalar,
parameter, set, variable, etc. statement.
Error when set element is not a member of a set referenced
for the position being worked with.
Error when set name does not match the set in this position.
Indication that GAMS has found nonlinear term in linear
model.
Reposition error messages to just after error marking.
Case where one error causes many messages and other than
the first one are not really valid.
Procedures to find and fix compiler errors
GAMS concept that data were placed into object when type
was declared (by scalar, parameter ... statement).
Common source of errors.

Set under control


Uncontrolled set
Unknown symbol

Set inside set varying statement like sum or loop or a set on


right hand side of statement indexed on left hand side
over that set.
Set in a statement that is not subject to set varying
statement like sum or loop or a set on right hand side of
statement that is not indexed on left hand side.
Indication that GAMS is looking for a declared named item
and spelling of this one doesn't match known items.