Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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. \begin{equation} u = \begin{cases} \sigma_w - x & x < \sigma_l \\ 0 & x > \sigma_l \end{cases} \end{equation}

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.

share|cite|improve this question
up vote 1 down vote accepted

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 \\ $

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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