Algorithms for SAT and k-sat problems On solutions that don t require bounded treewidth Pauli Miettinen Pauli.Miettinen@cs.Helsinki.FI Department of Computer Science - p. 1/23
- p. 2/23
Problem definitions Problem definitions Hamming balls Codes and Covering codes Example of covering codes Summarization of notations The propositional satifiability problem for Boolean formulas in conjunctive normal form ([CNF-]SAT) is as follows. Problem 1 ([CNF-]SAT). Given a boolean formula F in conjunctive normal form, is there an assignment A for F such that A satisfies F? A variation of this is the k satisfiability problem (k-sat). Problem 2 (k-sat). Given a boolean formula F in k conjunctive normal form, is there an assignment A for F such that A satisfies F? Both problems (with k > 2) are well known to be NP-complete. - p. 3/23
Hamming balls Problem definitions Hamming balls Codes and Covering codes Example of covering codes Summarization of notations A Hamming distance between two vectors u and v in H n = {0, 1} n is n d(u, v) = u i v i, i=1 i.e., the number of positions where u and v differ. The Hamming ball of radius R around an assignment A is the set of all assignments whose Hamming distance to A is at most R, i.e., B(A, R) = {A H n d(a, A ) R}. The volume of some ball with radius R in H n is R ( ) n V (n, R) =. i i=0 - p. 4/23
Codes and Covering codes Problem definitions Hamming balls Codes and Covering codes Example of covering codes Summarization of notations A code of length n is just a subset of H n. The covering radius R of a code C is R = max min d(u, v), u H n v C i.e., how far are the furthest assignments from this code. The normalized covering radius ρ is R/n. The covering code of radius R is a code C s.t. B(v, R) = H n. v C - p. 5/23
Example of covering codes Problem definitions Hamming balls Codes and Covering codes Example of covering codes Summarization of notations B(A 1, R) H n B(A 4, R) B(A 2, R) R B(A 3, R) - p. 6/23
Summarization of notations Problem definitions Hamming balls Codes and Covering codes Example of covering codes Summarization of notations n is the number of variables and m is the number of clauses in given formula F. k is the number of variables per clause in formulas in k-cnf, k > 2. H n = {0, 1} n is a Hamming space; A = (a i ) {0, 1} n is an assignment; d(, ) is the Hamming distance; B(A, R) H n is a (Hamming) ball of radius R and V (n, R) is the volume of such ball. C H n is a code and ρ is its normalized covering radius. h( ) is the binary entropy function, h(x) = x log 2 x (1 x) log 2 (1 x). - p. 7/23
- p. 8/23
Other work Hey, where s sums of products? of this presentation is to introduce some algoritmic techniques for SAT randomized local search deterministic local search to present following algorithms: a deterministic O((2 2/(k + 1)) n ) local search algorithm for k-sat; a randomized algorithm for SAT that runs in expected time O(m 2 2 n 0.712 n ); a deterministic O(m 2 2 n 2 n/ log 2 n ) local search algorithm for SAT. - p. 9/23
Other work A related work done by other people is listed below. The means that we are going to see a faster algorithm and the means that we are going to see a slower algorithm. Problem Deter./Rand. (Expt.) time Faster? Misc. 3-SAT Rand. O(1.324 n ) 4-SAT Rand. O(1.474 n ) k-sat Rand. O(2 (1 µ k k 1 )n+o(n) ) k > 4, µ k k 3-SAT Deter. O(1.505 n ) k-sat Deter. O(2 (1 1 2k )n ) k 5, limit SAT Rand. O(m2 n n 1+log 2 m ) SAT Deter. O(2 n ) trivial π2 6 - p. 10/23
Hey, where s sums of products? Other work Hey, where s sums of products? What are the relations to the previous presentations? this is not exactly a sums-of-products-type of thing [Mikko Koivisto, initial lecture] complexity is not related to some hard-to-measure quality of input formula Then why? algorithmic techniques can be generalized to other problems as well - p. 11/23
- p. 12/23
Local search within Hamming balls Local search within Hamming balls Local search cont d An example of BALL-CHECKING Multistart local search Covering codes Given a formula F, an assignment A H n and a radius R. Does F have a satisfying assignment within B(A, R)? Check all assignments A B(A, R). But it takes O(mV (n, R)) time, which is quite much. Let s call this naïve method a FULL-BALL-CHECKING procedure - p. 13/23
Local search cont d Given a formula F and an assignment A H n, can we solve efficiently does F have a satisfying assignment within a Hamming ball of radius R centered in A? Yes, we can! In time O(mk R ). The simple algorithm BALL-CHECKING(F, A, R) is as follows: 1. If A satisfies F, return A; if R 0 or F contains an empty clause, return no. 2. Choose a shortest clause (l 1 l k ) in F that is falsified by A. 3. For i = 1... k Call BALL-CHECKING(F i, A i, R 1) where F i is F with l i set to and A i is obtained from A by flipping the value of l i. If this call returns an assignment, return it. 4. return no. - p. 14/23
An example of BALL-CHECKING Initial values: Local search within Hamming balls Local search cont d An example of BALL-CHECKING Multistart local search Covering codes F = (x 1 x 2 x 3 ) (x 4 x 5 x 6 ) ( x 1 x 2 x 6 ), A = (0, 0, 0, 0, 0, 0), R = 2 Select the first clause and make a recursive call Values after setting x 1 = : F 1 = ( x 2 x 3 ) (x 4 x 5 x 6 ) ( x 2 x 6 ) = (x 4 x 5 x 6 ) (x 2 x 6 ), A = (1, 0, 0, 0, 0, 0), R = 1 Set x 4 = and make a recursive call F 1,4 = ( x 5 x 6 ) (x 2 x 6 ) = (x 2 x 6 ) A 1,4 = (1, 0, 0, 1, 0, 0), R = 0 - p. 15/23
Multistart local search Local search within Hamming balls Local search cont d An example of BALL-CHECKING Multistart local search Covering codes Multistart local search is a simple technique: select a random initial solution perform a local search from that solution if, after some amount of steps, the algorithm has not found an answer, select another random initial solution iterate this for a fixed number of times or until an answer is found It is a common method if the local search may go further from the answer. Quality can be improved if the initial solutions are chosen cleverly. - p. 16/23
Covering codes What would be a clever initial solution for SAT? Local search within Hamming balls Local search cont d An example of BALL-CHECKING Multistart local search Covering codes Covering codes might do well Take a covering code C s.t. its radius R is small enough and it has few enough codes in it. Alas, such a covering code is a bit contradictory. But, for any n 1 and r, there exists a covering code C of length n, covering radius at most r, and size at most n2 n /V (n, r) n nρ(1 ρ) 2 (1 h(ρ))n Such covering code gives quite good initial solutions! Let s leave the construction of such codes (fast enough) as a homework but it can be done! - p. 17/23
- p. 18/23
An algorithm for k-sat An algorithm for k-sat A randomized algorithm for SAT A deterministic algorithm for SAT A figurative example The algorithm is as follows 1. Set ρ = 1/(k + 1) 2. Generate a covering code C of length n and radius at most ρn. 3. For each A C, run BALL-CHECKING(F, A, ρn). Return true if at least one call returns an assignment; otherwise return false. Generating C takes p(n) (2 3n/6 + 2 (1 h(ρ))n ) time, where p is a polynomial depending only on n. C consists of p(n) 2 (1 h(ρ))n balls with radius ρn. BALL-CHECKING takes p(n) k ρn time per ball. The algorithm works in time p(n) (2 2/(k + 1)) n. - p. 19/23
A randomized algorithm for SAT An algorithm for k-sat A randomized algorithm for SAT A deterministic algorithm for SAT A figurative example Given formula F and two numbers R and l such that 0 R l n, a random algorithm is 1. N = 8R(1 R/n) 2 n(1 h(r/n)). 2. Repeat N times: (a) Choose an assignment A uniformly at random. (b) If F contains a clause that has at least l literals falsified by A and at most R literals satisfied by A, invoke FULL-BALL-CHECKING(F, A, R); otherwise invoke BALL-CHECKING(F, A, R). If the invoked procedure finds a satisfying assignment, return yes. 3. Return no. With R = 0.339 n and l = 1.87 n, the expected running time of algorithm is at most p(n) m 2 2 n 0.712 n. - p. 20/23
A deterministic algorithm for SAT An algorithm for k-sat A randomized algorithm for SAT A deterministic algorithm for SAT A figurative example Given formula F and two numbers R and l such that 0 R l n, a deterministic algorithm is 1. Generate a covering code C of length n and radius at most R. 2. For each A C: (a) If F contains a clause that has at least l literals falsified by A and at most R literals satisfied by A, invoke FULL-BALL-CHECKING(F, A, R); otherwise invoke BALL-CHEKCING(F, A, R). If the invoked procedure finds a satisfying assignment, return yes. 3. return no. With R = 2 n and l = log 2 e log 2 e log 2 n 2 n log2 n, algorithm runs in time at most p(n) m 2 2 n 2 n/ log 2 n. - p. 21/23
A figurative example An algorithm for k-sat A randomized algorithm for SAT A deterministic algorithm for SAT A figurative example - p. 22/23
Thank You! - p. 23/23