Heuristics for Efficient SAT Solving

63
Heuristics for Efficient SAT Solving As implemented in GRASP, Chaff and GSAT .

description

Heuristics for Efficient SAT Solving. As implemented in GRASP , Chaff and GSAT . Why SAT?. Fundamental problem from theoretical point of view Cook theorem, 1971: the first NP-complete problem. Numerous applications: Solving any NP problem... - PowerPoint PPT Presentation

Transcript of Heuristics for Efficient SAT Solving

Page 1: Heuristics for Efficient SAT Solving

Heuristics forEfficient SAT Solving

As implemented in GRASP, Chaff and GSAT.

Page 2: Heuristics for Efficient SAT Solving

Why SAT?• Fundamental problem from theoretical point of

view– Cook theorem, 1971: the first NP-complete problem.

• Numerous applications:– Solving any NP problem...– Verification: Model Checking, theorem-proving, ...– AI: Planning, automated deduction, ...– Design and analysis: CAD, VLSI– Physics: statistical mechanics (models for spin-glass

material)

Page 3: Heuristics for Efficient SAT Solving

SAT made some progress…

1

10

100

1000

10000

100000

1960 1970 1980 1990 2000 2010

Year

Vars

Page 5: Heuristics for Efficient SAT Solving

Agenda

• Modeling problems in Propositional Logic• SAT basics• Decision heuristics• Non-chronological Backtracking• Learning with Conflict Clauses• SAT and resolution• More techniques: decision heuristics, deduction.• Stochastic SAT solvers: the GSAT approach

Page 6: Heuristics for Efficient SAT Solving

Agenda Modeling problems in Propositional Logic SAT basics Decision heuristics Non-chronological Backtracking Learning with Conflict Clauses SAT and resolution More techniques: decision heuristics,

deduction. Stochastic SAT solvers: the GSAT approach

Page 7: Heuristics for Efficient SAT Solving

CNF-SAT Conjunctive Normal Form: Conjunction of

disjunction of literals. Example:(:x1 Ç :x2) Æ (x2 Ç x4 Ç : x1) Æ ...

Experience shows that CNF-SAT solving is faster than solving a general propositional formula.

There exists a polynomial transformation due to Tseitin (1970) of a general propositional formula to CNF, with addition of || variables.

Page 8: Heuristics for Efficient SAT Solving

(CNF) SAT basic definitions: literals A literal is a variable or its negation. Var(l) is the variable associated with a literal l. A literal is called negative if it is a negated

variable, and positive otherwise.

Page 9: Heuristics for Efficient SAT Solving

SAT basic definitions: literals If var(l) is unassigned, then l is unresolved. Otherwise, l is satisfied by an assignment if

(var(l)) = 1 and l is positive, or (var(l)) = 0 and l is negative,

and unsatisfied otherwise.

Page 10: Heuristics for Efficient SAT Solving

SAT basic definitions: clauses

The state of an n-long clause C under a partial assignment is: Satisfied if at least one of C’s literals is

satisfied, Conflicting if all of C’s literals are

unsatisfied, Unit if n-1 literals in C are unsatisfied and 1

literal is unresolved, and Unresolved otherwise.

Page 11: Heuristics for Efficient SAT Solving

SAT basic definitions: clauses

Example

Page 12: Heuristics for Efficient SAT Solving

SAT basic definitions: the unit clause rule

The unit clause rule: in a unit clause the unresolved literal must be satisfied.

Page 13: Heuristics for Efficient SAT Solving

Basic Backtracking Search

Organize the search in the form of a decision tree

Each node corresponds to a decision Depth of the node in the decision tree is

called the decision level Notation: x=v@d

x is assigned v 2 {0,1} at decision level d

Page 14: Heuristics for Efficient SAT Solving

Backtracking Search in Action

1 = (x2 x3)

2 = (x1 x4)

3 = (x2 x4)

x1

x1 = 0@1

{(x1,0), (x2,0), (x3,1)}

x2 x2 = 0@2

{(x1,1), (x2,0), (x3,1) , (x4,0)}

x1 = 1@1

x3 = 1@2

x4 = 0@1 x2 = 0@1

x3 = 1@1

No backtrack in this example, regardless of the decision!

Page 15: Heuristics for Efficient SAT Solving

Backtracking Search in Action

1 = (x2 x3)

