KR with SAT - PowerPoint PPT Presentation

1 / 38
About This Presentation
Title:

KR with SAT

Description:

... of disjunctions. Algorithm ... Distribute and to write the result as a conjunction of disjunctions ... Each disjunction of literals is called a clause ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 39
Provided by: vsi42
Category:
Tags: sat | disjunction

less

Transcript and Presenter's Notes

Title: KR with SAT


1
  • KR with SAT
  • Representation, Algorithms, Translations
  • My Thanks to Toby Walsh

2
Propositional Logic
  • Propositional logic is concerned with the truth
    or falsehood of statements (propositions) like
  • the valve is closed
  • five plus four equals nine
  • Connectives and ?
  • or ?
  • not ?
  • implies ?
  • equivalent ?

(X ? (Y ? Z)) ? ((X ? Y) ? (X ? Z)) X implies Y
and Z is the same as X implies Y and X implies Z
3
Inference rules
  • Logical inference is used to create new
    sentences that logically follow from a given set
    of predicate calculus sentences (KB).
  • An inference rule is sound if every sentence X
    produced by an inference rule operating on a KB
    logically follows from the KB. (That is, the
    inference rule does not create any
    contradictions)
  • An inference rule is complete if it is able to
    produce every expression that logically follows
    from (is entailed by) the KB. (Note the analogy
    to complete search algorithms.)

4
Sound rules of inference
  • Here are some examples of sound rules of
    inference.
  • Each can be shown to be sound using a truth
    table A rule is sound if its conclusion is true
    whenever the premise is true.
  • RULE PREMISE CONCLUSION
  • Modus Ponens A, A gt B B
  • And Introduction A, B A B
  • And Elimination A B A
  • Double Negation A A
  • Unit Resolution A v B, B A
  • Resolution A v B, B v C A v C

5
Conjunctive Normal Form
  • Every sentence in propositional logic can be
    transformed into conjunctive normal form
  • i.e. a conjunction of disjunctions
  • Algorithm
  • Eliminate ? using the rule that (p ?q) is
    equivalent to (?p ? q)
  • Use de Morgans laws so that negation applies to
    literals only
  • Distribute ? and ? to write the result as a
    conjunction of disjunctions

6
Conjunctive Normal Form - Example
  • ?(p ?q) ? (r ?p)
  • Eliminate implication signs
  • ?(?p ? q) ? (?r ? p)
  • Apply de Morgans laws
  • (p ? ?q) ? (?r ? p)
  • Apply associative and distributive laws
  • (p ? ?r ? p) ? (?q ? ?r ? p)
  • (p ? ?r) ? (?q ? ?r ? p)

7
SAT
  • The problem of finding a model for a formula in
    propositional logic is known as the propositional
    satisfiability problem (PSAT)
  • When the formula is in CNF it is usually called
    SAT
  • 1st problem shown to be NP-complete Cook 71
  • Each disjunction of literals is called a clause
  • Many real world problems can be formulated as SAT
    problems
  • including CSPs
  • 2SAT is a special case that can be solved in
    polynomial time

8
Representing knowledge using SAT - Example
  • Embassy ball (a diplomatic problem)
  • King wants to invite PERU or exclude QATAR
  • Queen wants to invite QATAR or ROMANIA
  • Kings wants to snub ROMANIA or PERU
  • Who can we invite?

9
Representing knowledge using SAT - Example
  • Embassy ball (a diplomatic problem)
  • King wants to invite PERU or exclude QATAR
  • Queen wants to invite QATAR or ROMANIA
  • Kings wants to snub ROMANIA or PERU
  • (P ? ?Q) ? (Q ? R) ? (?R ? ?P)
  • is satisfied by Ptrue, Qtrue, Rfalse
  • and by Pfalse, Qfalse, Rtrue

10
Other applications of SAT
  • Hardware verification

S Cin ? (P ? Q),
11
Other applications of SAT
  • Scheduling jobs in a factory
  • Set of jobs, resource constraints, start and due
    dates,
  • Just need to sequence jobs
  • Xij true iff Job i occurs before Job j
  • Design theory
  • Experimental design, Latin squares with special
    properties
  • Open problems solved by encoding problems into
    SAT

