0% found this document useful (0 votes)
28 views

Lecture 7 SAT

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Lecture 7 SAT

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Lecture 7: Satisfiability (SAT)

1
Satisfiability Terminology
q Satisfiability (called “SAT” for short)
q Give me an appropriate representation of function F(x1, x2,
… xn)
q Find an assignment of the variables (“vars” for short) (x1, x2,
… xn) so F( ) = 1
q Note – this assignment need not be unique. Could be many
satisfying solutions
q But if there are no satisfying assignments at all – prove it,
and return this info
q Some things you can do with BDDs, but easier with SAT
q SAT is aimed at scenarios where you just need one satisfying
assignment…
q …or prove that there is no such satisfying assignment
3
Standard SAT Form: CNF
q Conjunctive Normal Form (CNF) = Standard POS form
ɸ = ( a + c ) ( b + c) ( ¬a + ¬b + ¬c)

Clause Positive literal Negative literal

q Why CNF is useful?


q Need only determine that one clause evaluates to “0”
to know whole formula = “0”
q Of course, to satisfy the whole formula, you must make
all clauses identically “1”.
4
Assignment to a CNF
q An assignment…
q Gives values to some, not necessarily all, of variables
(vars) xi in (x1, x2, … , xn).
q Complete assignment: assigns value to all vars.
q Partial: some, not all, have values
q Assignment evaluate status of the clauses
q Suppose a=0, b=1 but c, d are unassigned

ɸ = ( a + ¬b ) (¬a + b + ¬ c) ( a + c + d ) ( ¬a + ¬b + ¬c)

Conflicting Satisfied unsolved SAT


5
How to we solve SAT?
q Recursively – the most common ways in CAD tools
q Strategy has two big ideas
q DECISION:
• Select a variable and assign its value; simplify CNF formula as
far as you can
• Hope you can decide if it’s SAT, yes/no, without further work
q DEDUCTION:
• Look at the newly simplified clauses
• Iteratively simplify, based on structure of clauses, and value of
partial assignment
• Do this until nothing simplifies. If you can decide SAT yes/no,
great.
• If not, then you have to recurse some more, back up to DECIDE

6
Example

ɸ = ( x + y + z)( ¬x + y )( ¬y + z ) ( ¬x + ¬y + ¬z)

7
Example

ɸ = ( x + y + z)( ¬x + y )( ¬y + z ) ( ¬x + ¬y + ¬z)

x=1
( 1 )( y )( ¬y + z ) ( ¬y + ¬z )

8
Example

ɸ = ( x + y + z)( ¬x + y )( ¬y + z ) ( ¬x + ¬y + ¬z)

x=1
( 1 )( y )( ¬y + z ) ( ¬y + ¬z )

y=1
( 1 )( z ) ( ¬z )

9
Example

ɸ = ( x + y + z)( ¬x + y )( ¬y + z ) ( ¬x + ¬y + ¬z)

x=1
( 1 )( y )( ¬y + z ) ( ¬y + ¬z )

y=1
( 1 )( z ) ( ¬z )

z=0 z=1

0 0
unSAT unSAT

10
Example

ɸ = ( x + y + z)( ¬x + y )( ¬y + z ) ( ¬x + ¬y + ¬z)

x=1
( 1 )( y )( ¬y + z ) ( ¬y + ¬z )

y=1 y=0

( 1 )( z ) ( ¬z ) 0

z=0 z=1 unSAT

0 0
unSAT unSAT

11
Example

ɸ = ( x + y + z)( ¬x + y )( ¬y + z ) ( ¬x + ¬y + ¬z)

x=1 x=0

( 1 )( y )( ¬y + z ) ( ¬y + ¬z ) ( 1 )( y + z ) ( ¬y + z )

y=1 y=0

( 1 )( z ) ( ¬z ) 0

z=0 z=1 unSAT

0 0
unSAT unSAT

12
Example

ɸ = ( x + y + z)( ¬x + y )( ¬y + z ) ( ¬x + ¬y + ¬z)

