Ensuring realations between decision variables

Problems with modeling
Post Reply
PeterBe
User
User
Posts: 64
Joined: 1 year ago

Ensuring realations between decision variables

Post by PeterBe » 1 year ago

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(t-1)=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(t-1)=1 the next 10 x(t)s should be 0.

Is it possible to include that in a mip model in GAMS?

Manassaldi
User
User
Posts: 71
Joined: 1 year ago
Location: Rosario - Argentina

Re: Ensuring realations between decision variables

Post by Manassaldi » 1 year ago

Hi again PeterBe, you can try this:

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(t-1) +   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) + 1-x(t-1) + 1-x(tp) =g= 1;
This can be fine but i'm not sure
Best regard!

PeterBe
User
User
Posts: 64
Joined: 1 year ago

Re: Ensuring realations between decision variables

Post by PeterBe » 1 year ago

Hi Manassaldi,

it seems to work :-) How did you derive those equations? Also with the basic steps?

Thanks a lot for your great help!

Manassaldi
User
User
Posts: 71
Joined: 1 year ago
Location: Rosario - Argentina

Re: Ensuring realations between decision variables

Post by Manassaldi » 1 year ago

Hi, I used the basic steps with your logic proposition.
" if x(t)=1 and x(t-1)=0 the next 10 x(t)s should be 1"
X(t) ^ ¬X(t-1) => (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(t-1) => ^(tp gt t and tp le t+10) X(tp)

" if x(t)=0 and x(t-1)=1 the next 10 x(t)s should be 0"
¬X(t) ^ X(t-1) => (¬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(t-1) => ^(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) + 1-x0 + 1-x(tp) =g= 1;
Bye!

PeterBe
User
User
Posts: 64
Joined: 1 year ago

Re: Ensuring realations between decision variables

Post by PeterBe » 9 months ago

Hi guys,

quite a long time ago I posted the question that you can see in the first post:
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(t-1)=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(t-1)=1 the next 10 x(t)s should be 0.
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)<=1

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

Manassaldi
User
User
Posts: 71
Joined: 1 year ago
Location: Rosario - Argentina

Re: Ensuring realations between decision variables

Post by Manassaldi » 9 months ago

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).. 1-on(t) + x(t) + y(t) =g= 1;
eq3(t).. on(t) + 1-x(t) =g= 1;
eq4(t).. on(t) + 1-y(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(t-1) + 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) + 1-on(t-1) + 1-on(tp) =g= 1;

Best!

PeterBe
User
User
Posts: 64
Joined: 1 year ago

Re: Ensuring realations between decision variables

Post by PeterBe » 9 months ago

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)

Post Reply