5

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$

SAH
  • 294
  • 1
  • 11

2 Answers2

7

$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
Betty
  • 544
  • 4
  • 16
user3680510
  • 3,655
  • 6
  • 26
4

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;
minimize
 costBus40*nbBus40  +nbBus30*costBus30;

subject to
{
 40*nbBus40+nbBus30*30>=nbKids;

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

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

/*
which gives

nbBus40 = 0;
nbBus30 = 10;

*/
Alex Fleischer
  • 4,000
  • 5
  • 11