x=1 x=0

( 1 )( y )( ¬y + z ) ( ¬y + ¬z ) ( 1 )( y + z ) ( ¬y + z )

y=1 y=0 z=1

( 1 )( z ) ( ¬z ) 0 (1)(1)

z=0 z=1 unSAT SAT!!

0 0
unSAT unSAT

13
Example

ɸ = ( x + y + z)( ¬x + y )( ¬y + z ) ( ¬x + ¬y + ¬z)

x=1 x=0

( 1 )( y )( ¬y + z ) ( ¬y + ¬z ) ( 1 )( y + z ) ( ¬y + z )

y=1 y=0 z=1

( 1 )( z ) ( ¬z ) 0 (1)(1)

z=0 z=1 unSAT SAT!!

0 0
unSAT unSAT Backtracking algorithm! (ECE 220)

14
Backtracking Algorithm (ECE220)
q Many useful to yes/no problems
q Depth-first search (DFS)

15
Boolean Constraint Propagation (BCP)
q To do “deduction”, use BCP
q Given a set of fixed variable assignments, what else can you
“deduce” about necessary assignments by “propagating
constraints”
q Most famous BCP strategy is “Unit Clause Rule”
q A clause is said to be “unit” if it has exactly one unassigned
literal
q Unit clause has exactly one way to be satisfied, ie, pick
polarity that makes clause=“1”
q This choice is called an “implication”

ɸ = ( a + c ) ( b + c) ( ¬a + ¬b + ¬c)
Assume:
a=1, b=1
ff
16
Boolean Constraint Propagation (BCP)
q To do “deduction”, use BCP
q Given a set of fixed variable assignments, what else can you
“deduce” about necessary assignments by “propagating
constraints”
q Most famous BCP strategy is “Unit Clause Rule”
q A clause is said to be “unit” if it has exactly one unassigned
literal
q Unit clause has exactly one way to be satisfied, ie, pick
polarity that makes clause=“1”
q This choice is called an “implication”

ɸ = ( a + c ) ( b + c) ( ¬a + ¬b + ¬c)
Assume:
c is unit unsigned clause – must
a=1, b=1
be 0 17
BCP Iteration – Go until no more implications

ɸ = (ω1)(ω2)(ω3)(ω4)(ω5)(ω6)(ω7)(ω8)(ω9)
q Example from
q J.P. Marques-Silva and K. Sakallah,
ω1 = ( ¬x1 + x2 )
0 “GRASP: A Search Algorithm for
ω2 = ( ¬x1 + x3 + x9) Propositional Satisfiability”, IEEE Trans.
Computers, Vol 8, No 5, May’99
ω3 = ( ¬x2 + ¬x3 + x4)
0 No SAT
ω4 = ( ¬x4 + x5 + x10) q Partial assignment is:
0 No BCP
ω5 = ( ¬x4 + x6 + x11) q x9=0 x10=0 x11=0 x12=1 x13=1
Now what?
ω6 = ( ¬x5 + ¬x6) q To start…
0 q What are obvious simplifications when
ω7 = ( x1 + x7 + ¬x12)
we assign these variables?
ω8 = ( x1 + x8)
0
ω9 = ( ¬x7 + ¬x8 + ¬x13)

18
BCP Iteration – Go until no more implications

ɸ = (ω1)(ω2)(ω3)(ω4)(ω5)(ω6)(ω7)(ω8)(ω9)
q Partial assignment is:
0 q x9=0 x10=0 x11=0 x12=1 x13=1
ω1 = ( ¬x1 + x2 )
0 0 Unit q Next: Assign a variable to value
ω2 = ( ¬x1 + x3 + x9)
q Assign x1=1
ω3 = ( ¬x2 + ¬x3 + x4)
0
ω4 = ( ¬x4 + x5 + x10)
0
ω5 = ( ¬x4 + x6 + x11)
ω6 = ( ¬x5 + ¬x6) Implications!
1 0 x1=1 à x2=1 && x3=1
ω7 = ( x1 + x7 + ¬x12)
1 SAT
ω8 = ( x1 + x8)
0
ω9 = ( ¬x7 + ¬x8 + ¬x13)

