Presentation is loading. Please wait.

Presentation is loading. Please wait.

© R.A. Rutenbar 2009 Slide 1 Carnegie Mellon (Lec 06) Boolean Satisfiability: SAT Solvers (Pt 1) What you know  Representation and manipulation via BDDs,

Similar presentations


Presentation on theme: "© R.A. Rutenbar 2009 Slide 1 Carnegie Mellon (Lec 06) Boolean Satisfiability: SAT Solvers (Pt 1) What you know  Representation and manipulation via BDDs,"— Presentation transcript:

1 © R.A. Rutenbar 2009 Slide 1 Carnegie Mellon (Lec 06) Boolean Satisfiability: SAT Solvers (Pt 1) What you know  Representation and manipulation via BDDs, mainly  Lets us do computational Boolean algebra, solve (ie, satisfy ) Boolean equations What you don’t know  That there’s another way to do this  Called “SAT solvers”  I give you a big Boolean equation in a special form  Tool tells me either (a) it’s satisfiable and returns an assignment of the variables or (b) it’s unsatisfiable, no such assignment exists  This is a whole different approach...

2 © R.A. Rutenbar 2009 Slide 2 Carnegie Mellon Some Terminology Satisfiability (called “SAT” for short)  Give me an appropriate representation of a Boolean function  (X), where X=(x1, x2, … xn}  Find an assignment of the variables X* so that  (X) = 1  Note – this assignment need not be unique. Could be many satisfying solutions  But if there are no satisfying assignments at all – prove it, and return this info Many things that you can do with BDDs, can also do with SAT  But SAT is especially aimed at scenarios where you need to solve for a satisfying assignment…  …or prove that there is no such satisfying assignment

3 © R.A. Rutenbar 2009 Slide 3 Carnegie Mellon Consider: Verification via Reachability For basic FSM equivalence, we ended up with this problem  Goal: solve the resulting Boolean equation, to see if we could satisfy it to make a “1”, which indicated we had non-equivalent FSMs  Note: needed BDDs to tell when reachability analysis terminates, to compute R k but the problem is the BDD may be too expensive to build and store in memory

4 © R.A. Rutenbar 2009 Slide 4 Carnegie Mellon BDDs versus SAT BDD properties  Represents all possible satisfying assignments in paths from root to “1” leaf  Cannot always build it – may require too much memory  Really a data structure, with a set of useful associated algorithms. Satisfiability is really sort of a “side effect” for BDDs  Disadvantage for “just solve it” applications is you still need to build the entire BDD data structure before you can get even one soln Today  BDDs most commonly used for applications where the goal is Boolean manipulation  Not best solution for “just solve it” tasks SAT properties  Does not obtain all possible satisfying assignments. Just finds one, if it exists  Cannot always finish the computation – may require too much CPU time to finish  Really an algorithm, not just a data structure. All SAT does is solve for satisfying assignment, or tell you “none”  Advantage for “just solve it” applications is that this is all that SAT solvers are designed to do: return one answer fast, or say “no!” Today  SAT solvers most commonly used for applications where the goal is “ solve it ”  Not really a solution for the cases where you need heavy duty Boolean manipulation

5 © R.A. Rutenbar 2009 Slide 5 Carnegie Mellon Standard SAT Form: CNF Conjunctive Normal Form (CNF) = Standard POS form Why CNF is useful  Need only determine that one clause evals to “0” to know whole formula evals to “0”  Of course, to satisfy the whole formula, you must make all clauses identically “1”.  = ( a + c ) ( b + c) ( ¬a + ¬b + ¬c)

6 © R.A. Rutenbar 2009 Slide 6 Carnegie Mellon Assignment to a CNF Formula An assignment …  …gives values to some, not necessarily all, of the variables xi in X.  Complete assignment: assigns all the variables values.  Partial assignment: some, not all, of the variables have values Assignment means we can evaluate status of the clauses  Suppose a=0, b=1 but c, d are unassigned  = ( a + ¬b ) (¬a + b + ¬ c) ( a + c + d ) ( ¬a + ¬b + ¬c)

