Hi guys,
I have a binary variable x(t) for every minute of a day (1440). This binary variable indicates if a heating device is on or off. Now I want to ensure that the device does not switch from on to off quite frequently. This is why I want to insert a restriction which ensures that if the heating device is switched on it should run for at least 10 minutes. This means that if x(t)=1 and x(t1)=0 the next 10 x(t)s should be 1. And of course the same with switching from on to off, meaning that if x(t)=0 and x(t1)=1 the next 10 x(t)s should be 0.
Is it possible to include that in a mip model in GAMS?
Ensuring realations between decision variables

 User
 Posts: 81
 Joined: 2 years ago
 Location: Rosario  Argentina
Re: Ensuring realations between decision variables
Hi again PeterBe, you can try this:
This can be fine but i'm not sure
Best regard!
Code: Select all
sets
t /1*1440/
;
alias(t,tp)
;
binary variable
x(t)
;
equation
eq1
eq2
;
eq1(t,tp)$(ord(t) gt 1 and ord(tp) gt ord(t) and ord(tp) le ord(t)+10).. 1  x(t) + x(t1) + x(tp) =g= 1;
eq2(t,tp)$(ord(t) gt 1 and ord(tp) gt ord(t) and ord(tp) le ord(t)+10).. x(t) + 1x(t1) + 1x(tp) =g= 1;
Best regard!
Re: Ensuring realations between decision variables
Hi Manassaldi,
it seems to work How did you derive those equations? Also with the basic steps?
Thanks a lot for your great help!
it seems to work How did you derive those equations? Also with the basic steps?
Thanks a lot for your great help!

 User
 Posts: 81
 Joined: 2 years ago
 Location: Rosario  Argentina
Re: Ensuring realations between decision variables
Hi, I used the basic steps with your logic proposition.
" if x(t)=1 and x(t1)=0 the next 10 x(t)s should be 1"
X(t) ^ ¬X(t1) => (X(t+1)^X(t+2)^X(t+3)^X(t+4)^X(t+5)^X(t+6)^X(t+7)^X(t+8)^X(t+9)^X(t+10))
or reduced:
X(t) ^ ¬X(t1) => ^(tp gt t and tp le t+10) X(tp)
" if x(t)=0 and x(t1)=1 the next 10 x(t)s should be 0"
¬X(t) ^ X(t1) => (¬X(t+1)^¬X(t+2)^¬X(t+3)^¬X(t+4)^¬X(t+5)^¬X(t+6)^¬X(t+7)^¬X(t+8)^¬X(t+9)^¬X(t+10))
or reduced:
¬X(t) ^ X(t1) => ^(tp gt t and tp le t+10) ¬X(tp)
I think that you can add the equations "eq3" and "eq4" where x0 correspond to the status of the previously day:
Bye!
" if x(t)=1 and x(t1)=0 the next 10 x(t)s should be 1"
X(t) ^ ¬X(t1) => (X(t+1)^X(t+2)^X(t+3)^X(t+4)^X(t+5)^X(t+6)^X(t+7)^X(t+8)^X(t+9)^X(t+10))
or reduced:
X(t) ^ ¬X(t1) => ^(tp gt t and tp le t+10) X(tp)
" if x(t)=0 and x(t1)=1 the next 10 x(t)s should be 0"
¬X(t) ^ X(t1) => (¬X(t+1)^¬X(t+2)^¬X(t+3)^¬X(t+4)^¬X(t+5)^¬X(t+6)^¬X(t+7)^¬X(t+8)^¬X(t+9)^¬X(t+10))
or reduced:
¬X(t) ^ X(t1) => ^(tp gt t and tp le t+10) ¬X(tp)
I think that you can add the equations "eq3" and "eq4" where x0 correspond to the status of the previously day:
Code: Select all
eq3(t,tp)$(ord(t) eq 1 and ord(tp) gt ord(t) and ord(tp) le ord(t)+10).. 1  x(t) + x0 + x(tp) =g= 1;
eq4(t,tp)$(ord(t) eq 1 and ord(tp) gt ord(t) and ord(tp) le ord(t)+10).. x(t) + 1x0 + 1x(tp) =g= 1;
Re: Ensuring realations between decision variables
Hi guys,
quite a long time ago I posted the question that you can see in the first post:
Now I want to adjust the above mentioned condition such that:
 If the heating device is on  meaning either x(t) =1 or y(t) =1  then it should not be switched off for the next 10 timesteps > so eighter x(tp)=1 or y(tp)=1 should be valid for t<tp<=10
 If the heating device is off  meaning x(t) =0 and y(t)=0  then it should not be switched on for the next 10 timesteps > x(tp) =0 and y(tp) =0 should be valid for t<tp<=10
