270 likes | 435 Views
Boolean Satisfiability. The most fundamental NP-complete problem, and now a powerful technology for solving many real world problems. Overview. CNF, SAT, 3SAT and 2SAT Resolution and Unit Propagation DPLL search Conflict-driven Nogood Learning Activity-based Search Modelling for SAT.
E N D
Boolean Satisfiability The most fundamental NP-complete problem, and now a powerful technology for solving many real world problems
Overview • CNF, SAT, 3SAT and 2SAT • Resolution and Unit Propagation • DPLL search • Conflict-driven Nogood Learning • Activity-based Search • Modelling for SAT
Conjunctive Normal Form • SAT solvers solve problems in • Conjunctive Normal Form (CNF) • Boolean variable: b(true/false) or (0/1) • Literal: lvariable bor its negation –b • negating a literal: -l = -bifl = b, and -l = bif l = -b • Clause: C disjunction or set of literals • CNF: theory T set of clauses • Assignment: set of literals A with {b,-b} not subset: e.g. {-b1,b2} Assign b1=false, b2=true
Boolean Satisfiability (SAT) • This is the most basic NP-complete problem. • SAT: Given a set of clauses T, find an assignment A such that for each C in T • Each clause C in T is satisfied by A
3SAT • 3SAT: SAT with the restriction that each clause has length at most 3. • SAT -> 3SAT • {l1, l2, l3, l4, l5, l6} l1 ∨ l2 ∨ l3 ∨l4 ∨l5 ∨l6 becomes the set of clauses • {l1, l2, b1}, {-b1, l3, b2}, {-b2, l4, b3}, {-b3, l5, l6} where b1, b2, b3 are new Boolean variables • 3SAT is NP-complete (by the above reduction)
2SAT • 2SAT: SAT with the restriction that each clause has length at most 2. • 2SAT is decidable in polynomial time (n3) • 2SAT is NL-complete • which is a crazy complexity class • Nondeterministic Turing machine with log writeable memory!
Resolution • The fundamental inference for CNF • {l1, l2, l3, b} {-b, l4, l5, l6} implies • {l1, l2, l3, l4, l5, l6} • Or • (l1 ∨l2 ∨l3 ∨b) ∧ (-b∨l4 ∨l5 ∨l6) -> l1 ∨l2 ∨l3 ∨l4 ∨l5 ∨l6 • One can prove unsatisfiability of a CNF formula by repeatedly applying all possible resolutions • if this generates an empty clause then UNSAT • otherwise SAT • Exponential process!
Unit Propagation • Resolution = too expensive • Unit Propagation (=unit resolution) • Restricted form of resolution = finds unit clauses • {l1, l2, …, ln, l} where –liin A forall 1 ≤ i≤ n • Add lto assignment A • {-b1, b2, b} A = {b1, -b2} • {-b1, b2, b} A := {b1, -b2, b} • (-b1 ∨b2 ∨b) ∧b1 ∧ -b2 -> b
Unit Propagation • Repeatedly apply unit propagation, • until no new unit consequences can be found • or failure detected • A = {b1, -b2, b3, -b4} C = {-b1, -b3, b4} • {-b1, -b3, b4} • Failure detected
Unit Propagation Example • T = {{-e11,-e21}, {-e11,-e31},{-e11,-e41}, {e21,-b21}, {e31,-b31},{e41,-b41}, {b21,-b51},{b51,-b52,e52},{b41,-e52}, • A = {e11,b52} {-e11,-e21} {-e11,-e31} {b51,-b52,e52} {-e11,-e41} {-e21,-b21} {b21,-b51} {-e31,-b31} {b41,-e52} {-e41,-b41} A ={e11,b52,-e21,-e31} A ={e11,b52,-e21,-e31,-e41} A = false A ={e11,b52,-e21} A ={e11,b52,-e21,-e31,-e41,-b21,-b31} A ={e11,b52,-e21,-e31,-e41,-b21} A ={e11,b52,-e21,-e31,-e41,-b21,-b31,-b41,-b51} A ={e11,b52,-e21,-e31,-e41,-b21,-b31,-b41} A ={e11,b52,-e21,-e31,-e41,-b21,-b31,-b41,-b51,e52} -e21 -b21 -b51 e52 e11 -e31 -b31 b52 fail -e41 -b41
Implication Graph • Records the reason why each Boolean literal became true • Decision • Propagation(and why) • Used for nogood reasoning! -e21 -b21 -b51 e52 e11 -e31 -b31 b52 fail -e41 -b41
DPLL search • Davis-Putnam-Logemann-Loveland algorithm • interleave decisions + unit propagation • dpll(A) A' = unitprop(A) if A' == false return false else if exists Boolean variable bnot appearing in A if dpll(A' union {b}) return true else if dpll(A' union {-b}) return true else return false else return true
DPLL Search Example {-b1,-b4,-b5} {-b1,-b4,b5} {-b2,b3} {b4,-b5} {b4,b5} X X {} X X b1 X {b1} {-b1} X b2 X b2 {b1,b2,b3} {b1,-b2} {-b1,b2,b3} b4 b4 b3 {-b1,b2,b3 b4} {b1,b2,b3, b4,b5,fail} {b1,b2,b3, -b4,b5,fail} {b1,-b2,b3} b4 b5 {b1,-b2,b3, b4,b5,fail} {b1,-b2,b3, -b4,b5,fail} {-b1,b2,b3 b4,b5}
DPLL search with nogood learning • dpll(A) A' = unitprop(A) if A' == false Add a clause C explaining the failure to T Backjump to the first place C can give new information else if exists Boolean variable bnot appearing in A if dpll(A' union {b}) return true else if dpll(A' union {-b}) return true else return false else return true
Nogood Learning • The implication graph shows a reason for failure • Any cut separating the fail node from decisions • explains the failure b52∧ -b51 ∧-e41false b52∧ -b51 ∧-b41false b52∧e11false e52∧ -b41false {b41,b51,-b52} {e41,b51,-b52} {-e11,-b52} {b41,-e52} b52 -e21 -b21 -b51 e52 e11 -e31 -b31 fail -e41 -b41
Which Nogood? • SAT solvers almost universally use the • First Unique Implication Point (1UIP) Nogood • Closest nogood to failure • only one literal from the last decision level • Asserting: on backjump it will unit propagate • General: more general than many other choices • Fast: doesn’t require too much computation • replace last literal in nogood until only one at last level
1UIP Nogood Creation e11 -e21 -b21 -b21 b22 e22 e22 -e31 -b31 -b31 -e32 -e32 -b32 -b32 b33 b33 e33 e33 fail -e41 -b41 -b41 -e42 -e42 -b42 -b42 b43 b43 e43 e43 -b51 b52 e52 1 UIP Nogood {-b21,-b31,-b41,e22,-e32}false {-b21,-b31,-b41,-e32,-e42}false {-b21,-b31,-b41,e22}false {-b21,-b41,-e42,-b32}false {-b21,-b32,-b42}false {-b21,-b32,-b42,b33}false {-b32,-b42,b33,b43}false -b42 ∧ b43 ∧e33 false e33 ∧e43 false {-e33,-e43} {b32,b42,-b33,-b43} {b21,b41,e42,b32} {b42,-b43,-e33} {b21,b32,b42} {b21,b31,b41,-e22} {b21,b31,b41,-e22,e32} {b21,b31,b41,e32,e42} {b21,b32,b42,-b33}
Backjumping e11 • Backtrack to second last level in nogood • Nogood will propagate • e.g. {b21,b31,b41,-e22} -e21 -b21 -e22 -b22 -e31 -b31 -e41 -b41 {b21,b31,b41,-e22} -b52 -b51 Continue unit propagation then make next choice
Why Add Nogoods • We will not make the same choices again • {e11,b52} leads to failure • After choosing e11 we infer –b52 • Better yet, any choice that leads to b21,b31,b41 prevents the choice b52 • Drastic reduction in search space • Faster solving
DPLL Search Example Again {-b1,-b4,-b5} {-b1,-b4,b5} {-b2,b3} {b4,-b5} {b4,b5} {} {b4,-b1} b1 b2 {b1} {b4,-b1,b2,b3} {b1,-b4,-b5,fail} b2 b5 Nogood {b4} {b1,b2,b3} {b4,-b1,b2,b3,b5} b4 {b1,b2,b3, b4,b5,fail} Backjump Nogood {-b1,-b4}
Restarts • Periodically • Restart the search from the beginning! • Stored nogoods prevent search doing the same thing again • New search decisions drive search to new places
Activity • Each time a Boolean variable is seen during nogood creation, i.e. • appears in final nogood, or • is eliminated in the reverse propagation • Increase activity by one • These variables are helping cause failure • Periodically divide all activities by some amount • activity reflects helping cause recent failure
Activity-based Search • Select the unfixed variable with highest activity • MiniSat: set to false • RSAT: set to the last value it took • works with backjumping to recreate the same path • e.g. -b1, b3, -b11, b4, -b5, b7, fail • backjump to -b1, b3, -b11 • If b4 is now highest activity variable set it true [b4] • If b5 is next highest activity variable set it false [-b5] • Activity-based search • concentrates on the variables causing failure • learns shorter nogoods by failing earlier
Activity-based Search • Works well with restart • On restart we concentrate on the now most active variables • a new part of the search space • learn new nogoods about this
Modern SAT Solvers • Modern SAT solvers can handled problems with • (low) millions of clauses • millions of variables assuming the input has structure • Random CNF is much harder (but uninteresting) • Before the advent of nogood learning • (low) thousands of clauses • hundreds of variables
SAT Successes • Hardware model checking; Software model checking; Termination analysis of term-rewrite systems; Test pattern generation (testing of software &hardware); Model finding; Symbolic trajectory evaluation; Planning; Knowledge representation; Games (n-queens, sudoku, etc.); Haplotype inference; Pedigree checking; Equivalence checking; Delay computation; Fault diagnosis; Digital filter design; Noise analysis; Cryptanalysis; Inversion attacks on hash functions; Graph coloring; Traveling salesperson;
The Future • SAT Modulo Theories • combine theory propagators with SAT solving • Lazy Clause Generation • combine constraint propagators with SAT solving • Extended Clause Resolution • introduce new literals during resolution to exponentially shorten proofs • Parallelism • adapt to new multi-core computing environment