How to model a binary variable that can only happen once a year?

Hello,

I have a set t which is the total number of months and a binary variable b(t).
I want to have a constraint that sets b(t) less or equal to 1 each year in a single constraint.
I can do this with predetermined time periods and multiple constraint like for example with 36 months:
eq1… sum(t (ord(t) >=1 and ord(t) <= 12), b(t)) =l= 1; eq2.. sum(t (ord(t) >=13 and ord(t) <= 24), b(t)) =l= 1;
eq3… sum(t $ (ord(t) >=25 and ord(t) <= 36), b(t)) =l= 1;

Is there a way to do this in a single line and generalize for multiple years?

Thank you.

alias(t, tt);
eq(tt)$(mod(ord(tt), 12) = 1).. sum(t $ (ord(t) >=ord(tt) and ord(t) <= ord(tt) + 12), b(t)) =l= 1;

You can check the equations are correct by displaying all constraints using option limrow = 10.

You can do much more complex set manipulations in GAMS separately and use those sets to define equations. For example you could do

set t/1*36/;
set tt(t);
tt(t)$(mod(ord(t), 12) =1) = yes;
display tt;

In the above code, you can use set tt to define your equations. In short, there are many ways but what I show above is one of those.

  • Atharv