Hi guys,
I am pretty new to GAMS - don't think this is gonna be hard for someone with experience.
I'd like to create a cumulated sum.
Please find the equation I'd like to implemet in the attached file.
I therefore defined a set t with several periods and a set m with several product variant types.
x(m,t) is a binary variable assigning t to m.
Now for every t I need the cumulated amount of x(m,t) in the respective period y(m,t).
Hence, I declared the sum to start with t'=1 an sum up to the currently considered t.
I'm pretty sure I somehow have to work with an alias and a $-(ord)condition here.
This is what I got so far, but something is missing:
Sets m / 1, 2, 3 /
t / 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 /;
alias (t,tt);
y(m,t) =e= Sum((t$(ord(t) =l= ord(tt)), x(m,t));
I'd apperciate your help!
Thanks
Marc
Cumulated sum
Cumulated sum
- Attachments
-
- Formel.png (1.46 KiB) Viewed 2832 times
-
- User
- Posts: 108
- Joined: 7 years ago
Re: Cumulated sum
I believe GAMS now has special ordered sets support, but I don't use them so I can't really help you in that direction.
This is a correct syntax for what you're trying to write.
eq(m,t).. y(m,t) =e= Sum((tt$(ord(t)>=ord(tt)),x(m,tt));
This is a correct syntax for what you're trying to write.
eq(m,t).. y(m,t) =e= Sum((tt$(ord(t)>=ord(tt)),x(m,tt));