Thursday, May 15, 2008

Multiplication of a continuous and a binary variable

The expression \(z = x \cdot \delta \) where \(x\) is a continuous variable and \(\delta\) is a binary variable can also be linearized fairly easily. The exact form depends on the bounds of \(x\). Assume \(x\) has lower bound \(x^{lo}\) and upper bound \(x^{up}\), then we can form the inequalities:
\[\boxed{\begin{split}\min\{0,x^{lo}\} &\le z \le \max\{0,x^{up}\} \\
x^{lo} \cdot \delta &\le z \le x^{up} \cdot \delta \\
x − x^{up} \cdot (1 − \delta) &\le z \le x − x^{lo} \cdot (1 − \delta)\end{split}}\]
The last restriction is essentially a big-M constraint:
\[\boxed{x − M_1 \cdot (1 − \delta) \le z \le x + M_2 \cdot (1 − \delta)}\]
where \(M_1\), \(M_2\) are chosen as tightly as possible while not excluding \(z=0\) when \(\delta=0\).

For the special case \(x^{lo}=0\) this reduces to:
\[\boxed{\begin{split}& z \in [0,x^{up}]\\ & z ≤ x^{up} · \delta\\ & z ≤ x\\ & z ≥ x − x^{up} · (1 − \delta)\end{split}}\]
The construct \(z=x· \delta\) can be used to model an OR condition: "\(z = 0\) OR \(z = x\)".


  1. Hey i have a problem where i have a function called average_price = a+b*x where x is a variable for the amount of products, a and b is constants from a table. The problem is when we have to find the total price/cost, (a+b*x)*x this makes the non-linear error.. do you have any suggestions ??

  2. Continuous * Continuous variable means either use a QP or NLP algorithm or formulate a piecewise linear function.

  3. Hello,
    I have used this formulation in two terms of my model that one of them are directly get involved in the objective function. However, I discovered that the corresponding term in the objective function makes the model computationally complicated.
    I.e., let R be the linear product of two variables ( acontinuous and a binary one). When I run the model without R in the objective function, the model is being solved in less than 1 minute, but, it will take more than 2 hours with R in the objective function.

    Do you know that it is the nature of this formulation, or I did something wrong?

    1. This cannot be answered without much more knowledge about the model, the formulation and the solver.

    2. Thank you
      So I will mail the model and details to you if you permit?

  4. This has been really helpful for me in model construction. Thanks a lot!!!

  5. Thank you, that was helpful. It would be better if the last two constraints to be used were clearly highlighted.