7 © R.A. Rutenbar 2009 Slide 7 Carnegie Mellon How Do We “Solve” Something Like This? Recursively  (Are you surprised?) Strategy has two big ideas  DECIDE:  Pick a variable and assign its value  Simplify the CNF formula as far you can  Hope you can decide if it’s SAT, yes/no, without further work  DEDUCE:  Look at the newly simplified clauses  You may be able to iteratively simplify, based on the structure of these clauses, and the value of the partial assignment  Apply this idea until nothing else simplifies. If you can decide SAT yes/no, great. If not, then you have to recurse some more, back up to DECIDE

8 © R.A. Rutenbar 2009 Slide 8 Carnegie Mellon How Do We “Solve” Something Like This?  = ( x + y + z)( ¬x + y )( ¬y + z ) ( ¬x + ¬y + ¬z)

9 © R.A. Rutenbar 2009 Slide 9 Carnegie Mellon Some Definitions and Notation  = ( x + y + z)( ¬x + y )( ¬y + z ) ( ¬x + ¬y + ¬z) Search is organized as a “decision tree”  At every level, you make a decision to assign a variable to a value  Nodes in the tree correspond to these variable decisions  Depth of the tree is the decision level of the variable Notation  Assign var x to value= v at level d of tree x=v@d  These really label the edges of the tree

10 © R.A. Rutenbar 2009 Slide 10 Carnegie Mellon Deduction = Boolean Constraint Propagation (BCP) Big idea behind BCP  Given a set of fixed variable assignments, what else can you “ deduce ” about necessary assignments by “ propagating constraints ” Lots of general strategies; most famous is “Unit Clause Rule”  A clause is said to be “ unit ” if it has exactly one unassigned literal  A unit clause has exactly one way to be satisfied, ie, pick polarity that makes clause=“1”  This choice is called an “implication”  Example: suppose a=1 and b=1  = ( a + c ) ( b + c) ( ¬a + ¬b + ¬c)

11 © R.A. Rutenbar 2009 Slide 11 Carnegie Mellon BCP is Iterative – Run Until No More Implications Assumptions  Partial assignment is x9=0 x10=0 x11=0 x12=1 x13=1 To start…  What are the results of the obvious simplifications when we actually assign these variables?  = (  1 )(  2 )(  3 )(  4 )(  5 )(  6 )(  7 )(  8 )(  9 )  1 = ( ¬x1 + x2 )  2 = ( ¬x1 + x3 + x9)  3 = ( ¬x2 + ¬x3 + x4)  4 = ( ¬x4 + x5 + x10)  5 = ( ¬x4 + x6 + x11)  6 = ( ¬x5 + ¬x6)  7 = ( x1 + x7 + ¬x12)  8 = ( x1 + x8)  9 = ( ¬x7 + ¬x8 + ¬x13)

12 © R.A. Rutenbar 2009 Slide 12 Carnegie Mellon BCP is Iterative – Run Until No More Implications Assumptions  Partial assignment is x9=0 x10=0 x11=0 x12=1 x13=1 Next…  Let’s assume the new decision var is x1  Assign x1=1  Do the obvious simplifications, what clauses are completely resolved now?  = (  1 )(  2 )(  3 )(  4 )(  5 )(  6 )(  7 )(  8 )(  9 )  1 = ( ¬x1 + x2 )  2 = ( ¬x1 + x3 + x9)  3 = ( ¬x2 + ¬x3 + x4)  4 = ( ¬x4 + x5 + x10)  5 = ( ¬x4 + x6 + x11)  6 = ( ¬x5 + ¬x6)  7 = ( x1 + x7 + ¬x12)  8 = ( x1 + x8)  9 = ( ¬x7 + ¬x8 + ¬x13)

