Algorithmic approach to creating all combinations based on a large truth table

Apologies if this was given elsewhere, but I haven't found it yet using my limited algorithmic terminology.;)

My situation is this: I have a variable number of data items, each of which is checked against each other against data items to determine compatibility. Compatibility is stored in the equivalent of a two-dimensional array (truth table?). My goal is to create every possible combination of these items, where every item in combination is compatible with every other item.

For example, if item 1 (of 4) was compatible with items 2 and 4, and item 2 was compatible with 1, 3, and 4, item 3 was compatible with 2, and item 4 was compatible with 1 and 2, my truth table would be look something like this:

1) {1,1,0,1}
2) {1,1,1,1}
3) {0,1,1,0}
4) {1,1,0,1}

The combinations I want from this would be:
1.2.4
1.2
1.4
1
2.3
2.4
2
3
4

My approach works well in a lot of situations, but sometimes it gets very cluttered when the number of items exceeds 5000, depending on the datasets. My secondary concern is to define a pattern that provides a runtime of 5 seconds to 3 hours ...

Just by looking at a boolean array, I just feel like there MUST be an easier solution - perhaps an algorithm named for someone. As you might deduce from the above, I don't necessarily know how to ask the question.;)

Thank you for your time!

+2


source to share


2 answers


I think that you have an "adjacency matrix", not a truth table, and that you are looking for all the "fully connected subgraphs" of the graph, of which the adjacency matrix is ​​the view. Fully linked subgraphs are also known if memory serves as "clicks". I'm not really sure what you're looking for; as one of the early respondents said, there are some discrepancies between your words and your matrix.

Do some searches on these terms; right now, it's too late for me to get this stuff out of my head or my library.

Note that your graph is symmetrical, that is, if "1 is compatible with 2", then "2 is compatible with 1". Now that data storage requirements have halved (they made them more complex, storing the top or bottom half of the matrix is ​​often more mind bending than the space it stores orders in). I also think that you should probably have 1s on the main diagonal to express the idea that "1 is compatible with 1". In the end, I suspect you will have some elements that are only compatible with yourself.



Finding clicks on the graph is unfortunately NP, but for matrices of only 5000x5000 elements, a naive brute-force algorithm shouldn't take too long in a compiled language.

Hello

Mark

+4


source


Basically you are trying to reduce the expression to disjunctive normal form. In general, this problem is NP-complete. I'm sorry. ^ _ ^



+1


source







All Articles