Represent SUMPRODUCT when one vector is binary

72 Views Asked by At

I have two vectors, one contains a series of integer values, the other contains a set of binary values.

Vector 1; integer values

Vector 2; binary values

In an integer programming formulation, how do I correctly represent the sum of the binary rows (which represent a value in Vector 1), where the Value in the binary vector is 1?

Example:

Vector 1:

2 4 5 2 5
7 3 1 2 3

Vector 2:

1 0 1 0 1
1 0 1 1 1

So the sum or row 1 in Vector 2 is 12, the sum of row 2 is 13. I need to represent this somehow but I'm not entirely sure how.

2

There are 2 best solutions below

2
On

Let's call the ranges as follows: the first row of vector 1 will be A1:A5, the second row B1:B5, the first row of vector 2 C1:C5, and the second row D1:D5. The use of SUMPRODUCT is easy. Just use =SUMPRODUCT(A1:A5, C1:C5), similarly for the other one.

0
On

I can suggest a MIP formulation. Let $x_i$ be the vector of binary variables (i.e. $x_i \in \{0,1\}$), and let $y_i \in \{0,\dots,U_i\}$ be your integer variable. Basically you want: $$\begin{align} &z_i = y_i \cdot y_i\\ &v = \sum_i z_i\end{align}$$ The product $z_i=y_i\cdot x_i$ is nonlinear but this can be linearized as follows: $$\begin{align} &0 \le z_i \le U_i x_i\\ &y_i-(1-x_i)U_i \le z_i \le y_i \end{align}$$