Problems with syntax of GAMS
meelih
User
Posts: 4
Joined: 10 months ago

Hi, i have two questions about sum notation

Think that i have a set
t /1*10/

and i have a binary variable x(t)

questions

1) How can i sum x(t) starting from t=2

2) How can i exclude t values which i want
that is:
I want to say that sum(t, x(t)) =e= 1 BUT i dont want this equation include t=9 and t=10 for example.
Or i want to say that sum(t, x(t)) =e= 1 again BUT starting from t=2 and ending at t=7 while t is /1*10/

Manassaldi
User
Posts: 65
Joined: 1 year ago
Location: Rosario - Argentina

Hello, you have many alternatives:

sets
t /t1*t10/
;
(1) sum(t\$(ord(t) ge 2),x(t))
(2) sum(t\$(ord(t) ne 9 and ord(t) ne 10),x(t)) =e= 1
sum(t\$(ord(t) ge 2 and ord(t) le 7),x(t)) =e= 1

using subsets:
sets
t /t1*t10/
sum1(t) /t2*t10/
sum2(t) /t1*t8/
sum3(t) /t2*t7/
;
(1) sum(t\$sum1(t),x(t))
(2) sum(t\$sum2(t),x(t)) =e= 1
sum(t\$sum3(t),x(t)) =e= 1

for example, if you want to avoid t=2 and t=6:
sets
t /t1*t10/
avoid(t) /t2,t6/
;
sum(t\$(not avoid(t)),x(t)) =e= 1 (includes all t except t=2 and t=6)

Bye!