Boolean Satisfiability Solvers Wonhong Nam

advertisement
Boolean Satisfiability Solvers
Wonhong Nam
wnam@cis.upenn.edu
Satisfiability

Boolean formula: f(v1, v2, v3, …)




Applications




Find an assignment to variables such that f(t1, t2, t3, …)
=T
Or show that there is no such an assignment: f(v1, v2, v3,
…) = F
NP-complete problem
EDA(Electronic Design Automation)
AI
Bound Model Checking
Tools

GRASP, SATO, Chaff and so on.
2002-11-19
CIS640
2
Outline
Introduction
 The Basic DPLL Framework
 Branching Heuristics
 Deduction Algorithm
 Conflict Analysis and Learning
 Performance Comparison
 Conclusion

2002-11-19
CIS640
3
Introduction

Formula specified in CNF.


f(v1, v2, v3) = (v1 + v2 + ¬v3) & (v1 + ¬v2) & (¬v1)
Advantages
In order to satisfy a formula, all of the clauses must be satisfied.
 In order to satisfy each clause, at least one of the literals must
be satisfied.



This example is satisfiable with v1 = F, v2 = F, v3 = F
Deduce
(v1 + v2 + ¬v3), v1 = F, v2 = F  v3 = F

Conflict
(v1 + v2 + ¬v3) & (V3), v1 = F, v2 = F  conflict
2002-11-19
CIS640
4
The Basic DPLL Framework (1/2)
DPLL(formula, assignment) {
necessary = deduction(formula, assignment);
new_asgnmnt = union(necessary, assignment);
if(is_satisfied(formula, new_asgnmnt))
return SATISFIABLE;
else if(is_conflicting(formula, new_asgnmnt))
return CONFLICT;
var = choose_free_variable(formula, new_asgnmnt);
asgn1 = union(new_asgnmnt, assign(var, 1));
if(DPLL(formula, asgn1)==SATISFIABLE)
return SATISFIABLE;
else {
asgn2 = union(new_asgnmnt, assign(var, 0));
return DPLL(formula, asgn2);
}
}
2002-11-19
CIS640
5
The Basic DPLL Framework (2/2)
status = preprocess();
if(status!=UNKNOWN) return status;
while(1){
decide_next_branch();
while(1){
status = deduce();
if(status == CONFLICT){
blevel = analyze_conflict();
if(blevel == 0)
return UNSATISFIABLE;
else backtrack(blevel);
} else if (status == SATISFIABLE){
return SATISFIABLE;
} else
break;
}
}
2002-11-19
CIS640
6
Branching Heuristics
A lack of clear statistical evidence
 Some common strategies




RAND
The maximization of some complex functions of the
current variable state and the clause. (BOHM and MOMs
heuristics)
DLIS(Dynamic Largest Individual Sum) heuristic


How to evaluate strategies.


to select the literal that appears most frequently in unresolved
clauses.
No clear answer.
Chaff: VSIDS(Variable State Independent Decaying Sum)
2002-11-19
CIS640
7
VSIDS

Observation


Strategy




The conflict clauses primarily make the search process
to be difficult problems.
Each variable in each polarity has a counter, initialized
to 0.
When a conflict clause is occurred, the counter
associated with each literal in the clause is incremented.
The variable and polarity with the highest counter is
chosen at each decision.
It has low overhead since the statistics are
only updated when there is a new conflict
clause.
2002-11-19
CIS640
8
The Basic DPLL Framework
status = preprocess();
if(status!=UNKNOWN) return status;
while(1){
decide_next_branch();
while(1){
status = deduce();
if(status == CONFLICT){
blevel = analyze_conflict();
if(blevel == 0)
return UNSATISFIABLE;
else backtrack(blevel);
} else if (status == SATISFIABLE){
return SATISFIABLE;
} else
break;
}
}
2002-11-19
CIS640
9
Deduction Algorithm(BCP)
Most of SAT solver spent about 80% of
running time in deduce().
 Unit clause



