Professional Documents
Culture Documents
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
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
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.
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
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
;
;
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.
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
36
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
340
408
The entry below indicates when one gets error 8 a common cause of that error is discussed
under the common error H section below.
EQUATIONS
OBJT.. PROFIT=E=
$96
Error Messages
96
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
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
[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
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
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
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.
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
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
****
****
****
****
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.
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
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