28
SAT Solver Heuristics

SAT Solver Heuristicspswlab.kaist.ac.kr/courses/cs453-fall09/model_checkin_2.pdf · • Boolean Constrain Propagation(BCP) is the process of assigning the True value to all unit literals

Embed Size (px)

Citation preview

SAT Solver Heuristics

SAT solver HistorySAT-solver History

St t d ith D id P t L L l d (DPLL) (1962)• Started with David-Putnam-Logemann-Loveland (DPLL) (1962)– Able to solve 10-15 variable problems

• Satz (Chu Min Li, 1995)– Able to solve some 1000 variable problems

• Chaff (Malik et al., 2001)– Intelligently hacked DPLL , Won the 2004 competitiong y , p– Able to solve some 10000 variable problems

Current state of the art• Current state-of-the-art– MiniSAT and SATELITEGTI (Chalmer’s university, 2004-2006)– Jerusat and Haifasat (Intel Haifa, 2002)– Ace (UCLA, 2004-2006)

2/45

MiniSATMiniSAT

Mi iS i f SAT l d l d b Nikl Eé• MiniSat is a fast SAT solver developed by Niklas Eén and Niklas Sörensson

MiniSat won all industrial categories in SAT 2005 competition– MiniSat won all industrial categories in SAT 2005 competition– MiniSat won SAT-Race 2006

• MiniSat is simple and well-documented– Well-defined interface for general use– Helpful implementation documents and comments– Minimal but efficient heuristic

• Main C (344 lines)• Main.C (344 lines)• Solver.C (741 lines)

3/45

Overview (1/2)Overview (1/2)

A set of propositional ariables and CNF cla ses• A set of propositional variables and CNF clauses involving variables– (x1  x2’  x3) ∧ (x2  x1’  x4)– x1, x2, x3 and x4 are variables (true or false)

• Literals: Variable and its negation• Literals: Variable and its negation– x1 and x1’

l i i fi d if f h li l i• A clause is satisfied if one of the literals is true– x1=true satisfies clause 1– x1=false satisfies clause 21

• Solution: An assignment that satisfies all clauses

4/21

Overview (2/2)Overview (2/2)U it l i l i hi h ll b t f lit l i i d• Unit clause is a clause in which all but one of literals is assigned to False

• Unit literal is the unassigned literal in a unit clauseg……(x0)∧ (-x0∨x1)∧

– (x0) is a unit clause and ‘x0’ is a unit literal

(-x2∨-x3∨-x4)∧……

– (-x0∨x1) is a unit clause since x0 has to be True– (-x2∨-x3∨-x4) can be a unit clause if the current assignment is that x3

and x4 are True4

• Boolean Constrain Propagation(BCP) is the process of assigning the True value to all unit literals

5/45

DPLL Overview (1/3)DPLL Overview (1/3)/* The Quest for Efficient Boolean Satisfiability Solvers* by L.Zhang and S.Malik, Computer Aided Verification 2002 */y g , p

DPLL(a formula φ, assignment) {necessary = deduction(φ, assignment);y (φ g )new_asgnment = union(necessary, assignment);if (is_satisfied(φ, new_asgnment))

return SATISFIABLE;return SATISFIABLE;else if (is_conflicting(φ, new_asgnmnt))

return UNSATISFIABLE;var = choose free variable(φ new asgnmnt);var = choose_free_variable(φ, new_asgnmnt);asgn1 = union(new_asgnmnt, assign(var, 1));if (DPLL(φ, asgn1) == SATISFIABLE)

return SATISFIABLE;return SATISFIABLE;else {

asgn2 = union (new_asgnmnt, assign(var,0));t DPLL (φ 2)return DPLL (φ, asgn2);

}}

6/45

DPLL Overview (2/3)DPLL Overview (2/3){p r} {¬p ¬q r} {p ¬r}

p=T p=F

{T r} {¬T  ¬q  r} {T  ¬r} {F  r} {¬F  ¬q  r} {F  ¬r}

{ q r} {r} { r}

SIMPLIFY SIMPLIFY

{¬q r} {r} {¬r}

{}SIMPLIFY

7/45

{}