19
BCP Iteration – Go until no more implications

ɸ = (ω1)(ω2)(ω3)(ω4)(ω5)(ω6)(ω7)(ω8)(ω9)
q Partial assignment is:
0 1 q x9=0 x10=0 x11=0 x12=1 x13=1
ω1 = ( ¬x1 + x2 )
0 1 0 SAT q Next: Assign a var to value
ω2 = ( ¬x1 + x3 + x9)
0 0 q Assign x1=1
ω3 = ( ¬x2 + ¬x3 + x4) UNIT
0 q Assign (implied): x2=1,
ω4 = ( ¬x4 + x5 + x10)
0 x3=1
ω5 = ( ¬x4 + x6 + x11)
ω6 = ( ¬x5 + ¬x6) Implications!
1 0 x2=1,x3=1 à x4=1
ω7 = ( x1 + x7 + ¬x12)
1 SAT
ω8 = ( x1 + x8)
0
ω9 = ( ¬x7 + ¬x8 + ¬x13)

20
BCP Iteration – Go until no more implications

ɸ = (ω1)(ω2)(ω3)(ω4)(ω5)(ω6)(ω7)(ω8)(ω9)
q Partial assignment is:
0 1 q x9=0 x10=0 x11=0 x12=1 x13=1
ω1 = ( ¬x1 + x2 )
0 1 0 SAT q Next: Assign a var to value
ω2 = ( ¬x1 + x3 + x9)
0 0 1 q Assign x1=1
ω3 = ( ¬x2 + ¬x3 + x4)
0 0 q Assign (implied): x2=1,
ω4 = ( ¬x4 + x5 + x10)
0 0 UNIT x3=1
ω5 = ( ¬x4 + x6 + x11)
q Assign (implied): x4=1
ω6 = ( ¬x5 + ¬x6)
1 0
ω7 = ( x1 + x7 + ¬x12) Implications!
1 SAT x4=1 à x5=1 && x6=1
ω8 = ( x1 + x8)
0
ω9 = ( ¬x7 + ¬x8 + ¬x13)

21
BCP Iteration – Go until no more implications

ɸ = (ω1)(ω2)(ω3)(ω4)(ω5)(ω6)(ω7)(ω8)(ω9)
q Partial assignment is:
0 1 q x9=0 x10=0 x11=0 x12=1 x13=1
ω1 = ( ¬x1 + x2 )
0 1 0 SAT q Next: Assign a var to value
ω2 = ( ¬x1 + x3 + x9)
0 0 1 q Assign x1=1
ω3 = ( ¬x2 + ¬x3 + x4)
0 1 0 q Assign (implied): x2=1,
ω4 = ( ¬x4 + x5 + x10)
0 1 0 UNIT x3=1
ω5 = ( ¬x4 + x6 + x11)
0 0 q Assign (implied): x4=1
ω6 = ( ¬x5 + ¬x6) CONFLICT!
1 0 q Assign (implied): x5=1 &&
ω7 = ( x1 + x7 + ¬x12)
1 SAT x6=1àunSAT
ω8 = ( x1 + x8) Conflict
0 x5=1 && x6=1 à clause ω6==0!
ω9 = ( ¬x7 + ¬x8 + ¬x13)

22
BCP Iteration – Go until no more implications

