Constraint propagation

Download Report

Transcript Constraint propagation

SAT-solving
An old AI technique becomes very
popular in modern A.I.
Overview:
Basics on SAT
Unit propagation SAT-solving
Local Search SAT-solving
What is SAT-solving?
 Given KR: a set of propositional formula’s
 Find a model for KR.
More specifically:
 Let X1, X2, …, Xn be all the variables in KR,
 Find an assignment I; Xi -> {T,F} , for i=1,n ,
such that all formula’s in KR become true.
Useful ?
3
Example: 3-queens
X1,1 X1,2 X1,3
Representation:
X2,1 X2,2 X2,3
X3,1 X3,2 X3,3
Xi,j represents: there is a queen on i,j
At least one queen on each row:
Xi,1  Xi,2  Xi,3
(i=1,3)
At most one queen on each row:
Xi,1  ~Xi,2  ~Xi,3 , Xi,2  ~Xi,1  ~Xi,3 , Xi,3  ~Xi,1  ~Xi,2
Plus: similar formulas for columns and diagonals.
33 formula’s !
Generalisation to q-queens ? Very many formula’s !
(i=1,3)
Example: personel rostering
Representation:
- For every employee, i,
- For every shift in the day, j,
- For every day in the month, k :
Xi,j,k represents: i works on shift j of day k
At least one person works on every shift of every day:
X
i=1,35
i,j,k
(j=1,5, k=1,30)
An interpretation assigns to each Xi,j,k: true or false
Is a personel assignment !
Often this is more elegantly done with assignments to
{0,1} and sums instead of 
Generalise to higher numbers than just 1
SAT-solving and NP-completeness
 SAT-solving: one of the first identified as NP-complete
Means: all other NP-problems are technically
equivalent with this problem
 If you find a P-algorithm for SAT: you get a Palgorithm for all the others.
 Also means: most problems can be encoded as
SAT-problems and solved using SAT-techniques.
6
But why practically useful?
 Although NP(-complete)
Very efficient heuristic approaches exist that
work well on certain classes of problems.
Has led to:
- Many areas in CS and AI convert problems
to SAT
- Then use SAT-solvers.
7
Example: Automated Reasoning
 Compute a finite grounding of the predicate logic theory.
 Marcus example: 2 constants: Marcus and Ceasar.
1. man(Marcus)
2. Pompeian(Marcus)
is ground
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. ….
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
 Add the propositional version of the negation of the
theorem
~loyal_to(Marcus,Caesar) converts to loyal_to_Marcus_Caesar
 The theorem follows if and only if this propositional
KB in unsatisfiable !
SAT-solving
9
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
Naive SAT-solving
Depth-first left-to-right
enumeration of all interpretations
SAT - Standard backtracking
X=T
T~Y~W,
FYZ,
FW
Y=T
X~Y~W,
~XYZ,
~XW
X=F
F~Y~W,
TYZ,
TW
Y=T
Y=F
FZ,
W
TZ,
W
Z=F
Z=T
T, W
W=T
F, W Fail
W=F
T
Success
F
Fail
F~W,
Z=F
Z=T
W=F
T
W=T
F, W
T, W
W=T
Y=F
F
Success Fail
F
T~W
W=F
T
Fail Fail Success
Success
Naïve SAT-solving algorithm
Form is a CNF-formula with variables X1, X2, ...Xn
S:= { Dj | Dj is a disjunction in Form}
NaiveSAT( i)
For Truth = T, F do
Xi := Truth;
Remove all Dj containing T from S;
Remove all F and F from all Dj;
If no Dj in S is equal to F then
If S= {} then
return( X1, X2, … , Xn);
Else i := i + 1; NaiveSAT( i ); i := i - 1;
End-For
Call: NaiveSAT(1)
Davis-Putman (1960):
unit propagation
The basis for VERY efficient SAT-solvers
An early form of Dynamic Search
Rearrangement
1. Dealing with pure symbols
 A variable Xi is pure if it only appears with one sign in all
disjunctions.
Example:
S = { X  ~Y , ~Y  ~Z, Z  X }
X is pure: only occurs positive
Y is pure: only occurs negative
Z is not pure.
 Assign a pure variable the value that makes it true
everywhere (don’t consider the other assignment).
15
SAT + treating pure symbols
X~Y~W,
~XYZ,
~XW
Z is pure
Z=T
X~Y~W,
~XY T,
~XW
Y is pure
Y=F
X T ~W,
~XW
X=F
T  W
Success
X is pure
Effect of dealing with pure
symbols:
We get a _much_ smaller search space !
But we are no longer considering all assignments.
Yet: we do not loose completeness:
If another solution exist, then the current
assignment is ok too.
+ If unsatisfiable: this will fail too.
The order of choosing variables has become
dynamic.
But not first-fail based.
17
1. Unit propagation
 A disjunction is unit if it only contains one variable Xi.
Example:
S = { X  ~Y , ~Y, X }
~Y and X are units
 Assign a unit the value that makes it true (don’t consider
the other assignment).
18
SAT – with unit propagation
T~Y~W,
FYZ,
FW
X=T
X~Y~W,
~XYZ,
~XW
X=F
F~Y~W,
TYZ,
TW
unit !
W=T
YZ,
T
unit !
Y=T
Y=F
TZ,
FZ
Success
Z=T
T
Success
Y=T
Y=F
F~W
T~W
Success
W=F
unit !
T
Success
Effect of unit propagation
Smaller search space again.
But example is not well suited for unit propagation.
Obviously: combine both optimizations!
Many more optimzations in real SAT-solvers!
- Components analysis.
- More Dynamic Search Rearrangement
- Eg.: take most frequent variable first
- Intelligent backtracking, Indexing, …
20
Marcus as SAT-solving:
 Part of the grounding of Marcus-example
 plus the negation of the theorem:
man_Marcus, ruler_Caesar, try_assassinate_Marcus_Ceasar,
loyal_to_Marcus_Caesar,
~man_Marcus  ~ruler_Ceasar  ~try_assassinate_Marcus_Ceasar
 ~local_to_Marcus_Ceasar, ...
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.
SAT-solving
by Local Search
WalkSAT algorithm
Local Search representation:
Xi , i=1,n propositional variables
Dj, j=1,m the disjunctions in the CNF
States are n-tuples:
(T,F,F,T, …,F)
= an interpretation for the Xi ‘s
Objective function: the number of Dj ‘s that evaluate to F
Find the global minimum
Neighbors: flip one truth value of an Xi in failing Dj
To avoid local minima: probabilistically do Not take
the best flip
The WalkSAT algorithm:
Max_flip:= some number;
P:= some probability;
S:= { Dj | Dj disjunction};
State:= some interpretation for X1, X2, ...Xn;
For i= 1 to Max_flip do
IF all Dj’s are true in State Then return State;
Else
Disj:= random Dj that is false under State;
With probability P flip random Xi in Dj;
Else
flip the Xi of Dj that minimizes false Dj’s;
End-For
Report Failure
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
What about Disjunctive
Normal From?
 DNF: a dual representation for propositional
formulas:
(A1  ...  An)  (B1  …  Bm)  …  (C1  …  Ck)
 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 !!!
So why do we still prefer CNF ??
Think about it.
26