DPLL Overview (3/3)DPLL Overview (3/3)/* overall structure of Minisat solve procedure *// overall structure of Minisat solve procedure /Solve(){

while(true){boolean constraint propagation();boolean_constraint_propagation();if(no_conflict){

if(no_unassigned_variable) return SAT;decision level++;decision_level++;make_decision();

}else{if (no dicisions made) return UNSAT;if (no_dicisions_made) return UNSAT;analyze_conflict();undo_assignments();add conflict clause();add_conflict_clause();

}}

}}

8/45

Conflict Clause Analysis (1/10)Conflict Clause Analysis (1/10)A fli h h l i f l ifi d• A conflict happens when one clause is falsified by unit propagation

A i F lAssume x4 is False(x1∨x4) ∧(-x1∨x2) ∧( x ∨x ) ∧(-x2∨x3) ∧(-x3∨-x2∨-x1) Falsified!Omitted clauses

• Analyze the conflicting clause to infer a clause– (-x3∨-x2∨-x1) is conflicting clause( 3 2 1) g

• The inferred clause is a new knowledge– A new learnt clause is added to constraints

9/45

Conflict Clause Analysis (2/10)Conflict Clause Analysis (2/10)

• Learnt clauses are inferred by conflict analysis(x1∨x4) ∧( x ∨x ) ∧(-x1∨x2) ∧(-x2∨x3) ∧(-x3∨-x2∨-x1) ∧omitted clauses ∧

• They help prune future parts of the search space

omitted clauses ∧(x4) learnt clause

space– Assigning False to x4 is the casual of conflict

Addi ( ) i hibi fli f– Adding (x4) to constraints prohibit conflict from –x4

• Learnt clauses actually drive backtracking

10/45

Conflict Clause Analysis (3/10)Conflict Clause Analysis (3/10)/* fli t l i l ith *//* conflict analysis algorithm */Analyze_conflict(){

cl = find_conflicting_clause();il l i f l ifi d d li l h l i d i d i/* Loop until cl is falsified and one literal whose value is determined in current

decision level is remained */While(!stop_criterion_met(cl)){

lit h lit l( l) /* l t th l t t d lit l */lit = choose_literal(cl); /* select the last propagated literal */Var = variable_of_literal(lit);ante = antecedent(var);l l ( l )cl = resolve(cl, ante, var);

}add_clause_to_database(cl);/* backtrack level is the lowest decision level for which the learnt clause is unit clause */back_dl = clause_asserting_level(cl);

b k dlreturn back_dl;}

Algorithm from Lintao Zhang and Sharad malik“The Quest for Efficient Boolean Satisfiability Solvers”

11/45

Conflict Clause Analysis (4/10)Conflict Clause Analysis (4/10)

• Example of conflict clause analysis– a, b, c, d, e, f, g, and h: 8 variables ( 28 cases)

(-f∨e) ∧(-g∨f) ∧

Satisfiable?( g )(b∨a∨e) ∧(c∨e∨f∨-b) ∧( )(-h∨g)(d∨-b∨h) ∧ Unsatisfiable?( )(-b∨-c∨-d) ∧(c∨d)

12/45

( )

C fli t Cl A l i (5/10)Conflict Clause Analysis (5/10)

Assignments antecedent

e=F assumption e=Fp

f=F -f∨e

g=F g∨f a=TDLevel=1g=F -g∨f

h=F -h∨g

a=T

b∨ c∨ d

Conflict

a=F assumption

b=T b∨a∨e

-b∨-c∨-d

DLevel=2

c=T c∨e∨f∨-b

d=T d∨ b∨h

DLevel=2

Example slides are from CMU 15-414 course pptd=T d∨-b∨h p pp

13/45

C fli t Cl A l i (6/10)Conflict Clause Analysis (6/10)

e=F

Assignments antecedent

e=F assumption

a=T

p

f=F -f∨e

g=F g∨fDLevel=1

a=T

b∨ c∨ d

g=F -g∨f

h=F -h∨g-b∨-c∨-da=F assumption

b=T b∨a∨e

c=T c∨e∨f∨-b

d=T d∨ b∨h

DLevel=2

d=T d∨-b∨h

14/45

R l tiResolution

• Resolution is a process to generate a clause from two clausesclause from two clauses

• Given two clauses (x∨y) and (-y∨z), th l t f th t l ithe resolvent of these two clauses is (x∨z)– (x∨y) ∧(-y∨z) is satisfiable iff

