Conditions in constraints

Hello,

I am quite new to GAMS and would like some advice on how I could use conditions ($) in constraints.

  1. I have a constraint that is valid only upon certain condition. For example I have a constraint called ctFreez(p,t,a) with a variable q(p,t,a) where p,t,a are sets. For each review period a, I have a time period t of 8 weeks. I want to put a condition such that if current time period t (which means time period) is smaller or equal to 2, then the quantity of product p is equal to q(p,t,a-1), i.e. the value from the previous review period. Would the following work?:
    ctFreez(p,t,a)…q(p,t,a)$t<=2 =e= q(p,t,a-1)
    I read GAMS documents multiple times, but I wasn’t really sure whether I can put a condition like this.

    \
  2. I have a constraint that rules shelf-life. The following restricts inventory such that the current inventory can fulfill demand only up until t+shelf life.
    image.png
    For this constraint, I typed Alias(t, dt) where dt is t’ in the constraint. But how can I put an upper bound for the summation? (i.e. sum t’ up until t+Shelf life (Lambda)).


    Thanks a lot in advance for your help!

You are missing ord() operator : https://www.gams.com/latest/docs/UG_OrderedSets.html#UG_OrderedSets_TheOrdOperator

ctFreez(p,t,a)$(ord(t)<=2) …q(p,t,a)=e= q(p,t,a-1)

This should work.

Same for second question.
sum(dt $( (ord(dt) > ord(t)) and (ord(dt) <= ord(t) + lambda)) , …)

\

  • Atharv

Thank you so much! :smiley: