I have an mixed-integer linear optimization problem that includes a energetic difference equation for the temperature of a building for the time $t$:

$$T(t) = T(t-1) + \frac{E^{\rm Heating}(t)-E^{\rm Demand}(t)}{V\cdot \rho\cdot c}, t>1$$

I used to have the temperature in the constraints with a minimum and maximum value:

$$T_{\min}\leq T(t) \leq T_{\max}$$

Now I would like to transform it from a constraint to the objective function. So what I want is to quantify the violation of this "constrain" $Z$ and minimize it in the objective function. So the equations should actually look like this:

\begin{align}\text{if} \hspace{0,5cm}T(t) < T_{\min} &\implies Z(t) = T_{\min} - T(t)\\\text{if} \hspace{0,5cm}T(t) > T_{\max} &\implies Z(t) = T(t) - T_{\max}\end{align}

And in the objective function $\min \sum_{t} Z(t)$.

Now my question is, whether this is possible to define within a mixed-integer linear problem and if so, how can I do that?


1 Answer 1


Introduce nonnegative variables $Z^+(t)$ and $Z^-(t)$, impose linear constraints $$T_\min \le T(t)-Z^+(t)+Z^-(t) \le T_\max,$$ and minimize $$\sum_t (Z^+(t)+Z^-(t)).$$ Notice that this approach easily allows penalizing overage and underage differently, if you want, just by changing the objective coefficients.

  • $\begingroup$ Thanks for your answer. Can I just directly use it or do I have to implement something like a Big-M approach. Because I have some "if" conditions and there, from what I have seen, most often the Big-M approach is used. $\endgroup$
    – PeterBe
    Apr 27, 2022 at 7:47
  • $\begingroup$ You can use it directly, without introducing binary variables or big-M constraints. The objective will naturally drive your “if” conditions to be satisfied for every optimal solution. $\endgroup$
    – RobPratt
    Apr 27, 2022 at 12:12
  • 1
    $\begingroup$ Thanks a lot Pratt for your help. I really appreciate it. I upvoted and accepted your answer. $\endgroup$
    – PeterBe
    Apr 27, 2022 at 12:18

Your Answer

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

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