Algorithm for SATfor SAT -- MiniSAT MiniSAT...

26
Algorithm Algorithm for SAT for SAT Algorithm Algorithm for SAT for SAT - MiniSAT MiniSAT Heuristics Heuristics Moonzoo Kim Korea Advanced Institute of Science and Technology Copyright © 2008 CS655 System Modeling and Analysis

Transcript of Algorithm for SATfor SAT -- MiniSAT MiniSAT...

AlgorithmAlgorithm for SATfor SATAlgorithm Algorithm for SATfor SAT-- MiniSATMiniSAT HeuristicsHeuristics

Moonzoo Kim

Korea Advanced Institute of Science and Technology

Copyright © 2008 CS655 System Modeling and Analysis

MiniSATMiniSAT SAT SolverSAT Solver

OverviewConflict Clause AnalysisConflict Clause AnalysisVSIDS Decision Heuristic

CS655 System

Modeling and Analysis

2/26

SAT Solver HistorySAT Solver HistoryStarted with DPLL (1962)

Able to solve 10-15 variable problems

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

Chaff (Malik et al., 2001)Intelligently hacked DPLL , Won the 2004 competitionAble to solve some 10000 variable problems

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

CS655 System

Modeling and Analysis

3/26

OverviewOverview

Mi iS t i f t 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 competitionMiniSat won all industrial categories in SAT 2005 competitionMiniSat won SAT-Race 2006

MiniSat is simple and well-documentedWell-defined interface for general useHelpful implementation documents and commentsMinimal but efficient heuristic

CS655 System

Modeling and Analysis

4/26

OverviewOverview

U it l i l i hi h ll b t f lit l i i d tUnit clause is a clause in which all but one of literals is assigned to FalseUnit 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 x3and x4 are True4

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

CS655 System

Modeling and Analysis

5/26

OverviewOverview

/* overall structure of Minisat solve/ overall structure of Minisat solve procedure */