ɸ = (ω1)(ω2)(ω3)(ω4)(ω5)(ω6)(ω7)(ω8)(ω9)
0
q 3 cases when BCP finishes
1
ω1 = ( ¬x1 + x2 ) q SAT: Find a SAT assignment, all
0 1 0 SAT clauses resolve to “1”. Return it.
ω2 = ( ¬x1 + x3 + x9)
0 0 1 q UNRESOLVED: One or more clauses
ω3 = ( ¬x2 + ¬x3 + x4) unresolved. Pick another unassigned
0 1 0
ω4 = ( ¬x4 + x5 + x10) var, and recurse more.
0 1 0 SAT
ω5 = ( ¬x4 + x6 + x11) q UNSAT: Like this. Found conflict,
0 0 one or more clauses eval to “0”
ω6 = ( ¬x5 + ¬x6) CONFLICT!
1 0 q Now what?
ω7 = ( x1 + x7 + ¬x12)
1 SAT q You need to undo one of our variable
ω8 = ( x1 + x8)
0 assignments, try again…
ω9 = ( ¬x7 + ¬x8 + ¬x13) UNRESOLVED

23
This has a name: DPLL Algorithm
q Davis-Putnam-Logemann-Loveland Algorithm
q Davis, Putnam published the basic recursive framework
in 1960 (!)
q Davis, Logemann, Loveland: found smarter BCP, eg,
unit-clause rule, in 1962
q 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)
q Big ideas
q A complete, systematic search of variable assignments
q Useful CNF form for efficiency
q BCP makes search stop earlier, “resolving” more
assignments w/o recursing more
24
DPLL’s wiki page …

25
SAT has huge progress > 20 years
q But: DPLL is only the start…
q SAT has been subject of intense work and great progress
q Efficient data structures for clauses (so can search them fast)
q Efficient variable selection heuristics (so search smart, find
lots of implications)
q Efficient BCP mechanisms (because SAT spends MOST of its
time here)
q Learning mechanisms (find patterns of vars that NEVER lead
to SAT, avoid them)

q Results: Good SAT codes that can do huge problems, fast


q Huge means? 50,000 vars; 25,000,000 literals;
50,000,000 clauses (!!)

26
Available SAT Solvers
q Many good solvers available online, open source

q Examples
q MiniSAT, from Niklas Eén, Niklas Sörensson in Sweden.
q CHAFF, from Sharad Malik and students, Princeton
University
q GRASP, from Joao Marques-Silva and Karem Sakallah,
University of Michigan
q …and many others too. Go google around for them…

27
More information about SAT

28
Summary
q SAT is very useful when you are solving yes/no prob
q Tiny, neat, clean, CNF formulation
q Better than using BDD packages (H = F xor G)
q Open-source tools (mini-sat, etc.)
q 40 years, but still important and widely used
q Started from DPLL algorithm
q Recent engineering efforts make it stupendously fast

29
BDD vs SAT
q BDDs q SAT
q Often work well for many q Often works well for many
problems problems
q But – no guarantee it will q But – no guarantee it will always
always work
work
q Can build BDD to represent
function ɸ q Can solve for SAT (y/n) on function
q But—sometimes cannot build ɸ
BDD with reasonable q But—sometimes cannot find SAT
computer resources (run out with reasonable computer
of memory SPACE) resources
q Yes -- builds a full (run out of TIME doing search)
representation of ɸ q No – does not represent all of ɸ
• Can do a big set of Boolean
manipulations on data • Can solve for SAT, but does not
structure support big set of operators
q Can build (∃xyz F) and (∀xyz q There are versions of Quantified
F) SAT that solve SAT on (∃xyz F),
(∀xyz F)
9
Typical Practical SAT Problem
q Are these two Boolean network the same?

Z = 1 SAT
F G If z SAT: we can find x such
that F(x) is not equal to G(x)!
F1 F2 G1 G2
Do SAT solve on this new network
à If SAT: networks not same,
and this pattern makes them
give different outputs
à If unSAT: yes, same!

10
Gate-level Network to CNF
q How do I get a CNF for a gate-level network?
q Isn’t this hard? Don’t I need Boolean algebra or BDDs?
No – it’s really easy
1 3

2 4 5

q Trick: build up CNF one gate at a time

a Gate consistency function ( or gate satisfiability function)


b d
ɸd = [d == (ab)] =

11
Gate-level Network to CNF
q How do I get a CNF for a gate-level network?
q Isn’t this hard? Don’t I need Boolean algebra or BDDs?
No – it’s really easy
1 3

