Set is under control already

Hi, All,
I found a strange thing when dealing with sum syntax.
The model works if I choose
DATA(‘CTOTS’,J2)=DATA(‘CTOTS’,J2)*sum(I2,DATA(I2,‘RTOTS’))/P_scale;
where
P_scale=sum(J2,DATA(‘CTOTS’,J2));

However, if I simple replace P_scale
DATA(‘CTOTS’,J2)=DATA(‘CTOTS’,J2)*sum(I2,DATA(I2,‘RTOTS’))/sum(J2,DATA(‘CTOTS’,J2));
GAMS will report “Set is under control already”

The full code is attached. Thanks in advance.

Best/JG


Set I
    I2(I)
    J
    J2(J);

Scalar P_scale;


TABLE DATA(I<,J<)

             COL1          COL2       COL3          COL4        RTOTS
ROW1         0             3            2             7           100
ROW2         11            4            3            11            50
ROW3         18            6            0             7            30
ROW4          8            5            5             0            10
CTOTS        80            50          30            30
*=========================================================================*
;

I2(I)$(not sameas(I,"CTOTS"))= YES;
J2(J)$(not sameas(J,"RTOTS"))= YES;


DATA(I2,'RTOTS')=100;
DATA('CTOTS',J2)=sum(i2,DATA(i2,j2));

P_scale=sum(J2,DATA('CTOTS',J2));
DATA('CTOTS',J2)=DATA('CTOTS',J2)*sum(I2,DATA(I2,'RTOTS'))/P_scale;
*DATA('CTOTS',J2)=DATA('CTOTS',J2)*sum(I2,DATA(I2,'RTOTS'))/sum(J2,DATA('CTOTS',J2));


Display DATA;

You are writing this statement for each J2 (there is a J2 on the left hand side). When you write sum(J2,…) there is no way to distinguish between the J2 that you are using in sum and the one on the left hand side. Therefore you get this error.

You can use alias.

alias(j2, j2p);

you can then use

DATA(‘CTOTS’,J2)=DATA(‘CTOTS’,J2)*sum(I2,DATA(I2,‘RTOTS’))/sum(J2P,DATA(‘CTOTS’,J2P));

Hope this helps.

  • Atharv

Thanks, Atharv. It works!