IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method...

30
IIT Bombay - CFDVS SAT Solvers Aditya Parameswaran Luv Kumar 1st June, 2005 and 14th June, 2005 Aditya Parameswaran, Luv Kumar: SAT Solvers, 1

Transcript of IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method...

Page 1: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

IIT Bombay - CFDVS

SAT Solvers

Aditya Parameswaran Luv Kumar

1st June, 2005 and 14th June, 2005

Aditya Parameswaran, Luv Kumar: SAT Solvers, 1

Page 2: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Outline

� Outline� The Satisfiability Problem� Types of Solvers� The basic DPLL Framework� Variations to the DPLL Algorithm

Branching HeuristicsDeduction MechanismConflict Analysis and LearningOther Techniques

� Stalmarcks Algorithm� More Details And Examples

Comparison of BerkMin and Chaff on Branching HeuristicsComparison of Chaff and SATO in BCP

� Local Search� Phase Transitions� More Details on Stalmarcks method

Equivalence Classes� References

Aditya Parameswaran, Luv Kumar: SAT Solvers, 2

Page 3: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

The Satisfiability Problem

I Given a Boolean propositional formula, does there existassignment of values such that the formula becomes true?

I We consider a CNF formula, C1 ∧ C2 ∧ C3 ∧ C4 . . . , where,

I Ci is a disjunction of literals like a,¬b, c , . . .

Aditya Parameswaran, Luv Kumar: SAT Solvers, 3

Page 4: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

The Satisfiability Problem

History of the SAT Problem

I Davis Putnam - Resolution based, 1960, later proposed Searchbased algorithm, 1962

I Proved NP Complete by Cook, 1971

I Stalmarcks algorithm - Patented, 1995

I Conflict driven Learning and Non chronological backtrackingin GRASP, 1996

I Local Search, 1997

I SATO - DPLL Based, 1997

I Chaff - DPLL Based, 2001

I BerkMin - DPLL Based, 2002

Aditya Parameswaran, Luv Kumar: SAT Solvers, 4

Page 5: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Types of Solvers

Two Types:

I Complete - find a solution or prove that none exist, e.g.Resolution, Search, Stalmarcks, BDDs

I Stochastic - do not prove unsatisfiability, can get somesolutions quickly, e.g. Local Search

Aditya Parameswaran, Luv Kumar: SAT Solvers, 5

Page 6: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

The basic DPLL Framework

Algorithm:

DPLL(formula, assignment) {if (deduce(formula, assignment) == SAT)

return SAT;else if (deduce(formula, assignment) == CONF)

return CONF;else {

v = new_variable(formula, assignment);a = new_assignment(formula, assignment, v, 0);if (DPLL(formula, a) == SAT)

return SAT;else {

a = new_assignment(formula, assignment, v, 1);return DPLL(formula, a);

}}

}Aditya Parameswaran, Luv Kumar: SAT Solvers, 6

Page 7: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Variations to the DPLL Algorithm

Iterative Algorithm

while(1) {decide_next_branch(); //branching heuristicswhile (true) {

status = deduce(); //deduction mechanismif (status == CONF) {

bl = analyze_conflict(); //conflict analysisif (bl == 0) return UNSAT;else backtrack(bl);

}else if (status == SATISFIABLE) return SAT;else break;

}}

Aditya Parameswaran, Luv Kumar: SAT Solvers, 7

Page 8: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Variations to the DPLL Algorithm

� Outline� The Satisfiability Problem� Types of Solvers� The basic DPLL Framework� Variations to the DPLL Algorithm

Branching HeuristicsDeduction MechanismConflict Analysis and LearningOther Techniques

� Stalmarcks Algorithm� More Details And Examples

Comparison of BerkMin and Chaff on Branching HeuristicsComparison of Chaff and SATO in BCP

� Local Search� Phase Transitions� More Details on Stalmarcks method

Equivalence Classes� References

Aditya Parameswaran, Luv Kumar: SAT Solvers, 8

Page 9: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Variations to the DPLL Algorithm

Branching Heuristics

I Branching Heuristics alter the search path and thereby changethe structure of the search tree

I In the original DPLL paper, a branch was randomly chosenI DLCS (Dynamic Largest Combined Sum)

• Introduced in GRASP• Pick the variable with largest number of occurrences in

unresolved clauses• State dependent• Considerable work reqd.• Static Statistic, does not take search history into consideration• Differentiation between learned and original clauses required.

Aditya Parameswaran, Luv Kumar: SAT Solvers, 9

Page 10: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Variations to the DPLL Algorithm

I VSIDS (Variable State Independent Decaying Sum)

• Introduced in Chaff• Choose variable with highest score to branch• Initial score is the number of clauses with the variable• Periodic division by a constant• Incrementation by a constant on addition of new clauses with

