sat basic definitions

37
SAT: Propositional Satisfiability A tutorial

Upload: send2me

Post on 05-Feb-2016

222 views

Category:

Documents


0 download

DESCRIPTION

combinatorial calculation

TRANSCRIPT

Page 1: SAT basic definitions

SAT: Propositional Satisfiability

A tutorial

Page 2: SAT basic definitions

What is SAT?

SATisfying assignment!

Given a propositional formula in CNF, find an assignment to Boolean variables that makes the formula true:

1 = (x2 x3)

2 = (x1 x4)

3 = (x2 x4)

A = {x1=0, x2=1, x3=0, x4=1}

1 = (x2 x3)

2 = (x1 x4)

3 = (x2 x4)

A = {x1=0, x2=1, x3=0, x4=1}

Page 3: SAT basic definitions

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 4: SAT basic definitions

SAT made some progress…

1

10

100

1000

10000

100000

1960 1970 1980 1990 2000 2010

Year

Vars

Page 5: SAT basic definitions

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 of a general propositional formula to CNF, with addition of || variables.

Page 6: SAT basic definitions

(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 7: SAT basic definitions

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 8: SAT basic definitions

SAT basic definitions: clauses

The state of an n-literal 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 9: SAT basic definitions

SAT basic definitions: clauses

Example

Page 10: SAT basic definitions

SAT basic definitions: the unit clause rule

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

Page 11: SAT basic definitions

Given in CNF: (x,y,z),(-x,y),(-y,z),(-x,-y,-z)

Decide()

Deduce()

Resolve_Conflict()

-xx

-zz-yy

z -z y -y

() ()

(z ),(-z ) ()

(y),(-y,z ),(-y,-z )

()

() ()

(y),(-y)

(y,z ),(-y,z )

X

X X X X

A Basic SAT algorithm

Page 12: SAT basic definitions

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 13: SAT basic definitions

Backtracking Search in Action

1 = (x2 x3)

2 = (x1 x4)

3 = (x2 x4)

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 14: SAT basic definitions

Backtracking Search in Action

1 = (x2 x3)

2 = (x1 x4)

3 = (x2 x4)

4 = (x1 x2 x3)

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 15: SAT basic definitions

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 16: SAT basic definitions

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 17: SAT basic definitions

Let f*(x) be the # of unresolved shortest 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 18: SAT basic definitions

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)

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 19: SAT basic definitions

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)

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 20: SAT basic definitions

Non-chronological backtracking

Non-chronological backtracking

x1

4

5

6

Decision level

Which assignments caused the conflicts ? x9= 0@1

x10= 0@3

x11= 0@3

x12= 1@2

x13= 1@2

Backtrack to decision level 3

3

These assignmentsare sufficient forcausing a conflict.

Page 21: SAT basic definitions

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 22: SAT basic definitions

Non-chronological Backtracking

x1 = 0

x2 = 0

x3 = 1

x4 = 0

x5 = 0

x7 = 1

x9 = 0

x6 = 0

...x5 = 1

x9 = 1

x3 = 0

Page 23: SAT basic definitions

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

Page 24: SAT basic definitions

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 25: SAT basic definitions

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 26: SAT basic definitions

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 27: SAT basic definitions

Conflict-driven Backtracking

x1 = 0

x2 = 0

x3 = 1

x4 = 0

x5 = 0

x5 = 1

x7 = 1

x3 = 1

x9 = 0

x9 = 1

x6 = 0

...

Page 28: SAT basic definitions

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 29: SAT basic definitions

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 30: SAT basic definitions

Conflict clauses and Resolution

The Resolution is a sound inference rule:

Example:

Page 31: SAT basic definitions

Consider the following example:

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

Conflict clauses and resolution

Page 32: SAT basic definitions

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

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

Conflict clauses and resolution

Page 33: SAT basic definitions

Applied to our example:

Finding the conflict clause:

cl is asserting the first UIP

Page 34: SAT basic definitions

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 35: SAT basic definitions

Numerous progressing heuristics

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

Page 36: SAT basic definitions

The K-Coloring problem:Given an undirected graph G(V,E) and a natural number k, is there an assignment color:

Formulation of problems as SAT :k-Coloring

Page 37: SAT basic definitions

Formulation of problems as SAT :k-Coloring

xi,j = node i is assigned the ‘color’ j (1 i n, 1 j k)

Constraints:i) At least one color to each node: (x1,1 x1,2 … x1,k …)

ii) At most one color to each node: )( ,,

1

1

11tiji

k

jt

k

j

n

ixx

iii) Coloring constraints: for each i,j such that (i,j) 2 E:

)(V ,11

ji

k

j

n

ix

)( ,,1

cjci

k

cxx