Hi all, I have just finished modelling some problem. I wrote the GAMS code but it is giving errors such as; - dimension different - The symbol is referenced with more/less indices as declared - Set identifier or quoted element expected Actually those are the errors rendered repeatedly.

Below is my GAMS code:

SET i DRGs /1,2,3,4/;
TABLE vars(i, j)
              1       2       3       4       5
     1        2000    7       5       30      800
     2        1500    4       2       10      500
     3        500     2       1       5       150
     4        300     1       0       1       50
     obj Objective Function
     constr1 Diagnostic services
     constr2 Bed-day
     constr3 Nursing Use
     constr4 Drugs
     constr5 min x1
     constr6 min x2
     constr7 min x3
     constr8 min x4;
obj..   Z =e= SUM( (i,j), X(i)*vars(i,1 ));
constr1.. SUM( (i,j), X(i)*vars(i,2) )  =L= 570;
constr2.. SUM( (i,j), X(i)*vars(i,3) )  =L= 1000;
constr3.. SUM( (i,j), X(i)*vars(i,4) )  =L= 50000;
constr4.. SUM( (i,j), X(i)*vars(i,5) )  =L= 50000;
constr5.. X(1) =G= 10;
constr6.. X(2) =G= 15;
constr7.. X(3) =G= 40;
constr8.. X(4) =G= 160;

Thanks alot for your help.

asked 06 May '15, 15:27

alexmath's gravatar image

accept rate: 0%

There are three major problem with your code.

  1. Set \(i\) is defined to have four elements, while Table \(vars\) is 5 by 5.
  2. Index \(j\) in Table \(vars\) is undefined. You might used the "alias" keyword for that.
  3. You cannot directly use a set member in a parameter or variable within equations. You have to put it between two apostrophes.

PS. At first, debugging GAMS could be challenging and frustrating. The key is to always look for the first error reported by GAMS, fix it, and then rerun the code. If you do so, you'll become an expert GAMS debugger in no time.


answered 06 May '15, 22:30

Ehsan's gravatar image

Ehsan ♦
accept rate: 16%

edited 06 May '15, 22:35

hi, I made \(j\) an alias of \(i\) and put apostrophes around all the \(i\)s in the \(X\) variable - like \(X('i')\) but it is still giving errors.

(09 May '15, 05:04) alexmath

@alexmath: Did you fixed the dimension problem of Table \(vars\) (item #1)?

(09 May '15, 23:21) Ehsan ♦

@Ehsan, well i tried using the 'alias' key word, that didnt fix it. so i deleted the entire first row but that didnt fix it either. Actually when i use the alias keyword, even if i dont delete the first row, I get "domain violation error". could be because of something like $X(′3′)$

(10 May '15, 03:45) alexmath

@alexmath: The problem is with the last column (i.e., column "5"), not the first row. Just remove that, and then everything should be fine. However, if set \(j\) has 5 members, you should define it as a new set, not an alias of set \(i\).

(10 May '15, 03:54) Ehsan ♦

Yes it does, I declared it as \(SET ~j ~\backslash v1*v5 \backslash;\) and tried accessing it as \(vars('i','v1')\); but that also is not working.

(10 May '15, 04:16) alexmath

@alexmath: Please read the manual. This could help you avoid syntax errors. Specific elements like v1 have to enclosed in '', like 'v1', but generic elements used for sums etc. are not enclosed. So do not enclose i or j. Furthermore, if you get errors and want to discuss them, please state the exact line and name of the error.

(10 May '15, 06:48) JF Meier

Thanks very much, now it works fine :). i had mixed up the specific elements and generic elements :)

(10 May '15, 08:26) alexmath
showing 5 of 7 show 2 more comments
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 06 May '15, 15:27

Seen: 4,135 times

Last updated: 10 May '15, 08:26

OR-Exchange! Your site for questions, answers, and announcements about operations research.