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)
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):
Note that the value for the constant 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?).
Code: Select all
constraint1.. a =l= b + bigM*i; constraint2.. a =g= b + 1e-6 - bigM*(1-i);
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:
To avoid this, logical expressions are modeled with the help of big-M constraints as shown above. Alternatively, one can model logical expressions using logic equations (e.g. using the =b= notation) with GAMS model type EMP or JAMS/LOGMIP.
Code: Select all
constraint1$(i=0).. a =l= b; constraint2$(i=1).. a =g= b + 1e-6;