Cumulative sum

Problems with syntax of GAMS
Post Reply
omnia_nabil
User
User
Posts: 5
Joined: 3 years ago

Cumulative sum

Post by omnia_nabil »

I want to write a summation equation that represents the following:

x1 <= y1
x1 + x2 <= y1+y2
x1 + x2 + x3 <= y1 +y2 + y3
x1 + x2 + x3 + x4 <= y1 + y2 + y3 + y4
x1 + x2 + x3 + x4 + x5 <= y1 + y2 + y3 + y4 + y5
x1 + x2 + x3 + x4 + x5 + x6 <= y1 + y2 +y3 +y4 + y5 + y6
________________________________________________________
GAMS code:

Set i /1*6/;

Variables
x(i)
y(i)
;

Please help me in writing this cumulative equation in GAMS
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: Cumulative sum

Post by Manassaldi »

hi, you should define an alias. Try this code
bye!

Code: Select all

Set i /1*6/;
alias(i,j)
Variables
x(i)
y(i)
;
equation
eq
;

eq(i).. sum(j$(ord(j) le ord(i)),x(j)) =l= sum(j$(ord(j) le ord(i)),y(j));
omnia_nabil
User
User
Posts: 5
Joined: 3 years ago

Re: Cumulative sum

Post by omnia_nabil »

It worked, Thanks a lot for your response.
omnia_nabil
User
User
Posts: 5
Joined: 3 years ago

Re: Cumulative sum

Post by omnia_nabil »

I have another question related to this topic:

I want to write an equation that represents the following:

z= (x1 - y1)
+ ( (x1+x2) - (y1+y2) )
+ ( (x1+x2+x3) - (y1+y2+y3) )
+ ( (x1+x2+x3+x4) - (y1+y2+y3+y4) )
+ ( (x1+x2+x3+x4+x5) - (y1+y2+y3+y4+y5) )
+ ( (x1+x2+x3+x4+x5+x6) - (y1+y2+y3+y4+y5+y6) )
Manassaldi
User
User
Posts: 118
Joined: 7 years ago
Location: Rosario - Argentina

Re: Cumulative sum

Post by Manassaldi »

I think this can work...

Code: Select all

eq.. z =e= sum((i,j)$(ord(j) le ord(i)),x(j) - y(j));  
bye!
omnia_nabil
User
User
Posts: 5
Joined: 3 years ago

Re: Cumulative sum

Post by omnia_nabil »

Thanks a lot.
Post Reply