מבוא לאימות תוכנה תרגול 11 SAT Solvers The SAT Problem Boolean Satisfiability Problem • Given a Boolean formula (v̅), look for assignment A for v̅ such that (A(v̅))=true . – A is a solution for (v̅). • A partial assignment assigns a subset of v̅. • CNF representation of (v̅): – (v̅) is a conjunction of clauses: (v̅)=cl1cl2… cln. – A clause is a disjunction of literals: cli=(lit1…litl). – A satisfies (v̅) ↔ A satisfies all its clauses. SAT Usage • • • • Verification: symbolic algorithms, CBMC Automatic theorem proving Solve any NP problem Artificial Intelligence: planning, automated deduction and many more… SAT Made Some Progress 100000 10000 Vars 1000 100 10 1 1960 1970 1980 1990 Year 2000 2010 Boolean Constraint Propagation • Unit Clause : A clause with exactly one unassigned literal, while all the rest are false. – Asserts the value of the unassigned variable. a=0 b=? c=1 cl = (a b c) b=0 – cl implies b and is its antecedent. – a and c are the antecedent variables of b. • BCP(): Calculates all the possible implications. Returns conflict / no-conflict. DPLL: Davis Putnam Logemann Loveland Backtrack Search Running on the formula: ¬𝑥6 ∨ ¬𝑥14 ∧ ¬𝑥6 ∨ 𝑥3 ∧ x1 ∨ ¬𝑥3 ∨ 𝑥18 ∧ ¬𝑥18 ∨ 𝑥4 ∧ ¬𝑥4 ∨ 𝑥14 ∨ ¬𝑥2 ∧ ¬𝑥8 ∨ ¬𝑥10 ∧ ¬𝑥8 ∨ 𝑥10 ∨ 𝑥7 ∧ 𝑥9 ∨ 𝑥5 ∨ 𝑥10 ∧ ¬𝑥5 ∨ ¬𝑥3 ∨ ¬𝑥9 ∧ ¬𝑥9 ∨ 𝑥15 ∧ ¬𝑥15 ∨ 𝑥14 ∨ ¬𝑥9 ∧ (𝑥8 ∨ 𝑥11 ) DPLL: Davis Putnam Logemann Loveland Backtrack Search • Choose a decision variable and value. x6 DPLL: Davis Putnam Logemann Loveland Backtrack Search • Choose a decision variable and value. • Run bcp() x6 ¬x14 x3 DPLL: Davis Putnam Logemann Loveland Backtrack Search • Choose a decision variable and value. • Run bcp() x6 ¬x14 x3 ¬x1 DPLL: Davis Putnam Logemann Loveland Backtrack Search • Choose a decision variable and value. • Run bcp() x6 ¬x14 x3 ¬x1 x18 x4 ¬x2 DPLL: Davis Putnam Logemann Loveland Backtrack Search • Choose a decision variable and value. • Run bcp() x6 ¬x14 x3 ¬x1 x18 x4 ¬x2 x8 DPLL: Davis Putnam Logemann Loveland Backtrack Search • Choose a decision variable and value. • Run bcp() x6 ¬x14 x3 ¬x1 x18 x4 ¬x2 x8 ¬x10 x7 DPLL: Davis Putnam Logemann Loveland Backtrack Search • Choose a decision variable and value. • Run bcp() • If a conflict occurs – Flip the highest decision variable not yet flipped. x6 ¬x14 x3 ¬x1 x18 x4 ¬x2 x8 ¬x10 x7 ¬x9 DPLL: Davis Putnam Logemann Loveland Backtrack Search • Choose a decision variable and value. • Run bcp() • If a conflict occurs – Flip the highest decision variable not yet flipped. x6 ¬x14 x3 ¬x1 x18 x4 ¬x2 x8 ¬x10 x7 ¬x9 x5 ¬x3 DPLL: Davis Putnam Logemann Loveland Backtrack Search • Choose a decision variable and value. • Run bcp() • If a conflict occurs – Flip the highest decision variable not yet flipped. – Mark as flipped. x6 ¬x14 x3 ¬x1 x18 x4 ¬x2 x8 ¬x10 x7 x9** DPLL: Davis Putnam Logemann Loveland Backtrack Search • Choose a decision variable and value. • Run bcp() • If a conflict occurs – flip the highest decision variable not yet flipped. – Mark as flipped – Run bcp(). x6 ¬x14 x3 ¬x1 x18 x4 ¬x2 x8 ¬x10 x7 x9** x15 x14 DPLL: Davis Putnam Logemann Loveland Backtrack Search • Choose a decision variable and value. • Run bcp() • If a conflict occurs – flip the highest decision variable not yet flipped. – Mark as flipped – Run bcp(). x6 ¬x14 x3 ¬x1 x18 x4 ¬x2 ¬x8** x9** x15 x14 DPLL: Davis Putnam Logemann Loveland Backtrack Search • Choose a decision variable and value. • Run bcp() • If a conflict occurs – flip the highest decision variable not yet flipped. – Mark as flipped – Run bcp(). x6 ¬x14 x3 ¬x1 x18 x4 ¬x2 ¬x8** x11 DPLL: Davis Putnam Logemann Loveland Backtrack Search • Termination – No unassigned variables – SAT – No decision variable to flip – un-SAT The SAT Problem - Resolution • Given a Boolean formula (v̅) in CNF, for clauses cl1=(A v) and cl2=(B v) . – resolution(cl1,cl2)=(A B) • For c=resolution(c1,c2) – (v̅) c – (v̅) (v̅) c Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 Conflict (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: Cuts x7 ¬x5 x3 ¬x9 ¬x8 x12 Conflict x19 x4 ¬x1 ¬x6 ¬x3 Learning: Conflict Clauses Reason Side ¬x5 x3 ¬x9 ¬x8 x12 Conflict x19 x4 Conflict Side x7 ¬x1 ¬x3 ¬x6 • x7, x5, x8,x19, x6 are the reason for the conflict. • Adding the clause (x5 x7 x6 x19 x8) will prevent it in the future. Learning: Conflict Clauses X1 0 X2 The clause (x2,x3) is 0 created after a conflict X3 0 1 X2 1 0 X3 X3 1 X3 0 The search tree is pruned accordingly Which cut should we choose\ which conflict clause should we choose? Learning: Asserting Clause Asserting Clause: a Conflict Clause with a single literal at the largest decision level. – Backtracking (to the right level) makes it a Unit clause. Modern solvers only consider Asserting Clauses. Learning: Implication Graph (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 Conflict (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 ¬x3 (x1,¬x12,x19) (x1,¬x6) ¬x6 (x6,¬x19,x8,¬x7,¬x3) Learning: UIP 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. Learning: UIP (x9,¬x5) (x9,¬x8) x7 ¬x5 x3 ¬x9 (x9,x12) (x5,x7) ¬x8 x12 Conflict (x5,¬x7,x3) (¬x4,¬x1) x19 x4 ¬x1 1 UIP (x1,¬x12,x19) (x1,¬x6) ¬x6 2 UIP ¬x3 (x6,¬x19,x8,¬x7,¬x3) Non –Chronological Backtracking • Backtrack multiple levels instead of one. • Use conflict clause to determine the level – Backtrack to the minimum level where the clause is still asserting. – Emphasis on recent learning. x8 ¬x10 x3 x7 x14 ¬x2 x5 ¬x4 x21 ¬x12 ¬x15 x19 x18 x32 ¬x6 x16 ¬x9 ¬x14 x1 Conflict Clause (x10,¬x7,x2,x9) x8 ¬x10 x3 ¬x2 x5 x7 x1 x9 Learning: Conflict Clauses • Prevent the reason to the conflict. – Consists of the negation to the reason literals. – Prunes the search tree. • Different cuts yield different conflict clauses. • We choose cuts such that: – Conflict clause includes one variable from the top level. It is a unit clause after backtracking one level. • The new problem is equivalent to the original.
© Copyright 2025 Paperzz