**Here is an example of the big-M method:**

If you have a logical expression

*i=1 <=> a>b*, where

*i*is a binary variable and

*a*and

*b*are free variables that can take any real value. You can reformulate this as follows:

*a <= b + bigM*i*

a > b - bigM*(1-i)

a > b - bigM*(1-i)

To interpret these constraints, a good way is to consider both values of the binary variable, in this case,

*i*. If

*i=1*, the first constraint will not be active if

*bigM*is big enough while the second constraint ensures

*a>b*. If

*i=0*, the first constraint ensures

*a<=b*while the second will not be active if

*bigM*is big enough. Since there are no strict "greater than" constraints in mathematical programming, you need to rewrite the second constraint as

*a >= b + epsilon - bigM*(1-i)*, where

*epsilon*is a small number (e.g.,

*1e-6*):

Code: Select all

```
constraint1.. a =l= b + bigM*i;
constraint2.. a =g= b + 1e-6 - bigM*(1-i);
```

*bigM*can usually be calculated from the data of the problem, just making it "big" can cause numerical problems with solvers (see How large should BIG M be?).

It should be further noted that using variables in a $-condition is not allowed. The $-condition must depend on data only. Therefore, the error "Endogenous $-control operations not allowed" appears if you try to model logical expressions as follows:

Code: Select all

```
constraint1$(i=0).. a =l= b;
constraint2$(i=1).. a =g= b + 1e-6;
```