ICS-271:Notes 5: 1
Set 5: Constraint Satisfaction Problems Chapter 6 R&N
ICS 271 Fall 2016 Kalev Kask
Chapter 6 R&N ICS 271 Fall 2016 Kalev Kask ICS-271:Notes 5: 1 - - PowerPoint PPT Presentation
Set 5: Constraint Satisfaction Problems Chapter 6 R&N ICS 271 Fall 2016 Kalev Kask ICS-271:Notes 5: 1 Outline The constraint network model Variables, domains, constraints, constraint graph, solutions Examples:
ICS-271:Notes 5: 1
ICS 271 Fall 2016 Kalev Kask
ICS-271:Notes 5: 2
– Variables, domains, constraints, constraint graph, solutions
– graph-coloring, 8-queen, cryptarithmetic, crossword puzzles, vision problems,scheduling, design
– arc-consistency, AC-1,AC-3
– Forward-checking, dynamic variable orderings
ICS-271:Notes 5: 3
ICS-271:Notes 5: 4
A B
red green red yellow green red green yellow yellow green yellow red
Variables - countries (A,B,C,etc.) Values - colors (e.g., red, green, yellow) Constraints: etc. , E D D, A B, A C A B D E F G
ICS-271:Notes 5: 5
ICS-271:Notes 5: 6
ICS-271:Notes 5: 7
ICS-271:Notes 5: 8
ICS-271:Notes 5: 9
– e.g., SA ≠ green
– e.g., SA ≠ WA
– Clauses in boolean (propositional) logic – e.g., cryptoarithmetic column constraints
ICS-271:Notes 5: 10
– Satisfaction problem
– Optimization problem
ICS-271:Notes 5: 11
Each row, column and major block must be all different “Well posed” if it has unique solution: 27 constraints
ICS-271:Notes 5: 12
Each row, column and major block must be all different “Well posed” if it has unique solution: 27 constraints
2 3 4 6
2
{1,2,3,4,5,6,7,8,9}
ICS-271:Notes 5: 13
ICS-271:Notes 5: 15
ICS-271:Notes 5: 16
–
–
– Rij which represent the list of allowed pairs of values, Rij is a subset
– A node for each variable and an edge for each constraint
– An assignment of a value from its domain to each variable such that no constraint is violated.
n
n
1
j ixD
D
j j i i ij j i n
1
X
5
X
4
X
3
X
2
X
ICS-271:Notes 5: 17
Place 4 Queens on a chess board of 4x4 such that no two queens reside in the same row, column or diagonal. Standard CSP formulation of the problem:
1
X
4
X
3
X
2
X
1 2 3 4
}. 4 , 3 , 2 , 1 {
i
D
4 2
( )
)} 2 , 4 )( 1 , 4 )( 1 , 3 )( 4 , 2 )( 4 , 1 )( 3 , 1 {(
12
R )} 3 , 4 )( 1 , 4 )( 4 , 3 )( 2 , 3 )( 3 , 2 )( 1 , 2 )( 4 , 1 )( 2 , 1 {(
13
R )} 3 , 4 )( 2 , 4 )( 4 , 3 )( 2 , 3 )( 1 , 3 )( 4 , 2 )( 3 , 2 )( 1 , 2 )( 3 , 1 )( 2 , 1 {(
14
R )} 2 , 4 )( 1 , 4 )( 1 , 3 )( 4 , 2 )( 4 , 1 )( 3 , 1 {(
23
R )} 3 , 4 )( 1 , 4 )( 4 , 3 )( 2 , 3 )( 3 , 2 )( 1 , 2 )( 4 , 1 )( 2 , 1 {(
24
R )} 2 , 4 )( 1 , 4 )( 1 , 3 )( 4 , 2 )( 4 , 1 )( 3 , 1 {(
34
R
1
X
2
X
4
X
3
X
ICS-271:Notes 5: 19
ICS-271:Notes 5: 20
ICS-271:Notes 5: 21
But only dn unique assignments
ICS-271:Notes 5: 22
ICS-271:Notes 5: 23
– a state:
– Operators:
– Goal state:
n
ICS-271:Notes 5: 24
ICS-271:Notes 5: 25
ICS-271:Notes 5: 26
ICS-271:Notes 5: 27
ICS-271:Notes 5: 28
Backtracking
– Complexity of consistent: O(e log t), t bounds #tuples, e bounds #constraints – Complexity of selectvalue: O(e k log t), k bounds domain size
ICS-271:Notes 5: 30
z divides x, y and t
ICS-271:Notes 5: 31
ICS-271:Notes 5: 32
Backtracking Search for a Solution
ICS-271:Notes 5: 33
Backtracking Search for a Solution
ICS-271:Notes 5: 34
Backtracking Search for All Solutions
ICS-271:Notes 5: 35
– variables, domains, constraints – solution = assignment to all variables such that all constraints are satisfied – constraint graph
– conditioning vs local consistency.
– Backtracking search :
– Effect on search space size on var/val order :
ICS-271:Notes 5: 36
ICS-271:Notes 5: 37
– Transform the network into smaller and smaller (but equivalent) networks by tightening the domains/constraints.
ICS-271:Notes 5: 38
ICS-271:Notes 5: 39
ICS-271:Notes 5: 40
domain of X domain of Y Arc is arc-consistent if for any value of there exist a matching value of Algorithm Revise makes an arc consistent Begin
from the Di. End. Revise is , k is the number of values in each domain.
) (
j i,X
X
i
X
i
X ) (
j i,X
X
) O(k 2
ICS-271:Notes 5: 41
– 1. Q <--- put all arcs in the queue in both directions – 2. While Q is not empty do, – 3. Select and delete an arc from the queue Q
queue all arcs that go to Xi ((Xl,Xi for all l except i). – 6. end-while
– Processing an arc requires O(k^2) steps – There is edges – The number of times each arc can be processed is 2·k – Total complexity is ) (
j i,X
X ) (
j i,X
X
) O(ek 3 e
ICS-271:Notes 5: 42
Each row, column and major block must be all different “Well posed” if it has unique solution: 27 constraints
2 3 4 6
2
{1,2,3,4,5,6,7,8,9}
ICS-271:Notes 5: 43
Each row, column and major block must be all different “Well posed” if it has unique solution Path-consistency or 3-consistency 4-consistency and i-consistency in geeral
ICS-271:Notes 5: 44
removed
– R’_zx – R’_zy – R’_zl – R’_xy – R’_xl – R’_yl
Tighter networks yield smaller search spaces
ICS-271:Notes 5: 45
– Arc-consistency, path-consistency, k-consistency – Variable ordering (fixed)
– Look-ahead schemes:
– Look-back schemes:
Improving Backtracking O(exp(n))
ICS-271:Notes 5: 46
ICS-271:Notes 5: 47
– Choose a variable that will detect failures early – Choose a value least likely to yield a dead-end – Approach: apply propagation at each node in the search tree
– Check each unassigned variable separately
– Apply full arc-consistency
ICS-271:Notes 5: 48
ICS-271:Notes 5: 49
ICS-271:Notes 5: 50
ICS-271:Notes 5: 51
ICS-271:Notes 5: 52
ICS-271:Notes 5: 53
ICS-271:Notes 5: 54
ICS-271:Notes 5: 55
ICS-271:Notes 5: 60
ICS-271:Notes 5: 62
– variables, domains, constraints – solution = assignment to all variables such that all constraints are satisfied – constraint graph
– conditioning vs local consistency.
– In the space of partial assignments; add var=val at each search space node. – Effect on search space size on var/val order :
– Prune domains/constraints – Arc/path/k-consistency
– Forward checking (FC) – Maintaining Arc Consistency (MAC)
ICS-271:Notes 5: 63
Forward-checking on Graph-coloring
) (
2
ek O
3 2
FW overhead: MAC overhead:
ICS-271:Notes 5: 64
ICS-271:Notes 5: 65
Is it possible that Chris goes to the party but Becky does not?
ICS-271:Notes 5: 66
– C must be true – A must be true – B must be false and true – formula is not satisfiable
ICS-271:Notes 5: 67
(Davis-Putnam, Logeman and Laveland, 1962)
ICS-271:Notes 5: 68
Only enclosed area will be explored with unit-propagation Backtracking look-ahead with Unit propagation= Generalized arc-consistency (Davis-Putnam, Logeman and Laveland, 1962)
example: (┐A V B) ˄ (┐C V A) ˄ (A V B V D) ˄ (C)
ICS-271:Notes 5: 70
Backjumping / Learning
– In deadends, go back to the most recent culprit.
– constraint-recording, no-good recording.
– good-recording
ICS-271:Notes 5: 72
– Conflict set : a partial assignment that cannot be extended to the next variable
– No-good : a partial assignment that cannot be extended to a solution – No-good = internal deadend
– But not other way around (x1=r is a no-good)
?
ICS-271:Notes 5: 74
ICS-271:Notes 5: 75
ICS-271:Notes 5: 76
ICS-271:Notes 5: 77
ICS-271:Notes 5: 78
ICS-271:Notes 5: 79
cycle-cutset) the rest of the problem can be solved in linear time by a tree algorithm.
cycle-cutset size):
2
C
ICS-271:Notes 5: 80
T WA NT SA NT SA Q SA Q
NSW
SA
NSW
V
Complexity is O(n exp(w)) where w bounds the number of variables in a cluster. Known as the treewidth.
ICS-271:Notes 5: 81
ICS-271:Notes 5: 83
ICS-271:Notes 5: 84
GSAT – local search for SAT
(Selman, Levesque and Mitchell, 1992)
1. For i=1 to MaxTries 2. Select a random assignment A 3. For j=1 to MaxFlips 4. if A satisfies all constraints, return A 5. else flip a variable to maximize the score 6. (number of satisfied constraints; if no variable 7. assignment increases the score, flip at random) 8. end 9. end
ICS-271:Notes 5: 85
(Selman, Kautz and Cohen, 1994)
With probability p random walk – flip a variable in some unsatisfied constraint With probability 1-p perform a hill-climbing step
Randomized hill-climbing often solves large and hard satisfiable problems
ICS-271:Notes 5: 86
– A method for overcoming local minimas – Allows bad moves with some probability:
next move is picked randomly. – Theoretically, with a slow enough cooling schedule, this algorithm will find the optimal solution. But so will searching randomly.
constraints
ICS-271:Notes 5: 87
ICS-271:Notes 5: 88
ICS-271:Notes 5: 89