5.8. Some constraints that take advantage of integer/binary variables#
At most two of the projects 1, 2, 3, 4 and 5 can be done:
If project 1 is done then also project 2 is done:
Restrict the variable \(x_i\) to have just one of a given set of integers {2,3,5,7} \(\to\) let \(y_1\),\(y_2\),\(y_3\),\(y_4\) be binary, and add the constraints:
Either-or constraints#
Satisfy only one of these two constraints depending on something else in the model:
Replace with the following two constraints:
where \(y\) is a binary variable and M is sufficiently large. When \(y\) is 1 the second constraint is active and the first is relaxed (\(\leq\) big number), when \(y\) is 0, the inverse happens.
If \(x_1\) happens (it has the value 1) then \(x_2\) cannot happen and vice-versa. Both can be zero as well meaning both will not happen, as \(x_1+x_2\leq 1\).
Discontinuous variables#
If you want to impose that in some situations \(x\) can only be defined as:
Introduce the binary variable \(y\) and add the following constraints:
In this way when \(y\) is 0, \(x\) is zero, and when it is 1 then \(x\) is between \(u\) and \(l\).
The product of two binary variables#
As you know, in linear programming you cannot multiply two variables but this does not mean that you cannot use some constraints to produce that product. The product \(x_1x_2\) of two binary variables \(x_1\) and \(x_2\) can be replaced by additional binary variable \(y\) by adding the following constraints:
with \(M\) sufficiently large. The \(y\) variable will be the result of multiplying \(x_1\) for \(x_2\).
The product of a binary and a continuous variable#
The product \(x_1x_2\) of the binary variable \(x_1\) and the continuous variable \(x_2\) with \(0\leq x_2\leq u\) can be replaced by an additional continuous variable \(y\) by adding the following constraints:
\(y\) is obviously the continuous variable you want to get.
Attribution
This chapter is written by Gonçalo Homem de Almeida Correia, Maria Nogal Macho, Jie Gao and Bahman Ahmadi. Find out more here.