Does anyone have an idea how I can do that. It would help me a lot and I'd really appreciate any input. Thanks in advance
quite a long time ago I posted the question that you can see in the first post:
Now I want to extend that model by having another binary variable y(t) that is used for the same heating device but for another storage. That means if x(t)=1 storage A is heated up by the heating device whereas when y(t) =1 storage B is heated up. As we only have one heating device only one storage can be heated up at every timestep t: x(t) + y(t)<=1I have a binary variable x(t) for every minute of a day (1440). This binary variable indicates if a heating device is on or off. Now I want to ensure that the device does not switch from on to off quite frequently. This is why I want to insert a restriction which ensures that if the heating device is switched on it should run for at least 10 minutes. This means that if x(t)=1 and x(t1)=0 the next 10 x(t)s should be 1. And of course the same with switching from on to off, meaning that if x(t)=0 and x(t1)=1 the next 10 x(t)s should be 0.
Now I want to adjust the above mentioned condition such that:
 If the heating device is on  meaning either x(t) =1 or y(t) =1  then it should not be switched off for the next 10 timesteps > so eighter x(tp)=1 or y(tp)=1 should be valid for t<tp<=10
 If the heating device is off  meaning x(t) =0 and y(t)=0  then it should not be switched on for the next 10 timesteps > x(tp) =0 and y(tp) =0 should be valid for t<tp<=10
Does anyone have an idea how I can do that. It would help me a lot and I'd really appreciate any input. Thanks in advance

 User
 Posts: 81
 Joined: 2 years ago
 Location: Rosario  Argentina
Re: Ensuring realations between decision variables
Hi Peter, I think that with the auxiliary variable "on(t)" can work.
If on(t)=1 x(t) or y(t) = 1
If on(t)=0 x(t) and y(t) = 0
eq1(t).. x(t) + y(t) =l= 1;
eq2(t).. 1on(t) + x(t) + y(t) =g= 1;
eq3(t).. on(t) + 1x(t) =g= 1;
eq4(t).. on(t) + 1y(t) =g= 1;
eq5(t,tp)$(ord(t) gt 1 and ord(tp) gt ord(t) and ord(tp) le ord(t)+10).. 1  on(t) + on(t1) + on(tp) =g= 1;
eq6(t,tp)$(ord(t) gt 1 and ord(tp) gt ord(t) and ord(tp) le ord(t)+10).. on(t) + 1on(t1) + 1on(tp) =g= 1;
Best!
If on(t)=1 x(t) or y(t) = 1
If on(t)=0 x(t) and y(t) = 0
eq1(t).. x(t) + y(t) =l= 1;
eq2(t).. 1on(t) + x(t) + y(t) =g= 1;
eq3(t).. on(t) + 1x(t) =g= 1;
eq4(t).. on(t) + 1y(t) =g= 1;
eq5(t,tp)$(ord(t) gt 1 and ord(tp) gt ord(t) and ord(tp) le ord(t)+10).. 1  on(t) + on(t1) + on(tp) =g= 1;
eq6(t,tp)$(ord(t) gt 1 and ord(tp) gt ord(t) and ord(tp) le ord(t)+10).. on(t) + 1on(t1) + 1on(tp) =g= 1;
Best!
Re: Ensuring realations between decision variables
Thanks Manassaldi for your answer, it seems to work, except for the very first two time slots. There the heating in stopped after 2 timeslots (which is not nice but not a big problem)