13 © R.A. Rutenbar 2009 Slide 13 Carnegie Mellon BCP is Iterative – Run Until No More Implications Assumptions  Partial assignment is x9=0 x10=0 x11=0 x12=1 x13=1  Current decision var is x1 Next… do unit-clause BCP  Does setting x1=1 create any unit clauses?  What values for unassigned vars can we now deduce?  = (  1 )(  2 )(  3 )(  4 )(  5 )(  6 )(  7 )(  8 )(  9 )  1 = ( ¬x1 + x2 )  2 = ( ¬x1 + x3 + x9)  3 = ( ¬x2 + ¬x3 + x4)  4 = ( ¬x4 + x5 + x10)  5 = ( ¬x4 + x6 + x11)  6 = ( ¬x5 + ¬x6)  7 = ( x1 + x7 + ¬x12)  8 = ( x1 + x8)  9 = ( ¬x7 + ¬x8 + ¬x13)

14 © R.A. Rutenbar 2009 Slide 14 Carnegie Mellon BCP is Iterative – Run Until No More Implications Assumptions  Partial assignment is x9=0 x10=0 x11=0 x12=1 x13=1  Current decision var is x1  Unit clause implications: Next… continue unit-clause BCP  Assign vars from unit clause BCP  Did we resolve any more clauses?  Any more values for unassigned vars we can deduce?  = (  1 )(  2 )(  3 )(  4 )(  5 )(  6 )(  7 )(  8 )(  9 )  1 = ( ¬x1 + x2 )  2 = ( ¬x1 + x3 + x9)  3 = ( ¬x2 + ¬x3 + x4)  4 = ( ¬x4 + x5 + x10)  5 = ( ¬x4 + x6 + x11)  6 = ( ¬x5 + ¬x6)  7 = ( x1 + x7 + ¬x12)  8 = ( x1 + x8)  9 = ( ¬x7 + ¬x8 + ¬x13) 1

15 © R.A. Rutenbar 2009 Slide 15 Carnegie Mellon BCP is Iterative – Run Until No More Implications Assumptions  Partial assignment is x9=0 x10=0 x11=0 x12=1 x13=1  Current decision var is x1  Unit clause implications: Next… continue unit-clause BCP  Assign vars from unit clause BCP  Did we resolve any more clauses?  Any more values for unassigned vars we can deduce?  = (  1 )(  2 )(  3 )(  4 )(  5 )(  6 )(  7 )(  8 )(  9 )  1 = ( ¬x1 + x2 )  2 = ( ¬x1 + x3 + x9)  3 = ( ¬x2 + ¬x3 + x4)  4 = ( ¬x4 + x5 + x10)  5 = ( ¬x4 + x6 + x11)  6 = ( ¬x5 + ¬x6)  7 = ( x1 + x7 + ¬x12)  8 = ( x1 + x8)  9 = ( ¬x7 + ¬x8 + ¬x13) 2

16 © R.A. Rutenbar 2009 Slide 16 Carnegie Mellon BCP is Iterative – Run Until No More Implications Assumptions  Partial assignment is x9=0 x10=0 x11=0 x12=1 x13=1  Current decision var is x1  Unit clause implications: Next… continue unit-clause BCP  Assign vars from unit clause BCP  Did we resolve any more clauses?  Any more values for unassigned vars we can deduce?  = (  1 )(  2 )(  3 )(  4 )(  5 )(  6 )(  7 )(  8 )(  9 )  1 = ( ¬x1 + x2 )  2 = ( ¬x1 + x3 + x9)  3 = ( ¬x2 + ¬x3 + x4)  4 = ( ¬x4 + x5 + x10)  5 = ( ¬x4 + x6 + x11)  6 = ( ¬x5 + ¬x6)  7 = ( x1 + x7 + ¬x12)  8 = ( x1 + x8)  9 = ( ¬x7 + ¬x8 + ¬x13) 3

