Arithmetic errors during GAMS execution

Top  Previous  Next

Execution time numerical errors can arise during GAMS execution calculations.  These occur because of improper exponentiation (such as raising a negative number to a real power), logs of negative numbers, or dividing by zero.  Such errors are marked in the LST file with **** and an associated brief message.  That message indicates the nature of the arithmetic problem and the line number of the source code where the problem was encountered.  Consider the example executcl.gms

 

sets elements /s1*s25/

parameter data1(elements)   data to be exponentiated

          datadiv(elements) divisors;

data1(elements)=1;

data1("s20")=1;

datadiv(elements)=1;

datadiv("s21")=0;

parameter result(elements);

result(elements)=data1(elements)**2.1/datadiv(elements)

display result;

 

Running GAMS we get LOG file contents of

 

--- Starting execution

--- EXECUTCL.GMS(10) 134 Kb

*** ExecError 10 at Line 10

    ILLEGAL ARGUMENTS IN ** OPERATION

*** ExecError 0 at Line 10

    DIVISION BY ZERO

--- EXECUTCL.GMS(11) 134 Kb 2 Errors

*** Status: Execution error(s)

--- Erasing scratch files

Exit code = 3

 

Sometimes the message indicates exactly where the problem is and the user can easily figure out the cause.  Other times the problem may arise within a multidimensional item.  In such cases the best way to find out where such difficulties appear is to use a display statement and show the result of the operation, then look for bad elements.  This may also involve displays of the input data to the calculations so one can investigate the numerical properties of elements entered into the calculation that yields the error. Often even more displays will be involved where one needs to trace faulty input data back through the program.  One would display these items repeatedly investigating places where these data have been calculated.  Eventually one will find why these data have taken on the specific numerical values they have.

In the case of the above example the display of Result in the LST file reveals

 

**** EXECUTION ERROR 10 AT LINE 10 .. ILLEGAL ARGUMENTS IN ** OPERATION

**** EXECUTION ERROR 0 AT LINE 10 .. DIVISION BY ZERO

 

----        11 PARAMETER RESULT

 

s1  1.000,    s2  1.000,    s3  1.000,    s4  1.000,    s5  1.000,    s6  1.000

s7  1.000,    s8  1.000,    s9  1.000,    s10 1.000,    s11 1.000,    s12 1.000

s13 1.000,    s14 1.000,    s15 1.000,    s16 1.000,    s17 1.000,    s18 1.000

s19 1.000,    s20  UNDF,    s21  UNDF,    s22 1.000,    s23 1.000,    s24 1.000

s25 1.000

 

Here we have an indication of where the execution errors arise in the result calculation:

 For the "S20" element where we are exponentiating a negative constant to a real power raw data investigations or displays of data1 and data2 would indicate the cause is the presence in data1 of an element equal to –1 and its subsequent exponentiation.

 For the element "S21" where we are dividing by zero raw data investigations or displays of data1 and data2 would indicate the cause is the presence in data2 of an element equal to 0 and its subsequent use as a divisor.

So we then fix with data revisions or conditionals stopping use of data items that will cause the program to blow up.