(x∨y)∧(-y∨z)∧(x∨z) is satisfiable( y) ( y ) ( )– The resolvent is redundant

15

C fli t Cl A l i (7/10)Conflict Clause Analysis (7/10)

e=F

Assignments antecedent

e=F assumption

a=T

p

f=F -f∨e

g=F g∨fDLevel=1

a=T

b∨ c∨ d

g=F -g∨f

h=F -h∨g-b∨-c∨-d-b∨-c∨h(a resolvent of

a=F assumption

b=T b∨a∨e (a resolvent of -b∨-c∨-dand d∨-b∨h)

c=T c∨e∨f∨-b

d=T d∨ b∨h

DLevel=2

)d=T d∨-b∨h

16/45

C fli t Cl A l i (8/10)Conflict Clause Analysis (8/10)

e=F

Assignments antecedent

e=F assumption

a=T

p

f=F -f∨e

g=F g∨fDLevel=1

a=T

b∨ c∨ d

g=F -g∨f

h=F -h∨g-b∨-c∨-d-b∨-c∨h

a=F assumption

b=T b∨a∨e

c=T c∨e∨f∨-b

d=T d∨ b∨h

DLevel=2

d=T d∨-b∨h

17/45

C fli t Cl A l i (9/10)Conflict Clause Analysis (9/10)

e=F

Assignments antecedent

e=F assumption

a=T

p

f=F -f∨e

g=F g∨fDLevel=1

a=T

b∨ c∨ d

g=F -g∨f

h=F -h∨g-b∨-c∨-d

b∨e∨f∨h learnt clause-b∨-c∨h

a=F assumption

b=T b∨a∨e-b∨e∨f∨h learnt clause

c=T c∨e∨f∨-b

d=T d∨ b∨h

DLevel=2

d=T d∨-b∨h

18/45

C fli t Cl A l i (10/10)Conflict Clause Analysis (10/10)

e=F

Assignments antecedent

e=F assumption

a=T b=F

p

f=F -f∨e

g=F g∨fDLevel=1 a=T

b∨ c∨ d

b=Fg=F -g∨f

h=F -h∨g-b∨-c∨-d-b∨-c∨hb∨e∨f∨h

b=F -b∨e∨f∨h

… …-b∨e∨f∨h

19/45

Variable State Independent Decaying Sum(VSIDS)

D i i h i i d i h i bl ill b• Decision heuristic to determine what variable will be assigned nextDecision is independent from the current assignment• Decision is independent from the current assignment of each variable

• VSIDS makes decisions based on activity• VSIDS makes decisions based on activity– Activity is a literal occurrence count with higher weight on the

more recently added clauses– MiniSAT does not consider any polarity in VSIDS

• Each variable, not literal has score

activity description from Lintao Zhang and Sharad malik“Th Q t f Effi i t B l S ti fi bilit S l ”

20/45

“The Quest for Efficient Boolean Satisfiability Solvers”

VSIDS Decision Heuristic –MiniSAT style (1/8)

I i i ll h f h i bl i 0• Initially, the score for each variable is 0• First make a decision e = False

Th d b t i ifi d– The order between same score is unspecified.– MiniSAT always assigns False to variables.

Variable Score ValueInitial constraints(-f∨e) ∧(-g∨f) ∧b

Variable Score Value

a 0

b 0(b∨a∨e) ∧(c∨e∨f∨-b) ∧(-h∨g) ∧(d b h)

c 0

d 0

e 0 F(d∨-b∨h) ∧(-b∨-c∨-d) ∧(c∨d)

e 0 F

f 0

g 0

21/45

h 0

VSIDS Decision Heuristic (2/8)VSIDS Decision Heuristic (2/8)

f h F l f BCP• f, g, h are False after BCP

(-f∨e) ∧

Variable Score Value

a 0(-f∨e) ∧(-g∨f) ∧(b∨a∨e) ∧(c∨e∨f∨-b) ∧

b 0

c 0

d 0(c∨e∨f∨ b) ∧(-h∨g) ∧(d∨-b∨h) ∧(-b∨-c∨-d) ∧

d 0

e 0 F

f 0 F( )(c∨d) g 0 F

h 0 F

22/45

VSIDS Decision Heuristic (3/8)VSIDS Decision Heuristic (3/8)

