how to use an expression as a subscript

helle,community.
i’m a beginner in gams,please give me ideas.
i want to use an expression as a subscript for binary variables.

Some of the formulas to calculate are as follows:
ΣiΣp Σl wipl*zi<j+6-i>pl≦T (∀j)
Σlzijpl=yjp (∀i,j,p)

is modulo,means mod(a,n).

itry this,

sets
i  /1*6/
p  /1*4/
l  /0*5/
j  /0*9/;

binary variables 
y(j,p),z(i,*,p,l);

variables
T;

parameters
Wipl(i,p,l) /omitted/
n  /10/

equations
total(j)
zy(i,j,p);

total(j)..sum((i,p,l),Wipl(i,p,l)*z(i,[color=#FF4000]((j+6-i)-n*((j+6-i)/n)[/color],p,l))=l=T;
zy(i,j,p)..sum(l,z(i,j,p,l))=e=y(j,p);

GAMS 24.9.2 r64480 Released Nov 14, 2017 WEX-WEI x86 64bit/MS Windows

There are many errors in the red part. An error($198) occurs even if the red part is a simple formula.

]Hi Rina

Note that set elements even if they are numbers, are not treated as numbers but like strings. Therefore, you can’t do the typical operations like i+j. The trick is to use either the ord operator (gives you the position of the set element as integer) or the value of the set element by adding “.val”.
If you are indexing, you can add integers to the index, (e.g. a(i+1), meaning the next element after i.

The second thing to notice is that you can use the dollar sign to restrict summations (and other stuff). Read the $-sign as “such that…”.
In your case, we have the following equation:

total(j)..sum((i,p,l),Wipl(i,p,l)*z(i,((j+6-i)-n*((j+6-i)/n),p,l))=l=T;

and here how I would rewrite this:

sets
    i  /1*6/
    p  /1*4/
    l  /0*5/
    j  /0*9/;

binary variables 
y(j,p),z(i,j,p,l);

variables
T;

parameters
Wipl(i,p,l) 
n  /10/;
wipl(i,p,l) = uniform(0,1);
equations
total(j)
zy(i,j,p);
* We need an alias of p to do the restriction on the summation.
alias(p,pp);
total(j)..sum((i,p,l),Wipl(i,p,l)*
    sum(pp$(pp.val = j.val + 6 -i.val - n*((j.val+6-i.val)/n)),z(i,j,pp,l)))=l=T;

Try to go through this code and read about the use of the $-sign in the documentation. If you have more questions, do not hesitate to ask them.
Cheers
Renger

Thank you very much, Renger.
i will challenge! :smiley: