4

How can one model the following condition in an integer linear program?

$$A = \begin{cases} 1 & \text{if } B > C\\ 0 & \text{otherwise}\end{cases}$$

where $A \in \{0,1\}$ and $B, C \in \mathbb N$. We have upper and lower bounds on both $B$ and $C$.

Salah
  • 91
  • 1
  • 1
  • 6

5 Answers5

1

The second inequality of the answer of Salah doesn't hold if $B=C$. I think the correct answer is the following two inequalities:

$$ B \geq C + 1 - M (1-A) $$ $$ B \leq C + M A $$

where $M$ is an upperbound on $|B-C| + 1$.

The first inequality restricts $A$ to $0$ if $B \leq C$.

For example, if $B=0$ and $C=0$, then

$$ 0 \geq 0 + 1 - M(1-A) \rightarrow A = 0 $$

The second inequality restricts $A$ to $1$ if $B > C$.

For example, if $B=1$ and $C=0$, then

$$ 1 \leq 0 + M A \rightarrow A = 1 $$

JobS
  • 11
  • 2
1

I think I found the answer here! It is sufficient to use the big-M method by introducing the following constraints:

B >= C + 1 - M*(1-A);

C >= B + 1 - M*A

Salah
  • 91
  • 1
  • 1
  • 6
0

This is another possibility for the "greater or equal" and "lower or equal" version. For the pure greater and pure lower version you must remove the +1 resp. -1 from first constraint. You must also add a +1 to the second constraint "... >= yM+1".

enter image description here

FXG
  • 101
0

Is it possible to enforce this through your objective function? For instance, if your objective function was $$\max A,$$ the constraint $$A\leq (B-C) M,$$ where $M$ is a "big-$M$" (large value) will work provided B is larger than C by some tolerance. The tolerance will be $\frac{1}{M}$, i.e. $B-C \geq \frac{1}{M}$ before the constraint is properly enforced.

Dylan Black
  • 156
  • 1
  • 4
0

If you are in a MILP setting, then I think the following should work. Assume $\underline{B},\underline{C}$ and $\overline{B},\overline{C}$ are your respective lower/upper bounds. Then the constraint $$A \geq \frac{B-C}{\overline{B}-\underline{C}}$$ ensures that $A=1$ if $B-C$ is positive, since the RHS of the equation is between 0 and 1 in this case. When $B-C$ is negative, then the constraint is useless. The constraint $$\frac{\underline{C}-\overline{B}}{C-B}\geq A$$ ensures that $A=0$ if $B-C$ is negative, for similar reasons.

Seb Destercke
  • 348
  • 2
  • 8