i d i i i bl• a is next decision variable

(-f∨e) ∧

Variable Score Value

a 0 F(-f∨e) ∧(-g∨f) ∧(b∨a∨e) ∧(c∨e∨f∨-b) ∧

a 0 F

b 0

c 0(c∨e∨f∨ b) ∧(-h∨g) ∧(d∨-b∨h) ∧(-b∨-c∨-d) ∧

d 0

e 0 F

f 0 F( )(c∨d)

f 0 F

g 0 F

h 0 F

23/45

VSIDS Decision Heuristic (4/8)VSIDS Decision Heuristic (4/8)

b T f BCP• b, c are True after BCP• Conflict occurs on variable d

St t fli t l i– Start conflict analysis

(-f∨e) ∧

Variable Score Value

a 0 F(-f∨e) ∧(-g∨f) ∧(b∨a∨e) ∧(c∨e∨f∨-b) ∧

a 0 F

b 0 T

c 0 T(c∨e∨f∨ b) ∧(-h∨g) ∧(d∨-b∨h) ∧(-b∨-c∨-d) ∧

d 0 T

e 0 F

f 0 F( )(c∨d)

f 0 F

g 0 F

h 0 F

24/45

VSIDS Decision Heuristic (5/8)VSIDS Decision Heuristic (5/8)

Th f i bl i l i i d b 1• The score of variable in resolvents is increased by 1– Even if a variable appears in resolvents two or mores increase the

score just oncej

(-f∨e) ∧

Variable Score Value

a 0 F(-f∨e) ∧(-g∨f) ∧(b∨a∨e) ∧(c∨e∨f∨-b) ∧

a 0 F

b 1 T

c 1 T(c∨e∨f∨ b) ∧(-h∨g) ∧(d∨-b∨h) ∧(-b∨-c∨-d) ∧

d 0 T

e 0 F

f 0 F

Resolvent on d-b∨-c∨h

( )(c∨d)

f 0 F

g 0 F

h 1 F

25/45

VSIDS Decision Heuristic (6/8)VSIDS Decision Heuristic (6/8)

Th d f fli l i• The end of conflict analysis• The scores are decaying 5% for next scoring

(-f∨e) ∧

Variable Score Value

a 0 F(-f∨e) ∧(-g∨f) ∧(b∨a∨e) ∧(c∨e∨f∨-b) ∧

a 0 F

b 0.95 T

c 0.95 TResolvents-b∨-c∨h

f(c∨e∨f∨ b) ∧(-h∨g) ∧(d∨-b∨h) ∧(-b∨-c∨-d) ∧

d 0 T

e 0.95 F

f 0 95 F

-b∨e∨f∨hlearnt clause

( )(c∨d)

f 0.95 F

g 0 F

h 0.95 F

26/45

VSIDS Decision Heuristic (7/8)VSIDS Decision Heuristic (7/8)

b i F l d i T f BCP• b is now False and a is True after BCP• Next decision variable is c with 0.95 score

Variable Score Value

a 0 T(-f∨e) ∧ a 0 T

b 0.95 F

c 0.95

(-f∨e) ∧(-g∨f) ∧(b∨a∨e) ∧(c∨e∨f∨-b) ∧

d 0

e 0.95 F

f 0 95 F

(c∨e∨f∨ b) ∧(-h∨g) ∧(d∨-b∨h) ∧(-b∨-c∨-d) ∧ f 0.95 F

g 0 F

h 0.95 F

( )(c∨d) ∧(-b∨e∨f∨h )

Learnt clause

27/45

VSIDS Decision Heuristic (8/8)VSIDS Decision Heuristic (8/8)

Fi ll fi d d l!• Finally we find a model!

Variable Score Value

a 0 T(-f∨e) ∧ a 0 T

b 0.95 F

c 0.95 F

(-f∨e) ∧(-g∨f) ∧(b∨a∨e) ∧(c∨e∨f∨-b) ∧

d 0 T

e 0.95 F

f 0 95 F

(c∨e∨f∨ b) ∧(-h∨g) ∧(d∨-b∨h) ∧(-b∨-c∨-d) ∧ f 0.95 F

g 0 F

h 0.95 F

( )(c∨d) ∧(-b∨e∨f∨h )

Learnt clause

28/45