Professional Documents
Culture Documents
V6 R V6 R
V4 G V4 G
•How about using a search algorithm? START =(V1=? V2=? V3=? V4=? V5=? V6=?)
•Define: a search state has variables 1 … k assigned. Values k+1 … n, succs(START) =
as yet unassigned. (V1=R V2=? V3=? V4=? V5=? V6=?)
•Start state: All unassigned. (V1=G V2=? V3=? V4=? V5=? V6=?)
•Goal state: All assigned, and all constraints satisfied. (V1=B V2=? V3=? V4=? V5=? V6=?)
•Successors of a stated with V1 … Vk assigned and rest unassigned are What search algorithms could we use?
all states (with V1 … Vk the same) with Vk+1 assigned a value from D. It turns out BFS is not a popular choice. Why not?
•Cost on transitions: 0 is fine. We don’t care. We just want any solution.
Slide 5 Slide 6
1
Blindingly obvious improvement –
DFS for CSPs
V5 Consistency Checking:
V3 V1
V2 “Backtracking Search”
V5
V6 R V3 V1
V2
V4 G
2
Graph-coloring-specific Constraint A New CSP (where fancier
Propagation propagation is possible)
In the case of Graph Coloring, CP looks simple: • The semi magic square
• Each variable can have value 1, 2 or 3
after we’ve made a search step (instantiated a
node with a color), propagate the color at that
node. V1 V2 V3 This row must
PropagateColorAtNode(node,color) sum to 6
This row must
1. remove color from all of “available lists” of our V4 V5 V6
uninstantiated neighbors. sum to 6
nstra int
2. If any of these neighbors gets ms, coset,
leempty
the it’s time to V7 V8 V9 This row must
backtrack. ne ra l C SP prob re than only sum to 6
e ch mo
But for G n do mu if ngpreviously
uniq ue
3. Foreachag naintio n caneighbors:
these e ets a had two or
prop
more available w h
colors e n
buta nodhas
now only one color c, run This column This column This column This diagonal
p a ga tin g
pro
PropagateColorAtNode(n,c) must sum to 6 must sum to 6 must sum to 6 must sum to 6
value…
Slide 13 Slide 14
3
(V1,V2,V3) must be one of
(1,2,3)
Propagate on Semi-magic Square Propagate on Semi-magic(1,3,2)
Square
(2,1,3)
(2,2,2)
• The semi magic square • The semi magic square (2,3,1)
(3,1,2)
• Each variable can have value 1, 2 or 3 • Each variable can have value 1, 2 or 3 (3,2,1)
This column This column This column This diagonal This column This column This column This diagonal
must sum to 6 must sum to 6 must sum to 6 must sum to 6 must sum to 6 must sum to 6 must sum to 6 must sum to 6
Slide 19 Slide 20
This column This column This column This diagonal This column This column This column This diagonal
must sum to 6 must sum to 6 must sum to 6 must sum to 6 must sum to 6 must sum to 6 must sum to 6 must sum to 6
Slide 21 Slide 22
After doing all row constraints and And after doing diagonal
column constraints… constraint…
This row must
1 23 23
sum to 6
This row must
23 23 123
sum to 6
This row must
1 23 23 23 123 23 This row must
sum to 6 sum to 6
This row must
23 123 123
sum to 6 This column This column This column This diagonal
This row must must sum to 6 must sum to 6 must sum to 6
23 123 123 must sum to 6
sum to 6
4
CSP Search with Constraint Propagation
And after doing another round of
constraints…
1 23 23 This row must CPSearch(A1, A2 ,… An)
sum to 6 Let i = lowest index such that Ai has more than one value
This row must foreach available value x in Ai
23 23 12
sum to 6 foreach k in 1, 2.. n
This row must Define A’k := Ak
23 12 23 A’i := { x }
sum to 6
Call Propagate(A’1, A’2 ,… A’n)
This column This column This column This diagonal If no “Backtrack” signal
must sum to 6 must sum to 6 must sum to 6 If A’1, A’2 ,… A’n are all unique we’re done!
lide
must sum to 6
Recursively Call CPSearch(A’1, A’2 ,… A’n) s
xt
YES! And this showed a case of a es on ne
constraint applying even when none of hang
ore c ? ls on
tai
a n y m n
So.. xt iteratio
the variables involved was down to a
the n
e De
unique value. Slide 25 Slide 26
CSP Search with Constraint Propagation Semi-magic Square 123 123 123
CPSearch Tree 123 123 123
123 123 123
CPSearch(A1, A2 ,… An)
Let i = lowest index such that Ai has more than one value
foreach available value x in Ai 1 23 23 2 123 123 3 12 12
foreach k in 1, 2.. n
Define A’k := Ak 23 23 12 123 123 123 12 12 23
A’i := { x } 23 12 23 123 123 123 12 23 12
Call Propagate(A’1, A’2 ,… A’n)
If no “Backtrack” signal
If A’1, A’2 ,… A’n are all unique we’re done!
1 2 3 1 3 2
Recursively Call CPSearch(A’1, A’2 ,… A’n)
2 3 1 3 2 1
What’s the top-level call? 3 1 2 2 1 3
Call with that Ai = complete set of possible values for Vi .
Slide 29 Slide 30
5
Semi-magic Square
CPSearch Tree
123 123 123 Some real CSPs
123 123 123
• Graph coloring is a real, and useful, CSP. Applied to
123 123 123 problems with many hundreds of thousands of nodes.
Not very AI-esque.
1 23 23 2 123 123 3 12 12 • VLSI or PCB board layout.
23 23 12 123 123 123 12 12 23 • Selecting a move in the game of “minesweeper”.
23 12 23 123 123 123 12 23 12 0 0 1
0 0 1
0 0 1
1 1 2
r
1 2 3 1 3 2 neve e
fa c t, we er thes
2 3 1 3 2 1 In id t
e n cons e stop a
3 1 2 2 1 3 ev se w s Which squares have a bomb? Squares with numbers don’t. Other squares
c a u
be es might. Numbers tell how many of the eight adjacent squares have bombs. We
succ
first want to find out if a given square can possibly have a bomb….
Slide 31 Slide 32
V = { V1 , V2 , V3 , V4 , V5 , V6 , V7 , V8 }, D = { B (bomb) , S (space) }
C = { (V1, V2) : { (B,S) , (S,B) }, (V1, V2, V3,) : { (B,S,S) , (S,B,S) , (S,S,B)},…}
Look at all intersections.
V1
What kind of intersection could this be? A
V2 concave intersection of three faces? Or
V8
an external convex intersection?
V7 V3
Adjacent intersections impose constraints on each other. Use CSP to
V6 V4 find a unique set of labelings. Important step to “understanding” the
V5 image.
Slide 33 Slide 34
Given a representation of the diagram, label each junction in one of the above
manners.
The junctions must be labeled so that lines are labeled consistently at both
ends.
Can you formulate that as a CSP? FUN FACT: Constraint Propagation always
Slide 35 works perfectly. Slide 36
6
Waltz Examples
Slide 37 Slide 38
Slide 41 Slide 42
7
Job-shop: the Variables and A slightly bigger example
Constraints before before
O11 R1 O12 R2 O13 R3
Variables
• The operation state times stIi
• The resources RIij (usually these are obvious from the definition of before
OIi. Only need to be assigned values when there are alternative
O21 R1 O22 R2
physical resources available, e.g. Pat or Chris for operating the drill).
Constraints: before before
• Precedence constraints. (Some OIis must be before some other O31 R3 O32 R1 O33 R2
OIjs).
• Capacity constraints. There must never be a pair of operations with before
O41 R4 O42 R2
overlapping periods of operation that use the same resources.
Example from [Sadeh and Fox, 96]: Norman M. Sadeh and Mark S. Fox, Variable and
Value Ordering Heuristics for the Job Shop Scheduling Constraint Satisfaction Problem,
Non-challenging question. Can you schedule our Job-shop? Artificial Intelligence Journal, Number Vol 86, No1, pages 1-41, 1996. Available from
citeseer.nj.nec.com/sadeh96variable.html
4 jobs. Each 3 units long. All jobs have release date 0 and due date
Slide 43 15. All operations use only one resource each. Slide 44
V7 B
V6 R Y
V4 G
B
V7
Y
Slide 45 Slide 46
constrained-value”. Choose the value which 6. Create a new search state. Cache the info you need for
backtracking. And go back to 1.
causes the smallest reduction in number of
available values for neighboring variables Slide 47 Slide 48
8
Job-shop example. Consistency Reactive CSP solutions
• Say you have built a large schedule.
enforcement • Disaster! Halfway through execution, one of the
Sadeh claims that generally forward-checking is resources breaks down. We have to reschedule!
better, computationally, than full constraint • Bad to have to wait 15 minutes for the scheduler to
propagation. But it can be supplemented with a make a new suggestion.
Job-shop specific TRICK.
Important area of research: efficient
The precedence constraints (i.e. the available schedule repair algorithms.
times for the operations to start due to the ordering • Question: If you expect that resources may
of operations) can be computed exactly, given a sometimes break, what could a scheduling program
partial schedule, very efficiently. do to take that into account?
• Unrelated Question: Why has none of this lecture
Slide 49 used A*? Slide 50