12
Fiber-optic routing
Nodes connect point to point fiber optic links
13
Fibre-optic routing
Input Ports
Output Ports
1
1
2
2
3
3
4
4
Routing Node
How can we achieve conflict-free routing in each
node of the network?
Dynamic wavelength routing is a NP-hard problem.
14
Routing Latin square problem
  • Each channel cannot be repeated on input ports
  • Each channel cannot be repeated on output ports

15
Latin square
  • Also called quasigroup
  • Each colour occurs once in each row and column

Quasigroup or Latin Square (Order 4)
16
Latin squares
  • Can we complete a partially colored Latin square?
  • NP-complete problem
  • Applications in telecommunications

17
SAT model for Latin square
  • What are the variables?
  • Xijk is true if square (i,j) has the colour k
  • What are the constraints
  • Row constraints
  • (?Xijk ? ?Xi(j1)k), .
  • Column constraints
  • (?Xijk ? ?X(i1)jk),
  • Xij1 ? ? Xij4

18
SAT vs. CSP
  • SAT CSP
  • Binary domains Non-binary domains
  • Non-binary constraints Binary constraints

19
Encoding CSP as SAT
  • A propositional variable Xij for each value j in
    the domain of the CSP variable Xi
  • Xij is true if Xi takes value j
  • Clauses that ensure each CSP variable is given a
    value
  • for each i Xi1 ? ? Xim
  • Clauses that ensure no CSP variable takes more
    than one values
  • for each i,j,k, with j?k, ?Xij ? ?Xik
  • (Binary) clauses that rule out any (binary)
    nogoods
  • e.g. (if X15, X24) is not allowed we have a
    clause ?X15 ? ?X24

20
Algorithms for SAT
  • How do we test if a problem is SAT or not?
  • Complete methods
  • Return Yes if SATisfiable
  • Return No if UNSATisfiable
  • Incomplete methods
  • If return Yes, problem is SATisfiable
  • Otherwise timeout/run forever, problem can be SAT
    or UNSAT

21
Complete SAT algorithms
  • Truth tables
  • Exponential time to construct
  • Exponential space

22
Complete SAT algorithms
  • DLL algorithm
  • Due to Davis, Logemann and Loveland from 1962
  • Original algorithm by Davis Putnam in 1960
    could use exponential space
  • DLL traded time for space to give linear space
    algorithm

23
Complete SAT algorithms
  • DLL algorithm
  • Consider
  • (X ? Y) ? (?X ? Z) ? (?Y ? Z) ?
  • Basic idea
  • Try Xtrue
  • Remove clauses which must be satisfied

24
Complete SAT algorithms
  • DLL algorithm
  • Consider
  • (?X ? Z) ? (?Y ? Z) ?
  • Basic idea
  • Try Xtrue
  • Remove clauses which must be satisfied
  • Simplify clauses containing ?X

25
Complete SAT algorithms
  • DLL algorithm
  • Consider
  • ( Z) ? (?Y ? Z) ?
  • Basic idea
  • Try Xtrue
  • Remove clauses which must be satisfied
  • Simplify clauses containing ?X
  • Can now deduce that Z must be true
  • At any point, may have to backtrack and try
    Xfalse instead

26
Complete SAT algorithms
  • DLL algorithm
  • Branching heuristics
  • Which variable to assign next?
  • Which value (true/false) to try first?
  • Other refinements
  • Clause learning
  • Intelligence backtracking
  • Implementation tricks
  • Worst-case complexity
  • O(1.696n)

27
Incomplete SAT algorithms
  • Most fit a very simple schema
  • Randomly guess truth assignment
  • Repeat
  • Pick a variable
  • Flip its truth value
  • Heuristics to pick variable
  • Any var in UNSAT clause
  • Var that maximizes number of SAT clauses if
    flipped
  • GSAT
  • Var in UNSAT clause flipped longest time ago