17 © R.A. Rutenbar 2009 Slide 17 Carnegie Mellon BCP is Iterative – Run Until No More Implications 3 cases when BCP finishes  SAT: We find a satisfying assignment, all the clauses resolve to “ 1 ”. Return it.  UNRESOLVED: We have one or more clauses unresolved. Means we need to pick another “free” unassigned variable and recurse more.  UNSAT: Like this case. Found a conflict that made one or more clauses eval to “ 0 ” Now what?  You need to undo one of our variable assignments…  … and backtrack, try something different  = (  1 )(  2 )(  3 )(  4 )(  5 )(  6 )(  7 )(  8 )(  9 )  1 = ( ¬x1 + x2 )  2 = ( ¬x1 + x3 + x9)  3 = ( ¬x2 + ¬x3 + x4)  4 = ( ¬x4 + x5 + x10)  5 = ( ¬x4 + x6 + x11)  6 = ( ¬x5 + ¬x6)  7 = ( x1 + x7 + ¬x12)  8 = ( x1 + x8)  9 = ( ¬x7 + ¬x8 + ¬x13)

18 © R.A. Rutenbar 2009 Slide 18 Carnegie Mellon BCP is Iterative – Run Until No More Implications Assumptions  Partial assignment is x9=0 x10=0 x11=0 x12=1 x13=1  Current decision var is x1  Unit clause implications: Go back to “most recent” decision and if it has not been tried both ways, “flip it” to other value  Erase all the simplifications due to x1=1, but keep the other simplifications  Erase all the unit clause implications too  Start again with x1=0 decision  = (  1 )(  2 )(  3 )(  4 )(  5 )(  6 )(  7 )(  8 )(  9 )  1 = ( ¬x1 + x2 )  2 = ( ¬x1 + x3 + x9)  3 = ( ¬x2 + ¬x3 + x4)  4 = ( ¬x4 + x5 + x10)  5 = ( ¬x4 + x6 + x11)  6 = ( ¬x5 + ¬x6)  7 = ( x1 + x7 + ¬x12)  8 = ( x1 + x8)  9 = ( ¬x7 + ¬x8 + ¬x13) 4

19 © R.A. Rutenbar 2009 Slide 19 Carnegie Mellon BCP is Iterative – Run Until No More Implications Assumptions  Partial assignment is x9=0 x10=0 x11=0 x12=1 x13=1  Current decision var still x1, but now x1=0  Unit clause implications: Again … do BCP till nothing left  Erase all the simplifications due to x1=1, but keep the other simplifications  Erase all the unit clause implications too  Start again with x1=0 decision  = (  1 )(  2 )(  3 )(  4 )(  5 )(  6 )(  7 )(  8 )(  9 )  1 = ( ¬x1 + x2 )  2 = ( ¬x1 + x3 + x9)  3 = ( ¬x2 + ¬x3 + x4)  4 = ( ¬x4 + x5 + x10)  5 = ( ¬x4 + x6 + x11)  6 = ( ¬x5 + ¬x6)  7 = ( x1 + x7 + ¬x12)  8 = ( x1 + x8)  9 = ( ¬x7 + ¬x8 + ¬x13) 5

20 © R.A. Rutenbar 2009 Slide 20 Carnegie Mellon BCP is Iterative – Run Until No More Implications Oops– another conflict! Now what?  Need to erase all the local clause simplifications and implications, again  We know neither x1=1 nor x1=0 works to find a satisfying assignment with these prior decisions  Backtrack again, to last decision made before the x1 assignment, that was not tried both ways, =1 and =0 x9 x10 x11 x12 x13 x1 x9=0 x10=0 x11=0 x12=1 x13=1 unsat  = (  1 )(  2 )(  3 )(  4 )(  5 )(  6 )(  7 )(  8 )(  9 )  1 = ( ¬x1 + x2 )  2 = ( ¬x1 + x3 + x9)  3 = ( ¬x2 + ¬x3 + x4)  4 = ( ¬x4 + x5 + x10)  5 = ( ¬x4 + x6 + x11)  6 = ( ¬x5 + ¬x6)  7 = ( x1 + x7 + ¬x12)  8 = ( x1 + x8)  9 = ( ¬x7 + ¬x8 + ¬x13)