the variable• State Independent• Focus on recent clauses

I BerkMin method

• Simliar to the Chaff method• When a conflict occurs, all literals in the clauses responsible

for the conflict have their scores increased• Periodic divison by a constant• Branch on one of the variables present in the last added clause

Aditya Parameswaran, Luv Kumar: SAT Solvers, 10

Page 11: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Variations to the DPLL Algorithm

Deduction Mechanism

I Most important part of the solver (maximum time spent here)

I The function deduce() tries to see if by the currentassignment of values to variables, some conclusions can begot regarding the satisfiability of the formula

I It returns SAT if the assignment causes a satisfying instanceand CONF if it causes a conflict, else returns UNKNOWN andupdates the program state.

I All SAT solvers use the unit clause rule

I The unit clause rule states that if all but one of the literals ina clause are assigned false, then that literal is assigned true

I Such clauses are called unit clauses the unassigned literal is aunit literal, the process of assigning 1 to all such literals iscalled BCP (Boolean Constraint Propagation)

I Counter Method is used in GRASP, Head-Tail List Method isfrom SATO, and Two-Literal watch was first used in Chaff

Aditya Parameswaran, Luv Kumar: SAT Solvers, 11

Page 12: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Variations to the DPLL Algorithm

Deduction Mechanism (contd.)I Counter Method

• Simple method of keeping track of which clauses are satisfiedor conflicting

• Each clause has 3 variables: number of 1 value literals, numberof 0 value literals and total number of literals

• When number of 0 value literals equals total number, theclause is contradictory

• When number of 0 value literals equals total number minus oneand number of 1 value literals equals 0 then it is an unit clause

• With m clauses and n variables and on an average l literals perclause then on an average ml/n counters are updated

• Undo takes same number of operations

Aditya Parameswaran, Luv Kumar: SAT Solvers, 12

Page 13: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Variations to the DPLL Algorithm

I Head-Tail List method• Each clause maintains two pointers, the head and tail pointer• Each variable maintains 4 linked lists, pos-head, neg-head,

pos-tail, neg-tail, each of which contain pointers to the clauseswhich have their head/tail literal in the positive/negativephases of the variable.

• If v is assigned 1, then both the pos-lists will be ignored.• For each clause v in the neg-head list, the solver will search for

a literal which does not evaluate to 1 such that,1. If we first encounter a literal evaluating to 1, then the clause

is sat., and we stop2. If we first encounter a literal u that is free and u is not the tail

literal, then we move the head pointer3. If all literals are assigned 0, and tail literal is undefined, then it

is a unit clause with tail literal as unit literal4. If all literals are assigned 0 and tail literal is 0, then it is a

conflicting clause

• Repeat for neg-tail list, backwards• Average number of clauses to be updated, m/n, same on

backtrack

Aditya Parameswaran, Luv Kumar: SAT Solvers, 13

Page 14: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Variations to the DPLL Algorithm

I Two Literal Watch method

• Two literals “watched” in each clause• Each variable has two lists, pos-watched and neg-watched

containing pointers to all the clauses where the variable iswatched in positive or negative phases

• When a variable v is assigned a value 1, then for each clause inthe neg-watched list, we search for a literal that is not set to 0

1. If there is such a literal u, and it is not the other watchedliteral, then we make u the watched literal

2. If the only such u is the other watched literal, and its free,then it is a unit clause

3. If the only such u is the other watched literal and it evaluatesto 1, then it is sat.

4. If all literals in the clause are assigned 0 and no such u exists,then clause is conflicting

• Backtrack in constant time

Aditya Parameswaran, Luv Kumar: SAT Solvers, 14

Page 15: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Variations to the DPLL Algorithm

Conflict Analysis and Learning

I Conflict Analysis tries to find the reason for the conflict andtries to resolve it

I Original DPLL paper used Chronological Backtracking, inwhich the last assignment that has not been flipped is flipped

I Non-Chronological Backtracking need not flip the lastassignment and could backtrack to a earlier decision level

I This was first introduced in GRASP

I Conflict Directed Learning incorporates learned ConflictClauses

I Conflict Clauses are obtained using Implication Graphs

I In Implication Graphs, all the variables, whose values areeither known or are implied are depicted

I Directed edges are drawn from the variables that make up partof the unit clause implying the new variable (antecedents)

Aditya Parameswaran, Luv Kumar: SAT Solvers, 15

Page 16: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Variations to the DPLL Algorithm

In the conflict clause, we include the following:

I The antecedents of the conflict which are decisions made inthe current decision level

I The antecedents of the conflict in previous decision levels

I Recursively, this procedure is applied to the antecedents whichare part of the current decision level, but are not decisions

The backtrack level is the maximum of the decision levels of all thevariables in the conflict clause

