# integer programming formulation problem

Consider a problem with three variables: $u$, $\sigma_l$, and $\sigma_w$ where $\sigma_w > \sigma_l$. I want to represent the following relationship using integer programming. $$u = \begin{cases} \sigma_w - x & x < \sigma_l \\ 0 & x > \sigma_l \end{cases}$$

Using simple either-or constraints (with a binary variable and big M) I can get the correct value for the cases where $x > \sigma_w$ and the case where $x < \sigma_l$, however when $x \in (\sigma_l , \sigma_w)$ these either-or constraints fail. To show you what I have tried thus far, I write the either-or constraints I tried:

$0 \leq u \leq Mz\\ \sigma_l - x + z(\sigma_w - \sigma_l) \leq u \leq \sigma_l - x + z(\sigma_w - \sigma_l) + M(1-z)$

where $z \in \{0,1\}$ and $M$ is an arbitarily large number.

-

After thinking further, the following either-or constraints do the trick. So, when $x<\sigma_l$, then $z$ must equal one and $u$ is set to $\sigma_w-x$. Otherwise, $z=0$ and $u=0$
$0 \leq x - \sigma_l + Mz\\ 0 \leq -u + Mz \\ x - \sigma_l \leq 0 + M(1-z) \\ \sigma_w - x \leq u \leq \sigma_w - x + M(1-z) \\ u \geq 0 \\$