Given a matrix of boolean values (example):
a b c
+--------
X | 1 0 1
Y | 1 1 1
Z | 0 1 1
+--------
What’s the optimum way to find all sequences [a|b|c] such that each sequence has at least one “true” (1) value for each of X, Y and Z.
In the example above, the set of sequences is (in no particular order):
abc, ab, ac, bc, c
Whereas these sequences do not satisfy the requirement:
a (doesn't provide Z)
b (doesn't provide X)
I’m actually looking for a generalized algorithm for an arbitrary matrix.
Any ideas?
Basically you’re solving
X & Y & ZwhereX = a | c,Y = a | b | c,Z = b | cfora,bandc.So basically you’re looking for all solutions of SAT on a formula in conjunctive normal form. Although some simplifications exist, basically any approach will be O(2N). The algorithms for efficiently finding a solution of this class of problem are listed in the wikipedia article; however if you want all solutions you will be iterating over 2N possibilities anyway, so simply enumerating them and testing will suffice.
A few trivial optimisations:
andall the values in a column and get 1, then that column is a basis for a solution (that column and any selection of other columns is a solution)orall the values in a column and get 0, then that column does not contribute to the basis of any solutionSince it is a 2N problem, it is reasonable to assume that N<64, and so you can make some implementation optimisations, but you won’t reduce the size of the problem.