I am working on an Energy Management problem. The objective is to minimize the electricity bill for the customer.

I have a time-series data with 15 min. intervals spanning the course of 1 year. The main controllable system is a hot water boiler which can be switched $ON$ or $OFF$, $1$ or $0$ respectively.

These are the requirements:

  • The boiler can only be switched (either $ON \rightarrow OFF$ or $OFF \rightarrow ON$) max. $n$ times a "day"
  • The "day" is not necessarily considered from 12:00AM to 12:00AM but it can be from 06:00AM to 06:00AM or any other 24 hour duration, it depends on the customer

I understand that there is a way to generate this constraint for 1 day using:
$\sum_{t=0}^{95} abs(b_{t+1} - b_t) \leq n$
where, $b_t$: boiler status at time $t$

But this uses $abs()$ which makes the problem non-linear. The entire problem, constraints and objective function are linear and hence, this constraint must also be linear. Any suggestions would be appreciated.

I am using Pyomo for optimization and the data is present as a Pandas Dataframe.


1 Answer 1


The abs function is piecewise linear, so you can represent it with two linear inequalities as shown in https://docs.mosek.com/modeling-cookbook/linear.html#absolute-value.

In your case, $\sum_{t=0}^{95} abs(b_{t+1} - b_t) \leq n$ can be formulated as $$\sum_{t=0}^{95} u_t \leq n,\quad u_t \geq abs(b_{t+1} - b_t).$$ and thus linearized as $$\sum_{t=0}^{95} u_t \leq n,\quad -u_t \leq b_{t+1} - b_t \leq u_t.$$

  • $\begingroup$ what does $\Delta b_t$ represent? is $\Delta b_t = b_{t+1} - b_t$? $\endgroup$ Commented May 23 at 8:40
  • 1
    $\begingroup$ I updated my answer renaming $\Delta b_t$ to $u_t$ to avoid confusion. $\endgroup$ Commented May 23 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.