# Optimization problem with if condition as constraint

I am trying to solve an optimization problem where the constraint contains absolute values and I am not sure how I can express this in a 'Pyomo-friendly' way.

Consider the following optimization problem:

$$\max_{b_{n}} \sum_{n} \space a_{n}(b_{n} - c_{n})$$

subject to $$a_{n} > 0$$ and $$b_{n} = \begin{cases} c_{n}, & |b_{n} - c_{n}|\leq \epsilon \\ b_{n}, & |b_{n} - c_{n}| > \epsilon \end{cases}$$.

As this is not a linear constraint, my guess is that this is not solvable. I also found this question where it is mentioned that there are some modelling tricks.

• Is $a_n>0$ for all $n$? Nov 28, 2022 at 19:59
• Yup, I will edit the post. Nov 28, 2022 at 20:03
• What are the optimization variables? Nov 29, 2022 at 11:11
• @RodrigodeAzevedo The $\max_{b_n}$ suggests that the $b_n$ are the variables and everything else is a constant, but my formulation works even if $c_n$ is also a variable. Nov 29, 2022 at 13:11
• @RobPratt Yes, indeed, but the "subject to $a_n > 0$" suggests something else. This confusion is avoided when people follow the convention of picking the first letters of the alphabet for knowns and the last letters of the alphabet for unknowns. Nov 29, 2022 at 13:53

It looks like you want to enforce the disjunction $$(b_n - c_n < -\epsilon) \lor (b_n - c_n = 0) \lor (b_n - c_n > \epsilon).$$ You can instead enforce the following disjunction: $$(b_n - c_n \le -\epsilon) \lor (b_n - c_n = 0) \lor (b_n - c_n \ge \epsilon).$$ Assume finite bounds $$L \le b_n - c_n \le U$$. Introduce binary variables $$x_n$$, $$y_n$$, and $$z_n$$, and impose the following linear constraints: \begin{align} x_n + y_n + z_n &= 1 &&\text{for all n}\\ Lx_n + 0y_n + \epsilon z_n \le b_n - c_n &\le -\epsilon x_n + 0y_n + Uz_n &&\text{for all n}\\ \end{align} Alternatively, omit $$y_n$$ and instead impose: \begin{align} x_n + z_n &\le 1 &&\text{for all n}\\ Lx_n + \epsilon z_n \le b_n - c_n &\le -\epsilon x_n + Uz_n &&\text{for all n}\\ \end{align}
• $L<-\epsilon < 0<\epsilon <U$ Nov 28, 2022 at 20:33