Title: KR with SAT
1- KR with SAT
- Representation, Algorithms, Translations
- My Thanks to Toby Walsh
2Propositional 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
3Inference 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.)
4Sound 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
5Conjunctive 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
6Conjunctive 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)
7SAT
- 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
8Representing 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?
9Representing 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
10Other applications of SAT
S Cin ? (P ? Q),
11Other 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.
14Routing Latin square problem
- Each channel cannot be repeated on input ports
- Each channel cannot be repeated on output ports
15Latin square
- Also called quasigroup
- Each colour occurs once in each row and column
Quasigroup or Latin Square (Order 4)
16Latin squares
- Can we complete a partially colored Latin square?
- NP-complete problem
- Applications in telecommunications
17SAT 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
18SAT vs. CSP
- SAT CSP
- Binary domains Non-binary domains
- Non-binary constraints Binary constraints
19Encoding 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
20Algorithms 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
21Complete SAT algorithms
- Truth tables
- Exponential time to construct
- Exponential space
22Complete 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
23Complete SAT algorithms
- DLL algorithm
- Consider
- (X ? Y) ? (?X ? Z) ? (?Y ? Z) ?
- Basic idea
- Try Xtrue
- Remove clauses which must be satisfied
24Complete SAT algorithms
- DLL algorithm
- Consider
- (?X ? Z) ? (?Y ? Z) ?
- Basic idea
- Try Xtrue
- Remove clauses which must be satisfied
- Simplify clauses containing ?X
25Complete 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
26Complete 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)
27Incomplete 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
28k-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!
29Encoding 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
30Dual 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
31Hidden 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
32Literal 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
33Non-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)
34Experiments 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
35Experiments 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
36Experiments 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?
37Experiments 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
38Conclusions
- 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