2 4 5

q Trick: build up CNF one gate at a time

a Gate consistency function ( or gate satisfiability function)


b d
ɸd = [d == (ab)] = d “exclusive nor” ab
= (a + d) (b + d) (a’ + b’ + d’)

12
EXOR vs EXNOR

q EXOR: Exclusive OR qEXNOR: Exclusive NOR


q Write is as: Y = A ⊕ B qWrite is as: Y = A ⊕ B
q Output is 1 just if A ≠ B, qOr like this: Y = A ⊙ B
ie, if A is different than B qOutput is 1 just if A == B,
that is,
if A is same as, equal to B
Y = A’B + AB’
Y = AB + A’B’

13
Gate to CNF
Gate consistency function == “1” just for combinations
of inputs and the output that are consistent with what
the gate actually does

a
b d ɸd = ( a + d ) ( b + d ) (¬ a + ¬ b + ¬ d )

a=0 b=0 d = 1 à Satisfied! (consistent)

a=1 b=1 d = 1 à Not satisfied! (inconsistent)

Some people call this “CNF encoding” of a gate


14
Example
q For a network: label each wire, build all gate
consistency funcs

a d
b 1 3
f ɸd = …
h
2 4 5
c g ɸe = …
e
ɸf = …
ɸg = g ⊕[d + e] = …
ɸh = …

15
Derive a CNF for a Boolean Network

q SAT CNF for network is simple:


q Any pattern of abch that satisfies this, also makes the gate network
output h=1
φ = (output var) ∏(k is gate output wire) ɸk
φ= h
a d
( a + d ) ( b + d ) ( ¬a + ¬b + ¬d ) 1 3
( ¬b + ¬e ) ( ¬c + ¬e ) ( b + c + e ) b
f
( ¬d + ¬f ) ( d + f ) h
( ¬d + g ) ( ¬e + g ) ( d + e + ¬g )
4 5
( f + ¬h ) ( g + ¬h ) ( ¬f + ¬g + h ) c 2
e g
q Only need Boolean algebra/simplification for each individual gate-
level function
q At network level, just AND them all together to get CNF

16
Rules for All Kinds of Basic Gates
q Gate consistency rules from:
q Fadi Aloul, Igor L. Markov, Karem Sakallah, “MINCE: A Static Global
Variable-Ordering Heuristic for SAT Search and BDD Manipulation,” J. of
Universal Computer Sci., vol. 10, no. 12 (2004), 1562-1596.

z= (x) z=NOR(x1, x2, … xn) z=OR(x1, x2, … xn)


(yes this is just a wire)
⎤ ⎡⎛ n ⎞ ⎤ ⎡ n ⎤ ⎡⎛ n ⎞ ⎤
[ x + z ][ x + z ]
⎡ n
(
⎢ ∏ xi + z ) ⎥ ⎢⎜⎝ ∑ ⎟⎠
xi + z ⎥ (
⎢∏ xi + z
⎣ i=1
) ⎥ ⎢⎜⎝ ∑ xi⎟⎠ + z ⎥
⎦ ⎣ i=1
⎣ i=1 ⎦ ⎣ i=1 ⎦ ⎦

z=NOT(x) z=NAND(x1, x2, … xn) Z=AND(x1, x2, … xn)


⎡ n ⎤ ⎡⎛ n ⎞ ⎤ ⎡ n ⎤ ⎡⎛ n ⎞ ⎤
[ x + z ][ x + z ] ⎢∏ ( xi + z )⎥ ⎢⎜⎝ ∑ xi⎟⎠ + z ⎥ (
⎢ ∏ xi + z
⎣ i=1
) ⎥ ⎢⎜⎝ ∑ ⎟⎠
⎦ ⎣ i=1
xi + z ⎥
⎣ i=1 ⎦ ⎣ i=1 ⎦ ⎦

