Download presentation
Presentation is loading. Please wait.
Published byFrederica Bradford Modified over 9 years ago
1
SAT-solving An old AI technique becomes very popular in modern A.I.
2
Overview: Basics on SAT Unit propagation SAT-solving Local Search SAT-solving Local Search SAT-solving
3
3 What is SAT-solving? Given KR: a set of propositional formula’s Find a model for KR. More specifically: Let X 1, X 2, …, X n be all the variables in KR, Find an assignment I; X i -> {T,F}, for i=1,n, such that all formula’s in KR become true. such that all formula’s in KR become true. Useful ?
4
Example: 3-queens Representation: X 1,1 X 1,2 X 1,3 X 2,1 X 2,3 X 2,2 X 3,1 X 3,2 X 3,3 represents: there is a queen on i,j represents: there is a queen on i,j X i,j X i,1 X i,2 X i,3 (i=1,3) At least one queen on each row: X i,1 ~X i,2 ~X i,3, X i,2 ~X i,1 ~X i,3, X i,3 ~X i,1 ~X i,2 (i=1,3) At most one queen on each row: Plus: similar formulas for columns and diagonals. 33 formula’s ! Generalisation to q-queens ? Very many formula’s !
5
Example: personel rostering Representation: - For every employee, i, - For every employee, i, - For every shift in the day, j, - For every shift in the day, j, - For every day in the month, k : - For every day in the month, k : represents: i works on shift j of day k represents: i works on shift j of day k X i,j,k Often this is more elegantly done with assignments to {0,1} and sums instead of Generalise to higher numbers than just 1 At least one person works on every shift of every day: X i,j,k (j=1,5, k=1,30) i=1,35 An interpretation assigns to each Xi,j,k: true or false Is a personel assignment !
6
6 SAT-solving and NP-completeness SAT-solving: one of the first identified as NP-complete If you find a P-algorithm for SAT: you get a P- algorithm for all the others. Also means: most problems can be encoded as SAT-problems and solved using SAT-techniques. Means: all other NP-problems are technically equivalent with this problem
7
7 But why practically useful? Although NP(-complete) Has led to: -Many areas in CS and AI convert problems to SAT -Then use SAT-solvers. Very efficient heuristic approaches exist that work well on certain classes of problems.
8
Example: Automated Reasoning Compute a finite grounding of the predicate logic theory. Marcus example: 2 constants: Marcus and Ceasar. 1. man(Marcus) is ground 2. Pompeian(Marcus) is ground 3. x Pompeian(x) Roman(x) Pompeian(Marcus) Roman(Marcus) Pompeian(Ceasar) Roman(Ceasar) 4. ruler(Caesar) is ground 5. x Roman(x) loyal_to(x,Caesar) hates(x,Caesar) Roman(Marcus) loyal_to(Marcus,Caesar) hates(Marcus,Caesar) Roman(Ceasar) loyal_to(Ceasar,Caesar) hates(Ceasar,Caesar) Ect. ….
9
9 Example: continued Ground predicate logic is equivalent to propositional ! Example: Pompeian(Marcus) converts to Pompeian_Marcus loyal_to(Marcus,Caesar) converts to loyal_to_Marcus_Caesar The theorem follows if and only if this propositional KB in unsatisfiable ! KB in unsatisfiable ! Add the propositional version of the negation of the theorem ~loyal_to(Marcus,Caesar) converts to loyal_to_Marcus_Caesar SAT-solving
10
Conjunctive Normal Form Every formula is equivalent to a formula of the form: (A1 ... An) (B1 … Bm) … (C1 … Ck) where all Ai, Bi, …, Ci are either atomic or ~atomic. Idea: p q p q push all ~ as deep as possible apply distributivity of and p q q p q ~p SAT-solving will work on a collection of disjunctions: X1 … Xn ~Y1 … ~Ym
11
Naive SAT-solving Depth-first left-to-right enumeration of all interpretations
12
SAT - Standard backtracking ~Y X ~Y ~W,, ~X Y Z, ~XW ~X W ~Y T ~Y ~W,, F Y Z, FW F W X=TX=TX=TX=T Y=TY=TY=TY=T,TZ,WW,TZ,WWW Z=TZ=TZ=TZ=T, W T, W W=TW=TW=TW=T TF W=FW=FW=FW=F, W F, W Z=FZ=FZ=FZ=F, W T, W Z=TZ=TZ=TZ=T T W=TW=TW=TW=T F W=FW=FW=FW=F, W F, W Z=FZ=FZ=FZ=F ~Y F ~Y ~W,, T Y Z, TW T W X=FX=FX=FX=F Y=TY=TY=TY=T F F ~W, W=TW=TW=TW=T F W=FW=FW=FW=F T,FZ,WW,FZ,WWW Y=FY=FY=FY=F Y=FY=FY=FY=F T T ~W Success Success Success Success Fail Fail Fail FailFail
13
13 Naïve SAT-solving algorithm NaiveSAT( i) For Truth = T, F do X i := Truth; X i := Truth; Remove all Dj containing T from S; Remove all Dj containing T from S; Remove all F and F from all Dj; Remove all F and F from all Dj; If no Dj in S is equal to F then If no Dj in S is equal to F then Else i := i + 1; NaiveSAT( i ); i := i - 1; If S= {} then return( X 1, X 2, …, X n ); return( X 1, X 2, …, X n ); Form is a CNF-formula with variables X 1, X 2,...X n S:= { Dj | Dj is a disjunction in Form} Call: NaiveSAT(1) End-For
14
Davis-Putman (1960): unit propagation The basis for VERY efficient SAT-solvers An early form of Dynamic Search Rearrangement
15
15 1. Dealing with pure symbols Example: S = { } S = { X ~Y, ~Y ~Z, Z X } X is pure: only occurs positive Y is pure: only occurs negative Z is not pure. A variable Xi is pure if it only appears with one sign in all disjunctions. Assign a pure variable the value that makes it true everywhere (don’t consider the other assignment).
16
SAT + treating pure symbols ~Y X ~Y ~W,, ~X Y Z, ~XW ~X W Success Z=TZ=TZ=TZ=T ~Y X ~Y ~W,, ~X Y T, ~XW ~X W Y=FY=FY=FY=F T X T ~W, ~XW ~X W X=FX=FX=FX=F T T W Z is pure Y is pure X is pure
17
17 The order of choosing variables has become dynamic. Effect of dealing with pure symbols: Yet: we do not loose completeness: If another solution exist, then the current assignment is ok too. + If unsatisfiable: this will fail too. But not first-fail based. We get a _much_ smaller search space ! But we are no longer considering all assignments.
18
18 1. Unit propagation Example: S = { } S = { X ~Y, ~Y, X } ~Y and X are units ~Y and X are units A disjunction is unit if it only contains one variable Xi. Assign a unit the value that makes it true (don’t consider the other assignment).
19
SAT – with unit propagation ~Y X ~Y ~W,, ~X Y Z, ~XW ~X W ~Y T ~Y ~W,, F Y Z, FW F W X=TX=TX=TX=T ~Y F ~Y ~W,, T Y Z, TW T W X=FX=FX=FX=F Y=TY=TY=TY=T F F ~W Y=FY=FY=FY=F T T ~W Success Success Success Success,YZ,TT,YZ,TTT W=TW=TW=TW=T Y=TY=TY=TY=T,TZ,,TZ, FZFZ Y=FY=FY=FY=F Z=TZ=TZ=TZ=T T W=FW=FW=FW=F T unit !
20
20 Many more optimzations in real SAT-solvers! Effect of unit propagation Obviously: combine both optimizations! - Components analysis. - More Dynamic Search Rearrangement -Eg.: take most frequent variable first - Intelligent backtracking, Indexing, … Smaller search space again. But example is not well suited for unit propagation.
21
Marcus as SAT-solving: man_Marcus, ruler_Caesar, try_assassinate_Marcus_Ceasar, loyal_to_Marcus_Caesar, ~man_Marcus ~ruler_Ceasar ~try_assassinate_Marcus_Ceasar ~local_to_Marcus_Ceasar,... ~local_to_Marcus_Ceasar,... Part of the grounding of Marcus-example plus the negation of the theorem: 4 unit propagations: try_assassinate_Marcus_Ceasar = T man_Marcus = T ruler_Caesar = T loyal_to_Marcus_Caesar = T T, T, T, T, F F F F,... Fails ! Theorem proved.
22
SAT-solving by Local Search WalkSAT algorithm
23
Local Search representation: X i, i=1,n propositional variables D j, j=1,m the disjunctions in the CNF States are n-tuples: (T,F,F,T, …,F) Objective function: the number of D j ‘s that evaluate to F = an interpretation for the X i ‘s Find the global minimum Neighbors: flip one truth value of an X i in failing D j To avoid local minima: probabilistically do Not take the best flip
24
24 The WalkSAT algorithm: For i= 1 to Max_flip do IF all Dj’s are true in State Then return State; IF all Dj’s are true in State Then return State; Else Else Disj:= random Dj that is false under State; Disj:= random Dj that is false under State; With probability P flip random Xi in Dj; With probability P flip random Xi in Dj; Else Else flip the Xi of Dj that minimizes false Dj’s; flip the Xi of Dj that minimizes false Dj’s; Max_flip:= some number; P:= some probability; S:= { Dj | Dj disjunction}; State:= some interpretation for X 1, X 2,...X n ; End-For Report Failure
25
Evaluation: Unclear whether optimized SAT-solving or Local Search is better. but today more people are using local search Efficiency of methods depends on underconstraint versus overconstraintness of problems see Norvig & Russel for a discussion
26
26 What about Disjunctive Normal From? DNF: a dual representation for propositional formulas: Satisfiability of DNF can be checked in linear time! Find 1 conjunction that does not contain a variable and the negation of that variable. But: conversion to DNF requires exponential time and exponential space ! CNF and DNF are dual: so conversion to CNF is also exponential !!! (A1 ... An) (B1 … Bm) … (C1 … Ck) So why do we still prefer CNF ?? Think about it.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.