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.
How to model a binary variable that can only happen once a year?
Re: How to model a binary variable that can only happen once a year?
Code: Select all
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 do much more complex set manipulations in GAMS separately and use those sets to define equations. For example you could do
Code: Select all
set t/1*36/;
set tt(t);
tt(t)$(mod(ord(t), 12) =1) = yes;
display tt;
- Atharv