7

How to express a chain of boolean If-then as MIP such as:

If $(x_{10} \ge b_1$ and $x_{11} \le b_1)$ AND $(x_{20} \ge b_2$ and $x_{21} \le b_2)$... AND... then $y_1 = 1$ else $y_1 = 0$.

So basically, if constants are between values of different $x_0$ and $x_1$ (lower and upper bounds for every constant) then $y = 1$, if at least one constant is out of bound then $y = 0$. I need to maximize sum of all $y$.

dhasson
  • 1,667
  • 1
  • 9
  • 21
GregK
  • 71
  • 2
  • AFAIK, some commercial solvers like CPLEX or GUROBI have had such capability to write such constraints directly in the static model. Would you see this link? – A.Omidi Jan 21 '20 at 05:40

1 Answers1

7

Because you are maximizing the sum of $y$, as long as each $y$ appears in no other constraints, you can get by with enforcing only one direction of the implication, namely $$y_1=1\implies (x_{10}\ge b_1 \land x_{11}\le b_1 \land \dots).$$ You can do this with one big-M constraint for each inequality, where $\ell$ and $u$ are (constant) lower and upper bounds on $x$: \begin{align} b_1-x_{10}&\le (b_1-\ell_{10})(1-y_1)\\ x_{11}-b_1&\le (u_{11}-b_1)(1-y_1)\\ b_2-x_{20}&\le (b_2-\ell_{20})(1-y_1)\\ x_{21}-b_2&\le (u_{21}-b_2)(1-y_1)\\ &\dots \end{align}

RobPratt
  • 32,006
  • 1
  • 44
  • 84