Assume you have a linear expression, e.g. the summation of a set of decision variables \(\sum_{i}{x_i}\), and you need to detect when it is in the interval \([A, B]\) by capturing that information in a binary variable called \(status\).

In that case, let \(auxbin_a\) and \(auxbin_b\) be auxiliary binary variables. Then, you can enforce the desired behavior by defining the following constraints:

- \(A*status - BigM*(1-status) \leq \sum_{i}{x_i}\)
- \(\sum_{i}{x_i} \leq B*status + BigM*(1-status)\)
- \(\sum_{i}{x_i} - A + 1 \leq BigM*auxbin_a\)
- \(B - \sum_{i}{x_i} + 1 \leq BigM*auxbin_b\)
- \(status \geq auxbin_a + auxbin_b -1\)

To see why this works, consider the following scenarios:

- If \(\sum_{i}{x_i} < A\), then:
- \(status = 0\) because of constraint 1.
- \(auxbin_b = 1\) because of constraint 4.
- \(auxbin_a = 0\) since \(status = 0\), \(auxbin_b = 1\), and because of constraint 5.

- If \(\sum_{i}{x_i} > B\), then:
- \(status = 0\) because of constraint 2.
- \(auxbin_a = 1\) because of constraint 3.
- \(auxbin_b = 0\) since \(status = 0\), \(auxbin_a = 1\), and because of constraint 5.

- If \(A \leq \sum_{i}{x_i} \leq B \), then:
- \(auxbin_a = 1\) because of constraint 3.
- \(auxbin_b = 1\) because of constraint 4.
- \(status = 1\) since \(auxbin_a = 1\), \(auxbin_b = 1\), and because of constraint 5.

**Note:** if the interval's upper bound \(B = \infty\), then one must omit constraints 2 & 4, and replace constraint 5 with \(status \geq auxbin_a \).

**Note:** if the interval's lower bound \(A= -\infty\), then one must omit constraints 1 & 3, and replace constraint 5 with \(status \geq auxbin_b \).

**Further Information:**

## Comments

0 comments

Article is closed for comments.