S
S
Sergey Sokolov2017-08-09 17:00:11
Mathematics
Sergey Sokolov, 2017-08-09 17:00:11

How to optimize searching for a combination of rows and columns in a matrix?

Given a matrix of ones and zeros. It is necessary to choose such a combination of columns and rows in it in order to maximize the ratio of the number of cells with "1" to the number of cells with "0". In this case, the more rows and columns involved, the better.
For example, here rows (0,1,3) with columns (0,3,5) give only one "0" for eight "1":

1 0 0 1 0 1
1 1 0 1 1 1
0 1 0 1 0 0
1 1 0 0 0 1

As I understand it, the problem is NP-complete, i.e. a full enumeration of all possible combinations is required. I would like to find such maximum samples on a fairly large number of rows and columns: from thousands to millions.
What are the algorithms that optimize this enumeration?
As a special case, you need to look for combinations without a single "0" at all.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Labunsky, 2017-08-09
@Labunsky

I didn't test it, but something like this:
1. We consider the sum of all values ​​of the matrix N, as well as the sum for each row and column M[] and the ratio 1 to 0 Z;
2. Subtract from N the minimum value among M: N -= min(M).;
3. "Remove" the row or column corresponding to min(M) from the matrix: subtract from each column or row (respectively) the values ​​at the intersection and update Z in parallel;
4. Compare Z with the previous value. If it has become more, return to step 2. If less, the combination has been found (undeleted rows and columns).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question