Solve(){while(true){

f l( ){boolean_constraint_propagation();if(no_conflict){

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

x1 = false x1 = true

x2 = false x2 = truedecision_level++;make_decision();

}else{if (no_dicisions_made) return UNSAT;analyze conflict();

x3 = false x3 = true

analyze_conflict();undo_assignments();add_conflict_clause();

}}

}

CS655 System

Modeling and Analysis

6/26

Conflict Clause AnalysisConflict Clause Analysis

A conflict happens when one clause is falsified by unit propagationby unit propagation

Assume x4 is False(x1∨x4) ∧( 1 4)(-x1∨x2) ∧(-x2∨x3) ∧(-x3∨-x2∨-x1) Falsified!

Analyze the conflicting clause to infer a clause( ∨ ∨ ) i fli ti l(-x3∨-x2∨-x1) is conflicting clause

The inferred clause is a new knowledgeA l t l i dd d t t i tA new learnt clause is added to constraints

CS655 System

Modeling and Analysis

7/26

Conflict Clause AnalysisConflict Clause Analysis

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

They help prune future parts of the search space

(-x3∨-x2∨-x1) ∧(x4) learnt clause

y p p p pAssigning False to x4 is the casual of conflictAdding (x4) to constraints prohibit conflict from –x4Adding (x4) to constraints prohibit conflict from x4

Learnt clauses actually drive backtracking

CS655 System

Modeling and Analysis

8/26

Conflict Clause AnalysisConflict Clause Analysis

/* conflict analysis algorithm */Analyze_conflict(){

cl = find confclicting clause();cl = find_confclicting_clause();/* Loop until cl is falsified and one literal whose value is determined in current decision level is remained */While(!stop criterion met(cl)){While(!stop_criterion_met(cl)){

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

}dd l t d t b ( l)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);back_dl = clause_asserting_level(cl);return back_dl;

}

CS655 System

Modeling and Analysis

9/26

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

Conflict Clause AnalysisConflict Clause Analysis

Example of conflict clause analysis

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

Satisfiable?

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

Unsatisfiable?(c∨d)

CS655 System

Modeling and Analysis

10/26

C fli t Cl A l iC fli t Cl A l iConflict Clause AnalysisConflict Clause Analysis

Assignments antecedent

e=F assumption e=Fpf=F -f∨eg=F g∨f a=T

DLevel=1g=F -g∨fh=F -h∨g

a=T

b∨ c∨ d

Conflict

a=F assumptionb=T b∨a∨e

-b∨-c∨-d

DLevel=c=T c∨e∨f∨-b d=T d∨ b∨h

DLevel=2

Example slides are from CMU 15-414 course ppt

CS655 System

Modeling and Analysis

d T d∨-b∨h

11/26

p pp

C fli t Cl A l iC fli t Cl A l iConflict Clause AnalysisConflict Clause Analysis

e=FAssignments antecedent

e=F assumption

a=T

pf=F -f∨eg=F g∨f

DLevel=1a=T

b∨ c∨ d

g=F -g∨fh=F -h∨g

-b∨-c∨-da=F assumptionb=T b∨a∨ec=T c∨e∨f∨-b d=T d∨ b∨h

DLevel=2

CS655 System

Modeling and Analysis 12/26

d T d∨-b∨h

C fli t Cl A l iC fli t Cl A l iConflict Clause AnalysisConflict Clause Analysis

e=FAssignments antecedent

e=F assumption

a=T

pf=F -f∨eg=F g∨f

DLevel=1a=T

b∨ c∨ d

g=F -g∨fh=F -h∨g

-b∨-c∨-d-b∨-c∨h

a=F assumptionb=T b∨a∨ec=T c∨e∨f∨-b d=T d∨ b∨h

DLevel=2

CS655 System

Modeling and Analysis 13/26

d T d∨-b∨h

C fli t Cl A l iC fli t Cl A l iConflict Clause AnalysisConflict Clause Analysis

e=FAssignments antecedent

e=F assumption

a=T

pf=F -f∨eg=F g∨f

DLevel=1a=T

b∨ c∨ d

g=F -g∨fh=F -h∨g

-b∨-c∨-d-b∨-c∨h

a=F assumptionb=T b∨a∨ec=T c∨e∨f∨-b d=T d∨ b∨h

DLevel=2

CS655 System

Modeling and Analysis 14/26

d T d∨-b∨h

C fli t Cl A l iC fli t Cl A l iConflict Clause AnalysisConflict Clause Analysis

e=FAssignments antecedent

e=F assumption

a=T

pf=F -f∨eg=F g∨f

DLevel=1a=T

b∨ c∨ d

g=F -g∨fh=F -h∨g

-b∨-c∨-d

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

a=F assumptionb=T b∨a∨e -b∨e∨f∨h learnt clausec=T c∨e∨f∨-b d=T d∨ b∨h

DLevel=2

CS655 System

Modeling and Analysis 15/26

d T d∨-b∨h

C fli t Cl A l iC fli t Cl A l iConflict Clause AnalysisConflict Clause Analysis

e=FAssignments antecedent

e=F assumption

a=T b=F

pf=F -f∨eg=F g∨fDLevel=1 a=T

b∨ c∨ d

b=Fg=F -g∨fh=F -h∨g

-b∨-c∨-d-b∨-c∨hb∨e∨f∨h

b=F -b∨e∨f∨h… … -b∨e∨f∨h

CS655 System

Modeling and Analysis 16/26

VSIDS Decision HeuristicVSIDS Decision Heuristic

V i bl St t I d d t D i S (VSIDS)Variable State Independent Decaying Sum(VSIDS) decision heuristic to determine what variable will be assigned nextnextdecision is independent from the current assignment of each variable

VSIDS makes decisions based on activityA ti it i lit l t ith hi h i ht thActivity is a literal occurrence count with higher weight on the more recently added clausesMiniSAT does not consider any polarity in VSIDSy p y

• 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 ”

CS655 System

Modeling and Analysis

17/26

“The Quest for Efficient Boolean Satisfiability Solvers”

VSIDS Decision HeuristicVSIDS Decision Heuristic

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

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

Variable Score ValuInitial constraints(-f∨e) ∧(-g∨f) ∧( )

Variable Score Value

a 0

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

b 0

c 0

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

f 00

CS655 System

Modeling and Analysis

18/26

g 0h 0

VSIDS Decision HeuristicVSIDS Decision Heuristic

f h F l ft BCPf, g, h are False after BCP

(-f∨e) ∧

Variable Score Value

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

a 0

b 0

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

d 0

e 0 F( )

f 0 Fg 0 Fh 0 F

CS655 System

Modeling and Analysis

19/26

VSIDS Decision HeuristicVSIDS Decision Heuristic

i t d i i i bla is next decision variable

(-f∨e) ∧

Variable Score Value(-f∨e) ∧

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

a 0 F

b 0

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

c 0

d 0

e 0 F( )f 0 Fg 0 Fh 0 F

CS655 System

Modeling and Analysis

20/26

h 0 F

VSIDS Decision HeuristicVSIDS Decision Heuristic

b T ft BCPb, c are True after BCPConflict occurs on variable d

St t fli t l iStart conflict analysis

(-f∨e) ∧

Variable Score Value(-f∨e) ∧

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

a 0 F

b 0 T

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

c 0 T

d 0 T

e 0 F( )f 0 Fg 0 Fh 0 F

CS655 System

Modeling and Analysis

21/26

h 0 F

VSIDS Decision HeuristicVSIDS Decision Heuristic

Th f i bl i l t i i d b 1The score of variable in resolvents is increased by 1If a variable appears in resolvents two or mores increase the score just oncethe score just once

(-f∨e) ∧

Variable Score Value(-f∨e) ∧

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

a 0 F

b 1 T

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

c 1 T

d 0 T

e 0 F

Resolvent on d-b∨-c∨h

( )f 0 Fg 0 Fh 1 F

CS655 System

Modeling and Analysis

22/26

h 1 F

VSIDS Decision HeuristicVSIDS Decision Heuristic

Th d f fli t l iThe end of conflict analysisThe scores are decaying 5% for next scoring

(-f∨e) ∧

Variable Score Value(-f∨e) ∧

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

a 0 F

b 0.95 T

c 0 95 T

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

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

c 0.95 T

d 0 T

e 0.95 F

-b∨e∨f∨hlearnt clause

( )f 0.95 Fg 0 Fh 0 95 F

CS655 System

Modeling and Analysis

23/26

h 0.95 F

VSIDS Decision HeuristicVSIDS Decision Heuristic

b i F l d i T ft BCPb is now False and a is True after BCPNext decision variable is c with 0.95 score

Variable Score Value(-f∨e) ∧

a 0 T

b 0.95 F

c 0 95

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

d 0

e 0.95 F

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

f 0.95 Fg 0 Fh 0 95 F

( )(-b∨e∨f∨h )Learnt clause

CS655 System

Modeling and Analysis

24/26

h 0.95 F

VSIDS Decision HeuristicVSIDS Decision Heuristic

Fi ll fi d d lFinally we find a model

Variable Score Value(-f∨e) ∧

a 0 T

b 0.95 F

c 0 95 F

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

d 0 T

e 0.95 F

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

f 0.95 Fg 0 Fh 0 95 F

( )(-b∨e∨f∨h )Learnt clause

CS655 System

Modeling and Analysis

25/26

h 0.95 F

Basic ReferencesBasic References

The Quest for Efficient boolean Satisfiability Solvers

L. Zhang and S. Malik

Computer Aided Verification, Denmark, July 2002 (LNCS 2404)A tool for checking ANSI-C programs

E Cl k D K i d F L dE. Clarke, D. Kroening and F. Lerda

Tools and Algorithms for the Construction and Analysis of Systems, Spain, 2004 (LNCS 2988)y , p , ( )Backdoors To Typical Case Complexity. R. Williams, C. Gomes, and B. Selman. I t ti l J i t C f A tifi i l I t lliInternational Joint Conference on Artificial Intelligence

CS655 System

Modeling and Analysis

26/26