8

There are two non-negative integer variables $q$ and $p$, where only one of them can take a positive value. To impose this relation, I write: \begin{align} q &\leq M(1 - y) \tag1 \\ p &\leq M(y) \tag2 \end{align}

where $y$ is binary and $M$ is a large number.

Is there a better way to model this relation, possibly without binary and/or big-M?

RobPratt
  • 32,006
  • 1
  • 44
  • 84
Mostafa
  • 2,104
  • 10
  • 28

1 Answers1

11

The big-M values need not be the same. You should choose $M_1$ in $(1)$ to be a small upper bound on $q$ and $M_2$ in $(2)$ to be a small upper bound on $p$.

An alternative formulation is $p q = 0$, but that is nonlinear.

If your solver supports indicator constraints, you can write the desired implications directly, without specifying big-M: \begin{align} y = 1 &\implies q = 0 \\ y = 0 &\implies p = 0 \end{align} But the solver might just introduce the big-M constraints on your behalf.

If your solver supports SOS1 constraints, you can use those, but again these might be automatically converted to big-M constraints.

SecretAgentMan
  • 1,895
  • 2
  • 13
  • 39
RobPratt
  • 32,006
  • 1
  • 44
  • 84