17
Rules Exist for MANY Basic Gates …
q EXOR/EXNOR gates are rather unpleasant for SAT
q And the basic “either-or” structure makes for some
tough SAT search, often
q And, they have rather large gate consistency functions
too
q Even small 2-input gates create a lot of terms, like this:

z=EXOR(a, b) z=EXNOR(a, b)

ɸz = z ⊕ (a ⊕ b) ɸz = z ⊕ (a ⊕ b)

18
Using the Rules …

z=NAND(x1, x2, … xn) n==2: z=NAND(x1, x2)


⎡ n ⎤ ⎡⎛ n ⎞ ⎤ x1
z
⎢∏ ( xi + z )⎥ ⎢⎜⎝ ∑ xi⎟⎠ + z ⎥ x2
⎣ i=1 ⎦ ⎣ i=1 ⎦

ɸz = ( x1 + z ) ( x2 + z ) (¬ x1 + ¬ x2 + ¬ z )

For these formulae, ∏ means “AND” ∑ means “OR”


19
Summary
q SAT has largely displaced BDDs for “just solve it”
apps
q Reason is scalability: can do very large problems faster,
more reliably
q Still, SAT, like BDDs, not guaranteed to find a solution in
reasonable time or space
q 40 years old, but still “the” big idea: DPLL
q Many recent engineering advances make it
stupendously fast

20
Quiz
q Derive the consistency function for XOR gate
qz = EXOR(a, b), what is ɸz

21
Gate-consistency Function
q How do I get a CNF for a gate-level network?
q Isn’t this hard? Don’t I need Boolean algebra or BDDs?
No – it’s really easy
1 3

2 4 5

q Trick: build up CNF one gate at a time

a Gate consistency function ( or gate satisfiability function)


b d
ɸd = [d == (ab)] = d “exclusive nor” ab
= (a + d) (b + d) (a’ + b’ + d’)

2
EXOR vs EXNOR

q EXOR: Exclusive OR qEXNOR: Exclusive NOR


q Write is as: Y = A ⊕ B qWrite is as: Y = A ⊕ B
q Output is 1 just if A ≠ B, qOr like this: Y = A ⊙ B
ie, if A is different than B qOutput is 1 just if A == B,
that is,
if A is same as, equal to B
Y = A’B + AB’
Y = AB + A’B’

3
Consistency Function for OR gate
ɸz = [z == (x + y)] = z “exclusive nor” x + y
= z (x + y) + z’ (x + y)’
= zx + zy + z’x’y’

4
Consistency Function for XOR gate
ɸz = [z == (x xor y)] = z “exclusive nor” (xy’ + x’y)
= z (xy’ + x’y) + z’ (xy’ + x’y)’
= zxy’ + zx’y + z’(x’+y)(x+y’)
= zxy’ + zx’y + z’(x’y’ + xy)
= zxy’ + zx’y + z’x’y’ + z’xy

5
CNF for a Logic Network
q For a network: label each wire, build all gate
consistency funcs

φ = (output var) ∏(k is gate output wire) ɸk


a d
b 1 3
f ɸd = …
h
2 4 5 ɸe = …
c e g
ɸf = …
φ= h ɸg = g ⊕[d + e] = …
( a + d ) ( b + d ) ( ¬a + ¬b + ¬d )
( ¬b + ¬e ) ( ¬c + ¬e ) ( b + c + e ) ɸh = …
( ¬d + ¬f ) ( d + f )
( ¬d + g ) ( ¬e + g ) ( d + e + ¬g )
( f + ¬h ) ( g + ¬h ) ( ¬f + ¬g + h )
6
MiniSat Package
q A lightweight open-source SAT solver
q help researchers and developers get started on SAT
q https://github.com/niklasso/minisat
q See homework document

