5

I would like to know how to define a constraint to set a limit for switching to 0 for a decision variable? So I have a linear variable $x(t)$ which quantifies the modulation degree of a heating device. It can be between $0$ (meaning that the device is switched off) and $1$ (meaning that the device is heating with full power). My $t$ is between $1$ and $288$ (timeslots for every $5$ minutes of $1$ day). As you can imagine it is not really good to change frequently between $0$ and a non-zero value because this would mean, that the heating device starts and stopps frequently during one day (sometime I have $5$ starts and stopps during $1$ hour) which should be avoided as it increases the wear of the device.

So I would like to set a limit to switching to 0 during one day. Is there a way how I could define a constraint for that? The rule in pseudocode is basically

if x(t-1)>0 and x(t)=0 then increase count by 1
Constraint: count <= limit

Do you have an idea how I could model that (if it is possible)? I'd appreciate every comment and would be thankful for your help.

Kuifje
  • 13,324
  • 1
  • 23
  • 56
PeterBe
  • 1,632
  • 2
  • 15
  • 30

1 Answers1

5

You can model this as follows. Let $y(t)\in \{0,1\}$ be a binary variable that is activated if the heating device is switched off at time $t\in \{1,...,288\}$ (and was active at time $t-1$).

This variable is activated every time $x(t-1)=1$ and $x(t)=0$: $$ x(t-1) \le x(t) + y(t)\quad \forall t=1,...,288 $$

So if $x(t-1)=1$, either $x(t)$ also takes value $1$ (and the device remains active), either $y(t)$ is activated.

You might want to minimize $\sum_{t=1}^{288}y(t)$ so that $y(t)$ is never activated "for free". Or you could also enforce this with additional constraints: $$ y(t)\le x(t-1) \quad \forall t=1,...,288\\ x(t)+y(t) \le 1 \quad \forall t=1,...,288 $$

And you can limit the number of activated variables to an upper bound $\ell$ (or equivalently, the number of times the device is switched off): $$ \sum_{t=1}^{288}y(t) \le \ell $$


EDIT:

If $x$ is continuous, you need to create a binary variable $b(t)$ that takes value $1$ when $x(t)>0$. You can do this with the following constraint: $$ x(t)\le b(t)\quad \forall t $$ And in the above approach, replace $x$ by $b$.

Kuifje
  • 13,324
  • 1
  • 23
  • 56
  • Thanks Kuifje for your answer. Basically x(t) is not a binary variable but a continuous variable with values BETWEEN 0 and 1 (so it can also have the value 0,432 for example). Does your approach also work with continuous variables? As far as I understand, it would not work because if x(t-1)=0,7 and x(t) = 0,3, y(t) would have to be 1 (as it is a binary variable). This would violate your 2nd and 3rd constraint. If y(t) would be 0, the 1st constraint would be violated. – PeterBe Apr 21 '21 at 10:16
  • a ok! in this case you need to create a binary variable for $x$. I will update. – Kuifje Apr 21 '21 at 10:32
  • Thanks a lot Kuifje for your answer. Now I would like to incrase the complexity a little bit but I am not sure whether this should be asked in a separate question. Basically the heating device can not only heat up one storage with x(t) but it can also heat up another storage system with another linear variable z(t) but not both at the same time (so x(t) + z(t)<=1). Now I would like to count and limit the starts and stopps of the heating device considering the 2 storage systems. So x(t-1) could be 1 and x(t) could be 0 and it would not count as a start if z(t) is bigger than 0. – PeterBe Apr 21 '21 at 14:11
  • 1
    glad to help! I suggest you post a new question which describes your full problem in detail. – Kuifje Apr 21 '21 at 14:23
  • Thanks Kuifje for your tremendous help. I upvoted and accepted your answer. – PeterBe Apr 21 '21 at 14:57
  • I just found a small mistake. You write that the equations should be valid for all t in 1,...,288. However when using a difference equation x(t-1) then you can't use it for t=1 as x(1-1) = x(0) is undefined becaue the set timeslots ranges from 1 to 288. – PeterBe May 12 '21 at 07:27
  • Hi Kuifje, are you sure that your suggested approach for linking the binary and the continous variable is correct? If x(t) has as value greater 0 then it is obvious that b(t) has the value 1. This is what I also see in the results of my model. But when x(t) has the value 0, then sometimes b(t) has the value 0 but sometimes it also has the value 1. To be totally honest, I do not see in your equations what prohibits b(t) to take the value 1 when x(t) has the value 0. – PeterBe May 17 '21 at 15:58
  • Yes you are right. This depends on what your cost function is, and if you have other constraints. If you want to constrain the model so that $b$ takes value $0$ if and only if $x=0$, then you can minimize $\sum_t b_t$ in your objective function. This way it will set $b_t$ to $1$ only if it really has no choice. – Kuifje May 17 '21 at 16:04
  • Thanks Kuifje for your answer. But I do not want to include this in my objective function as it should be a constraint and not an objective. How can implement this as a constraint? – PeterBe May 17 '21 at 16:06
  • I suggest you post the following new question: how to enforce $x=0; \Rightarrow b=0$, where $x$ is continuous and $\le 1$, and $b$ is binary. – Kuifje May 17 '21 at 16:08
  • Thanks for the answer Kuifje. I just posted a new question that you can see here: https://or.stackexchange.com/questions/6270/how-to-couple-a-binary-variable-to-a-continuous-variable-to-indicate-values-grea – PeterBe May 17 '21 at 16:38
  • When there is an anwer to the new question I would suggest to change your EDIT part of this answer because at the moment it is not entirely correct. – PeterBe May 17 '21 at 16:39
  • Ok, I will add a link to the answer when there is one. – Kuifje May 17 '21 at 16:43
  • Do you have a good reason to not just add $\sum b_t$ to the existing objective function ? – Kuifje May 18 '21 at 13:25
  • Somehow I have the impression that this is not a good idea and bad style. I would also not rule out that this would interfere with the 'real' objective. I think that there should be better ways of doing this. This is why I do not like this approach at all. – PeterBe May 18 '21 at 13:36