How to convert this if-then constraint to MIP constraint?

$\text{if } a \geq 0 \text{ then } b=K_1 \text{ else(a <0 ) } \ b =K_2$


2 Answers 2


$a \geq M_1x$

$a \leq M_2 - (M_2+eps)x$

$b = K_1 + (K_2-K_1)x$

  • $M_1 < 0$ bigM for the lower bound on $a$
  • $M_2 > 0$ bigM for the upper bound on $a$
  • $x$ binary variable equal to $1$ if $a < 0$, $0$ otherwise (i.e. $a \geq 0$)
  • $eps$ tolerance

I would like to remind that CPLEX can handle "if then" directly through logical constraints.

In OPL for example:

int nbKids=300;
float costBus40=500;
float costBus30=400;

dvar int+ nbBus40;
dvar int+ nbBus30;
 costBus40*nbBus40  +nbBus30*costBus30;

subject to

 // with if nb buses 40 more than 3  then nb buses30 more than 7

 //(nbBus40>=3)<=(nbBus30>=7); //equivalent

which gives

nbBus40 = 0;
nbBus30 = 10;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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