7
SAT: Thing we didn’t talk about
q We covered: DPLL at a very high level
q We did not cover many “deep” tricks in a modern
SAT engine
q Efficient data structures for clauses (so can search them
fast)
q Efficient variable selection heuristics (so search smart,
find lots of implications)
q Efficient BCP mechanisms (because SAT spends MOST of
its time here)
q Learning mechanisms (find patterns of variables that
NEVER lead to SAT, avoid them)
q Uses of randomness to accelerate the SAT search
process
8
DPLL Revisited
q CNF = clauses ω1•ω2• … ωk, over variables xi∈{x1,x2,…xn}

q Decision:
q Select a variable xi and assign its value; simplify CNF formula

q Deduction:
q Unit clause rule lets us perform Boolean Constraint Propagation
q Given a partial variable assignment, run BCP to further simplify
q Do this until nothing simplifies. If you can decide SAT yes/no, great.
q If not, then you have to recurse some more, back up to DECIDE

9
Adding Randomness
q Suppose you added some randomness to SAT engine
q Simplest place is the variable DECISION step – which one to pick

q SAT solvers use smart heuristics to choose variables to assign


q Heuristics calculate numerical scores that rank most promising
variables to choose
q Heuristics rank variables “likely” to create lots of BCP deductions
q In big problems, there are lots of ties, or variables with very similar
scores.
q So, to add randomness to a SAT solver:
q Break these ties randomly to decide next variable to assign
q Or randomly choose a variable that is close to best, but not “the”
best score

10
Why adding randomness?
q What happens if you add this randomness?
q Do this experiment: run the exact same SAT CNF problem,
many times
q Expect some different outcomes– you are deciding to assign
different variables in DPLL
• Note: you still expect CORRECT answers. But maybe different SAT
instances.
q Measure CPU time for each random run. Plot this histogram.
It always looks like this!

# instances
solved in
this much
CPU time

CPU time
11
How to “Read” this result?

Most SAT runs finish near this


“average” amount of CPU time

Some SAT runs make “lucky”


choices for variable assignments;
they run very fast Some SAT runs make “unlucky”
choices for variable assignments;
# instances
they run very slow
solved in
this much
CPU time

12
Can Exploit Randomness
q Strategy: Rapid Random Restarts
q If DPLL is running long, assume you are in one of the “slow” parts
of distribution.
q Stop before you finish SAT solve. Restart SAT solver back at the
beginning
q Big idea: Instead of one deep search, many shallow searches.
q Advanced idea: Keep learned conflict clauses across restarts
q Modern solvers “learn” patterns of variable assignments that can
never be SAT
q This helps solver not keep trying same bad ideas over and over
q These are implemented as new clauses “learned”, added to CNF
database
q Big idea: Do not throw these away across random restarts.
• Keep this “smart stuff” learned from previous random searches for new
ones

13
Does this work actually …?
q Example: Michigan GRASP solver
q “Solve is running too long” heuristic: Whenever the
solver reaches 100 “backtrack” decisions, where it must
undo a variable assignment because it led to an UNSAT
solution, GRASP stops, and does a random restart
q “Keep learned conflicts across restarts” heuristic:
GRASP saves every learned conflict (ie, pattern of bad
variable choices) with ≤ 10 literals, and uses for restart
q Result on one large SAT task:
• SAT without randomness: 42,645 backtracks, 2299.3 CPU sec
• SAT with randomness: 222 backtracks 3 random restarts, 53.5
CPU sec
Numbers courtesy Prof. Karem Sakallah, University of Michigan
See also: Marques-Silva, João P. Search Algorithms for Satisfiability Problems in Combinational Switching Circuits.
Ph.D. Dissertation, EECS Department, University of Michigan, May 1995. 14
Summary
q Modern SAT solver engines use randomness
q Rapid random restarts is a very effective heuristic to reduce
CPU time
q Several ways randomness appears. Easiest for us to explain is
in variable selection heuristics, for which variable to assign a
value to, in evolving DPLL process

q Consequences of randomness
q You get different answers sometimes. (Yes, its weird…)
q You do NOT get wrong answers. Just DIFFERENT anwers, eg,
SAT assignments
q Randomness is a good thing: makes it possible to do huge
SAT problems fast

15

You might also like