I am trying to sum over a subset between $t+1$ and $t+U-1$ as follows $$y_i^t+\sum_{k=t+1}^{t+Ut_i-1}z_i^k\le1$$ but I could not define the condition within sum.

Here is what I have tried:

y(i,t) + sum(t $(ord(t)=t+1 and ord(t)<= t+gendata(i,"U")-1) ,z(i,j)) =l= 1;

  • $\begingroup$ Welcome to OR.SE. One possible way would be defining two parameters as $UB$ and $LB$ in the pre-processing and filter the inner loop (on the summation) based on. Would you try that? $\endgroup$
    – A.Omidi
    Mar 6, 2021 at 15:37
  • $\begingroup$ You mean like this: Parameters LB 'lower limit'; LB= t+1; Parameters UB 'Upper limit'; UB= j+gendata(i,"MUP")-1; Uptime2.. u(i,j) + sum(j, $ (ord(j)>= LB AND ord(j)<= UB) ,v(i,j)) =l= 1; $\endgroup$
    – Tamam
    Mar 6, 2021 at 17:02
  • $\begingroup$ I meant something like this, just in the summation, you have to apply $ operator before comma. sum((j)$ (ord(j)>= LB AND ord(j)<= UB, ...). I recommend that first defining a global set on the planning horizon, set t /1...T/, then alias that by other index like $k$. $\endgroup$
    – A.Omidi
    Mar 6, 2021 at 19:55
  • $\begingroup$ I surely hope that GAMS produced a ton of error messages for this input. I usually start by studying the first error message, fix it, recompile and repeat. $\endgroup$ Mar 6, 2021 at 22:15
  • $\begingroup$ Related: GAMS Sum over a subset $\endgroup$ May 5, 2021 at 20:41

1 Answer 1

eq(t) .. y(i,t) + sum(t $(ord(k)<=t+1 and ord(k)<= ord(t)+gendata(i,"U")-1)  ,z(i,k)) =l= 1;

Just make sure that k is a subset of t This way alias(k,t);

  • $\begingroup$ It would help if you could add an exposition to your code. $\endgroup$
    – TheSimpliFire
    May 3, 2021 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.