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
Cumulative sum
-
- User
- Posts: 118
- Joined: 7 years ago
- Location: Rosario - Argentina
Re: Cumulative sum
hi, you should define an alias. Try this code
bye!
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));
-
- User
- Posts: 5
- Joined: 3 years ago
Re: Cumulative sum
It worked, Thanks a lot for your response.
-
- User
- Posts: 5
- Joined: 3 years ago
Re: Cumulative sum
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) )
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) )
-
- User
- Posts: 118
- Joined: 7 years ago
- Location: Rosario - Argentina
Re: Cumulative sum
I think this can work...
bye!
Code: Select all
eq.. z =e= sum((i,j)$(ord(j) le ord(i)),x(j) - y(j));