Aditya Parameswaran, Luv Kumar: SAT Solvers, 16

Page 17: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Variations to the DPLL Algorithm

Other Techniques

I In the deduce() function, some solvers use the pure literal rulein addition to the unit clause rule

I Some solvers use Random Restarts inorder to discard thesearch tree and start over

I Some solvers have a function preprocess() which tries to arriveat conclusions before the start of the algorithm

I The learned clauses are deleted after a given period

Aditya Parameswaran, Luv Kumar: SAT Solvers, 17

Page 18: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Stalmarcks Algorithm

I Essentially breadth first search, we try both sides of a branchto find forced decisions

I To prove validity of a formula, we assume the formula to befalse, and try to arrive at a contradiction

I All formulae are represented using → and ⊥, which isrepresented as 0 in the triplet

I A formula is represented using a set of triplets

I A triplet (x , y , z) is an abbreviation for x ↔ (y → z)I Example: p → (q → p) is represented as

• (b1, q, p)• (b2, p, b1)

I A terminal triplet is one that gives a contradiction, like

• (0, q, 1)• (1, 1, 0)• (0, 0, x)

Aditya Parameswaran, Luv Kumar: SAT Solvers, 18

Page 19: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Stalmarcks Algorithm

I Triggering rules to be used for manipulation of formulae:

• (r1) (0,y ,z)y/1 z/0 (r2) (x,y ,1)

x/1

• (r3) (x,0,z)x/1 (r4) (x,1,z)

x/z

• (r5) (x,y ,0)x/¬y (r6) (x,x,z)

x/1

• (r7) (x,y ,y)x/1

• Dilemma rule (D1 and D2 are derivations, and S is theintersection of the assignments produced by the twoderivations)

T

T [x/1] T [x/0]

D1 D2

U[S1] V [S0]

T [S ]

• If one of the derivation leads to a contradiction, the result ofapplying the dilemma rule is the result of the other derivation

Aditya Parameswaran, Luv Kumar: SAT Solvers, 19

Page 20: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

More Details And Examples

Chaff Branching Algorithm (VSIDS)1. Each variable in each polarity has a counter initialized to the

number of instances of that variable with the polarity2. When a clause is added, each variable in the clause has its

value incremented3. Unassigned variable and polarity with the highest count

chosen at each decision; ties broken at random by default4. Periodic division by 2

BerkMin Branching Algorithm1. Each variable in each polarity has a counter initialized to the

number of instances of that variable with the polarity2. In case of a conflict scores of the variables in the conflict

clause and those responsible for the conflict are incremented3. Unassigned variable and polarity with the highest count

chosen at each decision from the most recent clause added tothe clause database; ties broken at random by default

4. Periodic division by 4

Aditya Parameswaran, Luv Kumar: SAT Solvers, 20

Page 21: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

More Details And Examples

BCP Algorithms:- SATO List Method

If (neg_assigned(literal)) { from-pos-head(literal);from-pos-tail(literal); }

If (pos_assigned(literal)) { from-neg-head(literal);from-neg-tail(literal); }

from-pos-head(literal) {for all the clauses in pos-head list

for i = head_lit + 1 to tail_litif (truth_val (ith literal) == unknown)

if (ith literal == tail literal)unit clause, add to unit clauses stackexclude clause; return

elsemove pointer to ith literal; return

else if (truth_val (ith literal) == TRUE)exclude clause; return

conflict }

Aditya Parameswaran, Luv Kumar: SAT Solvers, 21

Page 22: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

More Details And Examples

BCP Algorithms:- Two Literal Watch Method

If (neg_assigned(literal))for all the clauses in pos-watched list

if there is a literal != 0 and != o. w. literalmove the pointer to the given locationif (literal == 1) then exclude clause

else if (o. w. literal == undefined)unit clause, add to unit clauses listexclude clause

else if (o. w. literal == 1)exclude clause

elseconflict

end forIf (pos_assigned(literal))

for all the clauses in neg-watched list...

Aditya Parameswaran, Luv Kumar: SAT Solvers, 22

Page 23: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Local Search

I A cost function is assigned to every variable assignment, theprocedure tries to minimise the cost function by moving to“neighboring” assignments

I A greedy procedure is one which constantly tries to minimisethe cost function

I A move which does not change the cost function is a sidewaysmove with a sequence of such moves as a plateau

I Has a probability of getting stuck in a local minima. In orderto get out of a local minima, the following procedures areadopted:

1. Random Walk: With probability p, a random variable in anunsatisfied clause is flipped, and with prob. (1-p) the greedyalgorithm is followed

2. Random Noise: Same as above, with no restrictions on randomvariable

I In most cases, if the initial assignment is close to the globalminima, then the solution can be obtained by minimising thecost function

Aditya Parameswaran, Luv Kumar: SAT Solvers, 23

