Vehicle Routing Problem Error

Hello, my model gives an error on line 72.
sum(i, y(i,j,k)) =l= 3; set is under control already
can you help?

Set
   i / d1*d12 / 
   j / kamyon, tir / 
   k / d1*d12 /  
;

Parameter
   demand(i)           
   / d1 100, d2 150, d3 200, d4 180, d5 160, d6 220, d7 130, d8 170, 
     d9 210, d10 190, d11 140, d12 160 /

   capacity(j)        
   / kamyon 150, tir 250 /

   cost(i,j)           
   / d1.kamyon 5953, d1.tir 8511, d2.kamyon 5601, d2.tir 7957, 
     d3.kamyon 5341, d3.tir 7539, d4.kamyon 10437, d4.tir 14733, 
     d5.kamyon 10682, d5.tir 15136, d6.kamyon 10345, d6.tir 14587, 
     d7.kamyon 7513, d7.tir 9446, d8.kamyon 5045, d8.tir 7311, 
     d9.kamyon 6928, d9.tir 10544, d10.kamyon 7880, d10.tir 10874, 
     d11.kamyon 3690, d11.tir 5223, d12.kamyon 1687, d12.tir 2935 /;

Table distance(i,k)    
        d1    d2    d3    d4    d5    d6    d7    d8    d9    d10   d11   d12
   d1   0     50    60    80    100   120   90    160   190   220   170   140
   d2   50    0     70    90    110   140   120   190   230   200   180   160
   d3   60    70    0     80    130   150   100   180   210   190   200   190
   d4   80    90    80    0     70    130   90    160   220   250   210   190
   d5   100   110   130   70    0     100   120   180   210   180   170   150
   d6   120   140   150   130   100   0     80    150   190   230   180   160
   d7   90    120   100   90    120   80    0     160   190   220   180   140
   d8   160   190   180   160   180   150   160   0     130   150   170   180
   d9   190   230   210   220   210   190   190   130   0     120   180   170
   d10  220   200   190   250   180   230   220   150   120   0     140   150
   d11  170   180   200   210   170   180   180   170   180   140   0     90
   d12  140   160   190   190   150   160   140   180   170   150   90    0;

Variable
   x(i,j)         
   y(i,j,k)           
   z                

Positive Variable x;
Binary Variable y;

Equation
   obj                 
   demandCon(i)        
   capacityCon(i,j)    
   routeCon(i,j,k)    
   yCon(i,j,k)         
   maxDistCon(i,j,k)  
   totalDemandCon(k)
;

obj .. 
   z =e= sum((i,j), cost(i,j) * x(i,j)) + sum((i,j,k), distance(i,k) * y(i,j,k));  

demandCon(i) ..
   sum(j, x(i,j)) =g= demand(i); 

capacityCon(i,j) ..
   x(i,j) =l= capacity(j); 

routeCon(i,j,k) ..
   y(i,j,k) =g= 0; 

yCon(i,j,k) ..
   x(i,j) =l= capacity(j) * y(i,j,k); 

maxDistCon(i,j,k) .. 
   sum(i, y(i,j,k)) =l= 3;  

totalDemandCon(k) .. 
   sum(i, demand(i) * y(i,j,k)) =l= capacity(j) * sum(i, y(i,j,k)); 

Model transport /all/;

Solve transport using mip minimizing z;

Display x.l, y.l, z.l;

Hi, please paste your code as preformatted text (use the </> button) to preserve e.g. the formatting of tables (I edited you post accordingly).

You can find a good explanation of how to avoid that error in the Fixing Compilation Errors Tutorial.

I hope this helps!

maxDistCon(i,j,k) ..
   sum(i, y(i,j,k)) =l= 3;

​You define the above equation for each (i, j, k) and inside this equation you sum over i. So when you access y(i, j,k), GAMS cannot determine whether the i in y(i, j, k) is the one over which the equation is defined or the one over which summation is carried out.

To avoid this confusion, you have to think about how your constraint is defined. In my opinion, you constraint should be defined over (j, k) instead of (i, j, k).

maxDistCon(j,k) ..
   sum(i, y(i,j,k)) =l= 3;

There are cases in which you really need to distinguish. You can use Alias in such cases.

The following will work too (but incorrect for this case)

alias(i, ii);
maxDistCon(i,j,k) ..
   sum(ii, y(ii,j,k)) =l= 3;