21 © R.A. Rutenbar 2009 Slide 21 Carnegie Mellon This Has a Famous Name: DPLL Davis-Putnam-Logemann-Loveland Algorithm  Davis, Putnam published the basic recursive framework in 1960 (!)  Davis, Logemann, Loveland came up with smarter BCP, eg, unit-clause rule, in 1962  Often called “Davis-Putnam” or “DP” in honor of the first paper in 1960, or (inaccurately) DPLL (all four of them never did publish this stuff together) Big ideas  A complete, systematic search of variable assignments  Useful CNF form for efficiency  BCP to make the recursions terminate earlier by “resolving” more assignments without recursing more deeply We’ll stick with the (inaccurate) but popular “DPLL” name

22 © R.A. Rutenbar 2009 Slide 22 Carnegie Mellon Vanilla DPLL Algorithm DPLL(set_of_clauses ) // do BCP while ( set_of_clauses contains a unit clause due to literal L ) { Simplify set_of_clauses by setting variable for L to its required value in all clauses } If ( set_of_clauses is all “ 1 ” clauses now) return ( SAT ) // you have simplified every clause to be “1” if ( set_of_clauses contains a clause that evals to “ 0 ”) return ( UNSAT ) // this is a conflict, this set of var assignment doesn’t satisfy // must recurse Heuristically choose an unassigned variable x and heuristically choose a value v if ( DPLL( set_of_clauses = simplified by setting x=v ) == SAT ) return ( SAT ) else return ( DPLL( set_of_clauses = simplified by setting x= ¬v ) )

23 © R.A. Rutenbar 2009 Slide 23 Carnegie Mellon What Do We Need for “Smart” DPLL? Need 5 basic components Clause database data structure  How do we store them? Access them? Branching heuristics  When we have to recurse—which variable to pick? BCP mechanisms  How do we actually do this deduction stuff to get all the implications? Conflict analysis and learning  Can be very clever about how you do the actual backtracking  Don’t just undo “last” decision, if we augment clause database cleverly Random restarts  Yes – randomness is something we can specifically exploit

24 © R.A. Rutenbar 2009 Slide 24 Carnegie Mellon (1) Clause Database Data Structure Most conventional approach is “sparse matrix” representation In a normal programming language, you get 2-D arrays  The idea is this is how you’d store an arbitrary “dense” 2-D matrix  Assumption is that you really plan to use all 4x5 = 20 matrix elements Foo[3][4] =

25 © R.A. Rutenbar 2009 Slide 25 Carnegie Mellon Simplistic Dense Matrix Scheme 2-D structure, one row per clause, one column per variable  Entries in structure tell you if the variable is in the clause, and in which polarity  1 = ( ¬x1 + x2 )  2 = ( ¬x1 + x3 + x9)  3 = ( ¬x2 + ¬x3 + x4)  4 = ( ¬x4 + x5 + x10)  5 = ( ¬x4 + x6 + x11)  6 = ( ¬x5 + ¬x6)  7 = ( x1 + x7 + ¬x12)  8 = ( x1 + x8)  9 = ( ¬x7 + ¬x8 + ¬x13) x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13

26 © R.A. Rutenbar 2009 Slide 26 Carnegie Mellon Sparse Matrix Scheme What’s wrong with that? Very inefficient – mostly empty!  Many variables and clauses, but each clause usually has just a few variables  Solution: “sparse matrix” which is just a set of horizontal and vertical linked lists  1 = ( ¬x1 + x2 )  2 = ( ¬x1 + x3 + x9)  3 = ( ¬x2 + ¬x3 + x4)  4 = ( ¬x4 + x5 + x10)  5 = ( ¬x4 + x6 + x11)  6 = ( ¬x5 + ¬x6)  7 = ( x1 + x7 + ¬x12)  8 = ( x1 + x8)  9 = ( ¬x7 + ¬x8 + ¬x13) x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13