Page 24: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Local Search

GSAT Algorithm

a = set of clausesfor i = 1 to MAX_TRIES

T = a randomly generated truth assignmentfor j = 1 to MAX_FLIPS

if T satisfies a then return Tp = a prop. variable such that change in

its truth assignment gives the largestincrease in total number of clauses ofa that are satisfied by T

T = T with the truth assignment of p reversedend forreturn "no satifying assignment found"

end

Aditya Parameswaran, Luv Kumar: SAT Solvers, 24

Page 25: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Phase Transitions

I Clauses are created randomly of fixed lengthI The parameters of interest are: number of clauses(L), number

of variables(N) and number of literals/clause(K )I Formulae with few clauses are underconstrained and usually

satisfiableI Formulae with many clauses are overconstrained and usually

unsatisfiableI Satisfiability of formulae in either extreme is easy to determineI A phase transition tends to occur in between when the

problems are critically constrained and it is difficult todetermine their satisfiability

I For random 2-SAT, the transition has been proven to occur atL/N = 1

I For random 3-SAT, the transition has been experimentallyfound to occur at L/N ≈ 4.3

Aditya Parameswaran, Luv Kumar: SAT Solvers, 25

Page 26: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

Phase Transitions

Aditya Parameswaran, Luv Kumar: SAT Solvers, 26

Page 27: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

More Details on Stalmarcks method

Equivalence Classes

I Are used to show relationships between variablesI Two formulae are said to be in the same equivalence class,

denoted as a ∼ b, if they have the same truth valueI It is not necessary to store the complementary classI Initially there are the individual variable “undeterminate”

equivalence classes, and also the > and ⊥ classesI Propagation rules merge atleast two equivalence classes, as

the proof progressesI Instead of branching on truth/false we can branch by merging

equivalence classes (A ≡ B or A ≡ ¬B)

Aditya Parameswaran, Luv Kumar: SAT Solvers, 27

Page 28: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

More Details on Stalmarcks method

Hardness, Proof Depth and Saturation

I A proof is said to be k-hard if there is no proof involving lessthan k applications of the dilemma rule, and there exists aproof which involves k applications of dilemma rule

I Proof Depth has the following definition:

• Simple rules have 0 depth• Composition of two simple proofs R1 to R2 and R2 to R3 has as itsdepth the maximum of the two above proofs• During the dilemma rule if the two branches have depth d1 and d2

then the depth of the whole system is max(d1, d2) + 1

I Alternatively, proof depth is the maximum number ofsimultaneously open branches

I A relation is k-saturated iff proofs of depth k or less do notadd any equivalences between the subformulas

Aditya Parameswaran, Luv Kumar: SAT Solvers, 28

Page 29: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

References

1. M Davis and H Putnam, A computing procedure forquantification theory, Journal of ACM (1960)

2. M Davis, G Logemann and D Loveland, A machine programfor theorem proving, Communications of ACM (1962)

3. H Zhang, SATO: An efficient propositional prover, Conf. onAutomated deduction (1997)

4. H Zhang and M Stickel, An efficient algorithm for unitpropagation, Int. Symp. on AI and mathematics, 1996

5. E Goldberg and Y Novikov, BerkMin: A fast and robust SATsolver, DATE - 2002

6. J P Marques Silva and K A Sakallah, GRASP: A new searchalgorithm for satisfiability, IEEE (Int. Conf. on tools with AI)- 1996

7. M Sheeran and G Stalmarck, A tutorial on Stalmarcks proofprocedure for propositional logic

8. M Moskewicz, C Madigan, Y Zhao, L Zhang and S Malik,Chaff: Engineering an efficient SAT solver, 39th Design

Aditya Parameswaran, Luv Kumar: SAT Solvers, 29

Page 30: IIT Bombay - CFDVS SAT Solvers · Deduction Mechanism (contd.) I Counter Method • Simple method of keeping track of which clauses are satisfied or conflicting • Each clause

References

Automation Conf. 20019. B Selman, H Levesque and D Mitchell, A new method for

solving hard satisfiability problems, National Conf. on AI, July1992

10. SAT Course material,http://www.inf.ed.ac.uk/teaching/courses/propm/papers/Zhang/

11. SAT solving, basic principles and directions,http://www-ti.informatik.uni-tuebingen.de/∼fmg/teaching/verif0405/BMC.pdf

12. S Malik and L Zhang, Quest for Efficient BooleanSatisfiability Solvers

13. S Malik, Quest for Efficient Boolean Satisfiability SolversPresentation,www.inf.ed.ac.uk/teaching/courses/propm/papers/cav-cade2002.pdf

All of these are available at www.cse.iitb.ac.in/∼ adityagp/sat/

Aditya Parameswaran, Luv Kumar: SAT Solvers, 30