28
k-SAT
  • Subclass of SAT problem
  • Exactly k variables in each clause
  • (P ? ?Q) ? (Q ? R) ? (?R ? ?P) is in 2-SAT
  • 3-SAT is NP-complete
  • SAT can be reduced to 3-SAT
  • 2-SAT is in P
  • Exists linear time algorithm!

29
Encoding CSP as SAT
  • There are various encodings of SAT into CSP
  • Can you think of any?
  • SAT into CSP
  • Dual Encoding
  • Hidden Variable Encoding
  • Literal Encoding
  • Non-binary Encoding

30
Dual Encoding
  • A dual variable Vi associated with each clause Ci
  • The domain of Vi consists of those tuples of
    truth values which satisfy the clause
  • For example the clause x1 ? x2 is associated
    with a dual variable having domain (T,F), (F,T),
    (T,T)
  • Binary constraints are posted between dual
    variables which are associated with clauses that
    share propositional variables
  • For example there is a binary constraint between
    variables V1 and V2 , where V1 corresponds to
    clause x1 ? x2 and V2 corresponds to clause
    x1??x2

31
Hidden Variable Encoding
  • A hidden variable Vi associated with each clause
    Ci
  • The domain of Vi consists of those tuples of
    truth values which satisfy the clause
  • For example the clause x1 ? x2 is associated
    with a hidden variable having domain (T,F),
    (F,T), (T,T)
  • We also have the original propositional
    variables with domains T,F
  • There is a binary constraint between a hidden
    variable and a propositional variable if the
    clause represented by the hidden variable
    mentions the propositional variable
  • For example there is a binary constraint between
    hidden variable V1 ,which corresponds to clause
    x1 ? x2 ,and variable x1

32
Literal Encoding
  • A variable Vi associated with each clause Ci
  • The domain of Vi consists of those literals
    which satisfy the clause
  • For example the clause x1 ? x2 is associated
    with a variable V1 having domain x1 , x2 and
    the clause x3 ? ?x2 is associated with a variable
    V2 having domain x3 , ?x2
  • There is a binary constraint between two
    variables Vi, Vj if the associated clause Ci
    contains a literal whose complement is contained
    in the associated clause Cj
  • For example there is a constraint between V1 and
    V2
  • the constraint allows tuples (x1,x3), (x1,?x2),
    (x2,x3)
  • domain size of variables is O(k), where k the
    length of the clauses

33
Non-binary Encoding
  • A variable Vi associated with each literal
  • The domain of Vi is T,F
  • A non-binary constraint is posted on variables
    appearing in the same clause
  • This constraint disalllows partial assignments
    that do not satisfy the clause
  • For example, associated with the clause x1 ? x2
    ? x3 is a non-binary constraint on variables x1 ,
    x2 , x3 which allows all tuples except (F,F,F)

34
Experiments with 3-SAT
  • Where are the hard 3-SAT problems?
  • Sample randomly generated 3-SAT
  • Fix number of clauses, l
  • Number of variables, n
  • By definition, each clause has 3 variables
  • Generate all possible clauses with uniform
    probability

35
Experiments with random 3-SAT
  • Which are the hard instances?
  • around l/n 4.3
  • What happens with larger problems?
  • Why are some dots red and others blue?
  • This is a so-called phase transition

36
Experiments with random 3-SAT
  • Varying problem size, n
  • Complexity peak appears to be largely invariant
    of algorithm
  • complete algorithms like Davis-Putnam
  • Incomplete methods like local search
  • Whats so special about 4.3?

37
Experiments with random 3-SAT
  • Complexity peak coincides with satisfiability
    transition
  • l/n lt 4.3 problems under-constrained and SAT
  • l/n gt 4.3 problems over-constrained and UNSAT
  • l/n4.3, problems on knife-edge between SAT and
    UNSAT

38
Conclusions
  • SAT is a useful problem class
  • Theoretical importance
  • prototypical NP-complete problem
  • NP-completeness is usually proved by reduction
    to SAT
  • Practical value
  • can be used to represent and reason with
    knowledge in many domains
  • SAT problems can be translated into CSPs and vice
    versa
  • as to which representation is better It depends
    on the specific problem
Write a Comment
User Comments (0)
About PowerShow.com