( v1 + v2 + ¬v3 ), v1=F, v2=F  v3 = F
When can it occur?



All-but-one literals in a clause are assigned to 0
BCP(Boolean Constraint Propagation)
How implement?

Keeping counters for each clause.
GRASP, rel_sat, satz etc.
 GRASP - Each clause keeps two counters.




2002-11-19
For the number of value 1 literals in the clause.
For the number of value 0 literals in the clause.
if(# of literals - # of 0 literals == 1) unit clause.
CIS640
10
BCP (1/3)

SATO – head/tail pointers.

Each clause has two pointers.



The head points to the first free literal of the clause.
The tail points to the last free literal of the clause.
Advantage over counter method


2002-11-19
Only when the literals pointed by the head or the tail are
assigned to 0, the pointer moves.
When the variable is assigned value 1, the clauses that
contain the positive literal will not be visited at all and
vice-versa.
CIS640
11
BCP (2/3)

Chaff – watched literals.
Observation – Undoing during backtracking has
some computation that can be reduced.
 Two watched literal pointers.




There is no imposed order on the two pointers within a
clause.
Each of the pointers can move in either direction.
Advantage


2002-11-19
The same advantage as the head/tail mechanism
compared with the counting scheme.
Undoing takes less time because the watched literal
pointers do not need to move.
CIS640
12
BCP (3/3)
2002-11-19
CIS640
13
The Basic DPLL Framework
status = preprocess();
if(status!=UNKNOWN) return status;
while(1){
decide_next_branch();
while(1){
status = deduce();
if(status == CONFLICT){
blevel = analyze_conflict();
if(blevel == 0)
return UNSATISFIABLE;
else backtrack(blevel);
} else if (status == SATISFIABLE){
return SATISFIABLE;
} else
break;
}
}
2002-11-19
CIS640
14
Conflict Analysis and Learning (1/3)

When a conflicting clause occurs,


The solver needs to backtrack and undo the decisions.
Chronological backtracking


The solver keeps a flag indicating whether it has been
tried in both phases or not.
When a conflicting clause occurs,
The solver looks for the decision variable with the latest decision
level that has not been flipped,
 marks it flipped,
 undoes all the assignments between that decision level and
current decision level,
 and then tries the other phase for the decision variable.


v1 = T, v2 = F, v3 = T, v3 = F.
2002-11-19
CIS640
15
Conflict Analysis and Learning (2/3)

Non-chronological backtracking


Backtrack to an earlier decision level than the last
unflipped decision.
Conflict-directed learning

The information about the current conflict may be added
to the original formula.


GRASP, rel_sat, SATO and Chaff
Resolution
To generate a clause from two clauses like the process of
consensus in the logic optimization domain.
( x + y ) & ( ¬y + z) ≡ ( x + y ) & ( ¬y + z) & ( x + z )
 Resolvent



Redundant

2002-11-19
( x + y ) & ( ¬y + z)  ( x + z )
Adding the resolvent does not change the satisfiability of the original
formula.
CIS640
16
Conflict Analysis and Learning (3/3)

Learning
The conflict analysis will add some clauses to
the original formula.
 The redundant resolvent avoids making the
same mistake in the future search.


F = (a+b) & (¬a+¬b+¬c) & (¬b+c) &…
Pick “a=true”, no deduction.
 Pick “b=true”.



2002-11-19
Conflict occurs between (¬a+¬b+¬c) and (¬b+c).
Resolvent: (¬a+¬b)
CIS640
17
Performance Comparison
2002-11-19
CIS640
18
Conclusion

Techniques employed in modern
Boolean Satisfiability solvers.
DPLL search algorithm
 Branching Heuristics
 Deduction Algorithm
 Conflict Analysis and Learning


Currently, zChaff is best SAT solver in
both industrial and handmade
benchmarks.
2002-11-19
CIS640
19
Download