27 © R.A. Rutenbar 2009 Slide 27 Carnegie Mellon Sparse Matrix Scheme Advantages  Conceptually very easy  Avoids all the “empty” entries of the dense matrix scheme  Easy to find all the variables in a particular clause – just walk down the horizontal list  Easy to find all the clauses that have variable xi in them—just walk down the vertical list  Easy to add a new clause to the database, or delete one (we’ll see why later) Disadvantages  It’s smaller than the 2-D dense matrix – yes  But, it’s not necessarily “small” overall, especially if the problem is gigantic  Gigantic means millions of vars or clauses  In this case, the problem is that you are overwhelmed by pointers, especially if you doubly link everything So, how do people really do it?  Combination of schemes.  Use arrays to store literals in clauses  Still use some pointers to link things that need to be searched, but replace some of these ptrs with small searches across clauses  Also, have to do garbage collection to allow for insert/delete actions on the arrays

28 © R.A. Rutenbar 2009 Slide 28 Carnegie Mellon (2) Branching Heuristics Reminder about the context… xi xj xk xm xi=… xj=… xk=… xm=…

29 © R.A. Rutenbar 2009 Slide 29 Carnegie Mellon Heuristic Selects Next Decision Var && Its Value Scenario  After decision variable assignment, some clauses are resolved  After BCP iteration, more clauses resolved ..but, not all the clauses are resolve, ie, they are not unit, we don’t know what to do to make them resolve to “1” Strategy:  Use some heuristic to pick an unassigned literal in some clause(s) in this set  Use this as the next decision variable.value  Recurse: Simplify using this decision assignment, then run BCP, etc etc So – which variable/value to pick?  One that makes the search finish faster  Many options…  = (  i)(  j)(  k)…(  m)…(  n)(  p)…(  z)

30 © R.A. Rutenbar 2009 Slide 30 Carnegie Mellon Branching Heuristics Three sorts of general ideas  Use taxonomy from Ian Gent (eg, www.dcs.st- and.ac.uk/~ipg/AI/Lectures/Search4.ppt ) How constrained?  Pick variables that are “more constrained” first  Idea: Hope this works on the “hard” stuff first, makes the problem easier to solve How likely to satisfy?  Pick variables that are immediately likely to satisfy the problem  Idea: Should try the variable that might—individually—go farthest toward answer How likely to simplify problem?  Pick variable that will lead to most BCP implications via unit propagation  Idea: Make the problem as small as you can, as fast as you can

31 © R.A. Rutenbar 2009 Slide 31 Carnegie Mellon Branching Heuristics: MOM “MOM” acronym, means…  Pick unassigned literal occurring M ost O ften in the M inimal size clauses  Pick a threshold (3, or 5, or …) for max # of literals in a “minimal size clause”  Pick the unassigned literal (ie, you can pick x or ¬x ) that occurs most often  This defines both the variable (it’s x ) and the value (if x, it’s 1, if ¬x, it’s 0 ) Motivation  If this literal appears in a LOT of clauses, you hope to immediately resolve (simplify) a maximal number of clauses  Hope is to make the set of unresolved clauses you need to work with very small, or just quickly find out that this assignment makes  =0 so you can backtrack right away  This is a “how constrained” sort of heuristic: pick the most constrained var


Download ppt "© R.A. Rutenbar 2009 Slide 1 Carnegie Mellon (Lec 06) Boolean Satisfiability: SAT Solvers (Pt 1) What you know  Representation and manipulation via BDDs,"

Similar presentations


Ads by Google