2 = (x1 x4)

3 = (x2 x4)

4 = (x1 x2 x3)

Add a clause

x4 = 0@1

x2 = 0@1

x3 = 1@1

conflict{(x1,0), (x2,0), (x3,1)}

x2

x2 = 0@2 x3 = 1@2

x1 = 0@1 x1

x1 = 1@1

Page 16: Heuristics for Efficient SAT Solving

While (true){

if (!Decide()) return (SAT); while (!Deduce())

if (!Resolve_Conflict()) return (UNSAT);}

Choose the next variable and value.Return False if all

variables are assigned

Apply unit clause rule.Return False if reached

a conflict

Backtrack until no conflict.

Return False if impossible

A Basic SAT algorithm (DPLL-based)

Page 17: Heuristics for Efficient SAT Solving

Agenda Modeling problems in Propositional Logic SAT basics Decision heuristics Non-chronological Backtracking Learning with Conflict Clauses SAT and resolution More techniques: decision heuristics,

deduction. Stochastic SAT solvers: the GSAT approach

Page 18: Heuristics for Efficient SAT Solving

Maintain a counter for each literal: in how many unresolved clauses it appears ?

Decide on the literal with the largest counter. Requires O(#literals) queries for each

decision.

Decision heuristics DLIS (Dynamic Largest Individual Sum)

Page 19: Heuristics for Efficient SAT Solving

Compute for every clause and every literal l:

J(l) :=

Choose a variable l that maximizes J(l).

This gives an exponentially higher weight to literals in shorter clauses.

,

||2l

Decision heuristicsJeroslow-Wang method

Page 20: Heuristics for Efficient SAT Solving

Let f*(x) be the # of unresolved smallest clauses containing x. Choose x that maximizes: ((f*(x) + f*(!x)) * 2k + f*(x) * f*(!x)

k is chosen heuristically. The idea:

Give preference to satisfying small clauses. Among those, give preference to balanced

variables (e.g. f*(x) = 3, f*(!x) = 3 is better than f*(x) = 1, f*(!x) = 5).

Decision heuristicsMOM (Maximum Occurrence of clauses of Minimum size).

Page 21: Heuristics for Efficient SAT Solving

Pause...

We will see other (more advanced) decision Heuristics soon.

These heuristics are integrated with a mechanism called Learning with Conflict-Clauses, which we will learns next.

Page 22: Heuristics for Efficient SAT Solving

Agenda Modeling problems in Propositional Logic SAT basics Decision heuristics Non-chronological Backtracking Learning with Conflict Clauses SAT and resolution More techniques: decision heuristics,

deduction. Stochastic SAT solvers: the GSAT approach

Page 23: Heuristics for Efficient SAT Solving

Implication graphs and learning

1 = (x1 x2)

2 = (x1 x3 x9)

3 = (x2 x3 x4)

4 = (x4 x5 x10)

5 = (x4 x6 x11)

6 = (x5 x6)

7 = (x1 x7 x12)

8 = (x1 x8)

9 = (x7 x8 x13)

Current truth assignment: {x9=0@1 ,x10=0@3, x11=0@3, x12=1@2, x13=1@2}

Current decision assignment: {x1=1@6}

6

6

conflict

x9=0@1

x1=1@6

x10=0@3

x11=0@3

x5=1@64

4

5

5 x6=1@62

2

x3=1@6

1

x2=1@6

3

3

x4=1@6

We learn the conflict clause 10 : (: x1 Ç x9 Ç x11 Ç x10)

and backtrack to the highest (deepest) dec. level in this clause (6).

Page 24: Heuristics for Efficient SAT Solving

Implication graph, flipped assignment

x1=0@6

x11=0@3

x10=0@3

x9=0@1

x7=1@6

x12=1@2

7

7

x8=1@6

8

10

10

10 9

9

x13=1@2

9

Due to the conflict clause

1 = (x1 x2)

2 = (x1 x3 x9)

3 = (x2 x3 x4)

4 = (x4 x5 x10)

5 = (x4 x6 x11)

6 = (x5 x6)

7 = (x1 x7 x12)

8 = (x1 x8)

9 = (x7 x8 x13)

10 : (: x1 Ç x9 Ç x11 Ç x10)

We learn the conflict clause 11 : (:x13 Ç x9 Ç x10 Ç x11 Ç :x12)

and backtrack to the highest (deepest) dec. level in this clause (3).

Page 25: Heuristics for Efficient SAT Solving

Non-chronological backtracking

Non-chronological backtracking

x1

4

5

6

Decision level

Which assignments caused the conflicts ? x9= 0@1x10= 0@3x11= 0@3x12= 1@2x13= 1@2

Backtrack to decision level 3

3

These assignmentsAre sufficient forCausing a conflict.

Page 26: Heuristics for Efficient SAT Solving

Non-chronological backtracking (option #1)

So the rule is: backtrack to the largest decision level in the conflict clause.

Q: What if the flipped assignment works ? A: continue to the next decision level, leaving the current one without a decision variable.

Backtracking back to this level will lead to another conflict and further backtracking.

Page 27: Heuristics for Efficient SAT Solving

Non-chronological Backtracking

x1 = 0

x2 = 0

x3 = 1

x4 = 0

x5 = 0x7 = 1

x9 = 0

x6 = 0

...x5 = 1

x9 = 1

x3 = 0

Page 28: Heuristics for Efficient SAT Solving

More Conflict Clauses Def: A Conflict Clause is any clause implied by the

formula Let L be a set of literals labeling nodes that form a cut

in the implication graph, separating the conflict node from the roots.

Claim: Çl2L:l is a Conflict Clause.

5

5 x6=1@6

6

6

conflict

x9=0@1

x1=1@6

x10=0@3

x11=0@3

x5=1@64

4

2

2

x3=1@6

1

x2=1@6

3

3

x4=1@6

1. (x10 Ç :x1 Ç x9 Ç x11)

2. (x10 Ç :x4 Ç x11)

3. (x10 Ç :x2 Ç :x3 Ç x11)

12

3

Skip alternative learning

Page 29: Heuristics for Efficient SAT Solving

Conflict clauses

How many clauses should we add ? If not all, then which ones ?

Shorter ones ? Check their influence on the backtracking

level ? The most “influential” ?

The answer requires two definitions: Asserting clauses Unique Implication points (UIP’s)

Page 30: Heuristics for Efficient SAT Solving

Asserting clauses Def: An Asserting Clause is a Conflict Clause

with a single literal from the current decision level. Backtracking (to the right level) makes it a Unit clause.

Modern solvers only consider Asserting Clauses.

Page 31: Heuristics for Efficient SAT Solving

Unique Implication Points (UIP’s) Def: A Unique Implication Point (UIP) is an internal node in

the Implication Graph that all paths from the decision to the conflict node go through it.

The First-UIP is the closest UIP to the conflict. The method of choice: an asserting clause that includes

the first UIP. In this case (x10 Ç :x4 Ç x11).

5

5

6

6

conflict

4

4

2

2

1 3

3

UIPUIP

x10=0@3

x11=0@3

x4=1@6

Page 32: Heuristics for Efficient SAT Solving

Conflict-driven backtracking (option #2)

Previous method: backtrack to highest decision level in conflict clause (and erase it).

A better method (empirically): backtrack to the second highest decision level in the clause, without erasing it. The asserted literal is implied at that level.

In our example: (x10 Ç :x4 Ç x11) Previously we backtracked to decision level 6. Now we backtrack to decision level 3. x4 = 0@3 is implied.

63 3

Page 33: Heuristics for Efficient SAT Solving

Conflict-driven Backtrackingx1 = 0

x2 = 0

x3 = 1

x4 = 0

x5 = 0

x5 = 1

x7 = 1

x3 = 1

x9 = 0

x9 = 1

x6 = 0

...

Page 34: Heuristics for Efficient SAT Solving

Conflict-Driven Backtracking So the rule is: backtrack to the second highest

decision level dl, but do not erase it. If the conflict clause has a single literal, backtrack to

decision level 0.

Q: It seems to waste work, since it erases assignments in decision levels higher than dl, unrelated to the conflict.

A: indeed. But allows the SAT solver to redirect itself with the new information.

Page 35: Heuristics for Efficient SAT Solving

DecisionConflict

Decision Level

Time

work invested in refuting x=1

(some of it seems wasted)

Cx=1 Refutation of x=1

C1

C5

C4

C3

C2

Progress of a SAT solver

BCP

Page 36: Heuristics for Efficient SAT Solving

Agenda Modeling problems in Propositional Logic SAT basics Decision heuristics Non-chronological Backtracking Learning with Conflict Clauses SAT and resolution More techniques: decision heuristics,

deduction. Stochastic SAT solvers: the GSAT approach

Page 37: Heuristics for Efficient SAT Solving

Conflict clauses and Resolution

The Binary-resolution is a sound inference rule:

Example:

Page 38: Heuristics for Efficient SAT Solving

Consider the following example:

Conflict clause: c5: (x2 Ç :x4 Ç x10)

Conflict clauses and resolution

Page 39: Heuristics for Efficient SAT Solving

Conflict clause: c5: (x2 Ç :x4 Ç x10)

Resolution order: x4,x5,x6,x7 T1 = Res(c4,c3,x7) = (:x5 Ç :x6) T2 = Res(T1, c2, x6) = (:x4 Ç :x5 Ç X10 ) T3 = Res(T2,c1,x5) = (x2 Ç :x4 Ç x10 )

Conflict clauses and resolution

Page 40: Heuristics for Efficient SAT Solving

Applied to our example:

Finding the conflict clause:

cl is asserting the first UIP

Page 41: Heuristics for Efficient SAT Solving

The Resolution-Graph keeps track of the “inference relation”

1

2

3

4

5

6

10

7

8

9

11

5

5

6

6 conflict

4

4

2

2

1 3

3

7

7

8

10

10

10 9

9

conflict

9

Resolution Graph

Page 42: Heuristics for Efficient SAT Solving

The resolution graphWhat is it good for ? Example: for computing an Unsatisfiable core

[Picture Borrowed from Zhang, Malik SAT’03]

Page 43: Heuristics for Efficient SAT Solving

Resolution graph: example

L :

Inferred clauses

Empty clause

Original clauses

) (

(x1 x3 !x2) (x2 x6)

(x1 x3 x6)

(!x3 !x4) (!x3 x4)

(!x3)

(!x6) (!x1) (x3)

(x1 x6)

(x1)

(x4)

Unsatisfiable core

learning

Page 44: Heuristics for Efficient SAT Solving

Agenda Modeling problems in Propositional Logic SAT basics Decision heuristics Non-chronological Backtracking Learning with Conflict Clauses SAT and resolution More techniques: decision heuristics, deduction. Stochastic SAT solvers: the GSAT approach

Page 45: Heuristics for Efficient SAT Solving

4. Periodically, all the counters are divided by a constant.3. The unassigned variable with the highest counter is chosen.

2. When a clause is added, the counters are updated.

1. Each variable in each polarity has a counter initialized to 0.

(Implemented in Chaff)

Decision heuristicsVSIDS (Variable State Independent Decaying Sum)

Page 46: Heuristics for Efficient SAT Solving

• Chaff holds a list of unassigned variables sorted by the counter value.

• Updates are needed only when adding conflict clauses.

• Thus - decision is made in constant time.

Decision heuristicsVSIDS (cont’d)

Page 47: Heuristics for Efficient SAT Solving

VSIDS is a ‘quasi-static’ strategy:

- static because it doesn’t depend on current assignment

- dynamic because it gradually changes. Variables that appear in recent conflicts have higher priority.

This strategy is a conflict-driven decision strategy.“..employing this strategy dramatically (i.e. an orderof magnitude) improved performance ... “

Decision heuristicsVSIDS (cont’d)

Page 48: Heuristics for Efficient SAT Solving

Decision Heuristics - Berkmin

Keep conflict clauses in a stack Choose the first unresolved clause in the

stack If there is no such clause, use VSIDS

Choose from this clause a variable + value according to some scoring (e.g. VSIDS)

This gives absolute priority to conflicts.

Page 49: Heuristics for Efficient SAT Solving

Berkmin heuristic

tail-first conflict clause

Page 50: Heuristics for Efficient SAT Solving

Deduction() allocates new implied variables and conflicts. How can this be done efficiently ?

Observation: More than 90% of the time SAT solvers perform Deduction().

More engineering aspects of SAT solvers

Page 51: Heuristics for Efficient SAT Solving

Hold 2 counters for each clause :

val1( ) - # of negative literals assigned 0 in + # of positive literals assigned 1 in .

val0() - # of negative literals assigned 1 in + # of positive literals assigned 0 in .

Grasp implements Deduction() with counters

Page 52: Heuristics for Efficient SAT Solving

Every assignment to a variable x results in updating the counters for all the clauses that contain x.

Grasp implements Deduction() with counters

is satisfied iff val1() > 0

is unsatisfied iff val0() = ||

is unit iff val1() = 0 val0() = || - 1

is unresolved iff val1() = 0 val0() < || - 1..

Backtracking: Same complexity.

Page 53: Heuristics for Efficient SAT Solving

Observation: during Deduction(), we are only interested in newly implied variables and conflicts.

These occur only when the number of literals in with value ‘false’ is greater than || - 2

Conclusion: no need to visit a clause unless (val0() > || - 2)

How can this be implemented ?

Chaff implements Deduction() with a pair of observers

Page 54: Heuristics for Efficient SAT Solving

Define two ‘observers’: O1(), O2(). O1() and O2() point to two distinct

literals which are not ‘false’. becomes unit if updating one

observer leads to O1() = O2(). Visit clause only if O1() or O2()

become ‘false’.

Chaff implements Deduction() with a pair of observers

Page 55: Heuristics for Efficient SAT Solving

Both observers of an implied clause are on the highest decision level present in the clause. Therefore, backtracking will un-assign them first.Conclusion: when backtracking, observers stay in place.

1 2 3 4 5

V[1]=0

1 2 3 4 5

V[5]=0, v[4]= 0

1 2 3 4 5

V[2]=0

O1 O2

1 2 3 4 5 Unit clause

Backtrackv[4] = v[5]= Xv[1] = 1

1 2 3 4 5

Backtracking: No updating. Complexity = constant.

Chaff implements Deduction() with a pair of observers

Page 56: Heuristics for Efficient SAT Solving

The choice of observing literals is important. Best strategy is - the least frequently updated variables.

The observers method has a learning curve in this respect:

1. The initial observers are chosen arbitrarily.

2. The process shifts the observers away from variables that were recently updated (these variables will most probably be reassigned in a short time).

In our example: the next time v[5] is updated, it will point to a significantly smaller set of clauses.

Chaff implements Deduction() with a pair of observers

Page 57: Heuristics for Efficient SAT Solving

Agenda Modeling problems in Propositional Logic SAT basics Decision heuristics Non-chronological Backtracking Learning with Conflict Clauses SAT and resolution More techniques: decision heuristics,

deduction. Stochastic SAT solvers: the GSAT approach

Page 58: Heuristics for Efficient SAT Solving

GSAT: stochastic SAT solving

for i = 1 to max_tries { T := randomly generated truth assignment for j = 1 to max_flips { if T satisfies return TRUE

choose v s.t. flipping v’s value gives largest increase in the # of satisfied clauses (break ties randomly). T := T with v’s assignment flipped. } }

Given a CNF formula , choose max_tries and max_flips

Many alternative heuristics

Page 59: Heuristics for Efficient SAT Solving

Numerous progressing heuristics

Hill-climbing Tabu-list Simulated-annealing Random-Walk Min-conflicts ...

Page 60: Heuristics for Efficient SAT Solving

Improvement # 1: clause weights

Initial weight of each clause: 1

Increase by k the weight of unsatisfied clauses.

Choose v according to max increase in weight

Clause weights is another example of conflict-driven decision strategy.

Page 61: Heuristics for Efficient SAT Solving

Improvement # 2: Averaging-in

Q: Can we reuse information gathered in previous tries in order to speed up the search ?

A: Yes! Rather than choosing T randomly each time, repeat ‘good assignments’ and choose randomly the rest.

Page 62: Heuristics for Efficient SAT Solving

Let X1, X2 and X3 be equally wide bit vectors.

Define a function bit_average : X1 X2 X3 as follows:

b1i b1

i = b2i

random otherwise

(where bji is the i-th bit in Xj, j {1,2,3})

Improvement # 2: Averaging-in (cont’d)

b3i :=

Page 63: Heuristics for Efficient SAT Solving

Improvement # 2: Averaging-in (cont’d)

Let Tiinit

be the initial assignment (T) in cycle i.

Let Tibest

be the assignment with highest # of satisfied clauses in

cycle i.

T1init := random assignment.

T2init := random assignment.

i > 2, Tiinit := bit_average(Ti-1

best, Ti-2best)