11
Brian Williams 16.410 - 13
September 29th, 2003 Slides adapted from:
6.034 Tomas Lozano Perez
and AIMA Stuart Russell & Peter Norvig
2
Outline
• Recap: constraint satisfaction problems (CSP)
• Solving CSPs
• Arc-consistency and propagation
• Analysis of constraint propagation
• Search
3
Solving CSPs involves some combination of:
1. Constraint propagation
• eliminates values that can’t be part of any solution
2. Search
• explores valid assignments
4
Arc Consistency
• Directed arc (Vi, Vj) is arc consistent if
• For every x in Di, there exists some y in Djsuch that assignment (x,y) is allowed by constraint Cij
• Or ∀x∈Di∃y∈Djsuch that (x,y) is allowed by constraint Cij where
•∀ denotes “for all”
•∃ denotes “there exists”
•∈ denotes “in”
Arc consistency eliminates values of each variable domain that can never satisfy a particular constraint (an arc).
Vi Vj
{1,2,3} {1,2}
=
5
• Directed arc (Vi, Vj) is arc consistent if
•∀x∈Di∃y∈Djsuch that (x,y) is allowed by constraint Cij
{1,2,3} {1,2}
Example:Given: Variables V1and V2 with Domain {1,2,3,4}
Constraint: {(1, 3) (1, 4) (2, 1)}
What is the result of arc consistency?
6
Achieving Arc Consistency via Constraint Propagation
• Directed arc (Vi, Vj) is arc consistentif
∀x∈Di∃y∈Djsuch that (x,y) is allowed by constraint Cij Arc consistency eliminates values of each variable domain that can never satisfy a particular constraint (an arc).
Constraint propagation: To achieve arc consistency:
• Delete every value from each tail domain Diof each arc that fails this condition,
•Repeatuntil quiescence:
• If element deleted from Dithen
•check directed arc consistency for each arc with head Di
• Maintain arcs to be checked on FIFO queue (no duplicates).
7
R,G,B
G R, G
Graph Coloring
Initial Domains
Different-color constraint V2
V3
Each undirected constraint arc denotes two directed constraint arcs.
8
Constraint Propagation Example
R,G,B
G R, G
Different-color constraint V1
V2
V3
Value deleted Arc examined
R,G,B
G R, G
V2
V3 V1
Graph Coloring
Initial Domains
Arcs to examine V1-V2, V1-V3, V2-V3
• Introduce queue of arcs to be examined.
• Start by adding all arcs to the queue.
9
V1 > V2
Value deleted Arc examined
R,G,B
G R, G
V2
V3 V1
Arcs to examine V1<V2, V1-V3, V2-V3
• Vi– Vjdenotes two arcs between Viand Vj.
• Vi < Vj denotes an arc from Vjand Vi.
• Delete unmentioned tail values
10
Constraint Propagation Example
R,G,B
G R, G
Different-color constraint V1
V2
V3
none V1 > V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R,G,B
G R, G
V2
V3 V1
Arcs to examine V1<V2, V1-V3, V2-V3
• Vi– Vjdenotes two arcs between Viand Vj.
• Vi < Vj denotes an arc from Vjand Vi.
• Delete unmentioned tail values
11
R,G,B
G R, G
Different-color constraint V2
V3
V2 > V1
none V1 > V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R,G,B
G R, G
V2
V3 V1
Arcs to examine V1-V3, V2-V3
• Vi– Vjdenotes two arcs between Viand Vj.
• Vi < Vj denotes an arc from Vjand Vi.
• Delete unmentioned tail values
12
Constraint Propagation Example
R,G,B
G R, G
Different-color constraint V1
V2
V3
none V2 > V1
none V1 > V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R,G,B
G R, G
V2
V3 V1
Arcs to examine V1-V3, V2-V3
• Vi– Vjdenotes two arcs between Viand Vj.
• Vi < Vj denotes an arc from Vjand Vi.
• Delete unmentioned tail values
13
none V1 – V2
Value deleted Arc examined
R,G,B
G R, G
V2
V3 V1
Arcs to examine V1-V3, V2-V3
• Vi– Vjdenotes two arcs between Viand Vj.
• Vi < Vj denotes an arc from Vjand Vi.
• Delete unmentioned tail values
14
Constraint Propagation Example
R,G,B
G R, G
Different-color constraint V1
V2
V3
V1>V3
none V1 – V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R,G,B
G R, G
V2
V3 V1
Arcs to examine V1<V3, V2-V3
• Vi– Vjdenotes two arcs between Viand Vj.
• Vi < Vj denotes an arc from Vjand Vi.
• Delete unmentioned tail values
15
R,G,B
G R, G
Different-color constraint V2
V3
V1(G) V1>V3
none V1 – V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R,G,B
G R, G
V2
V3 V1
Arcs to examine V1<V3, V2-V3
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
16
Constraint Propagation Example
R,G,B
G R, G
Different-color constraint V1
V2
V3
V1(G) V1>V3
none V1 – V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R,G,B
G R, G
V2
V3 V1
Arcs to examine
V1<V3, V2-V3, V2>V1, V1<V3,
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
17
V1<V3
V1(G) V1>V3
none V1 – V2
Value deleted Arc examined
R, B
G R, G
V2
V3 V1
Arcs to examine V2-V3, V2>V1
• Delete unmentioned tail values
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
18
Constraint Propagation Example
R,G,B
G R, G
Different-color constraint V1
V2
V3
none V1<V3
V1(G) V1>V3
none V1 – V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R, B
G R, G
V2
V3 V1
Arcs to examine V2-V3, V2>V1
• Delete unmentioned tail values
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
19
R,G,B
G R, G
Different-color constraint V2
V3
V2 >V3
V1(G) V1-V3
none V1 – V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R, B
G R, G
V2
V3 V1
Arcs to examine V2<V3, V2>V1
• Delete unmentioned tail values
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
20
Constraint Propagation Example
R,G,B
G R, G
Different-color constraint V1
V2
V3
V2(G) V2 >V3
V1(G) V1-V3
none V1 – V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R, B
G R, G
V2
V3 V1
Arcs to examine V2<V3, V2>V1
• Delete unmentioned tail values
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
21
V2(G) V2 >V3
V1(G) V1-V3
none V1 – V2
Value deleted Arc examined
R, B
G R, G
V2
V3 V1
Arcs to examine V2<V3, V2>V1 , V1>V2
• Delete unmentioned tail values
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
22
Constraint Propagation Example
R,G,B
G R, G
Different-color constraint V1
V2
V3
V3 > V2
V2(G) V2 >V3
V1(G) V1-V3
none V1 – V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R, B
G R
V2
V3 V1
Arcs to examine V2>V1 , V1>V2
• Delete unmentioned tail values
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
23
R,G,B
G R, G
Different-color constraint V2
V3
none V3 > V2
V2(G) V2 >V3
V1(G) V1-V3
none V1 – V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R, B
G R
V2
V3 V1
Arcs to examine V2>V1 , V1>V2
• Delete unmentioned tail values
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
24
Constraint Propagation Example
R,G,B
G R, G
Different-color constraint V1
V2
V3
V2>V1
V2(G) V2 -V3
V1(G) V1-V3
none V1 – V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R, B
G R
V2
V3 V1
Arcs to examine V1>V2
• Delete unmentioned tail values
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
25
none V2>V1
V2(G) V2 -V3
V1(G) V1-V3
none V1 – V2
Value deleted Arc examined
R, B
G R
V2
V3 V1
Arcs to examine V1>V2
• Delete unmentioned tail values
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
26
Constraint Propagation Example
R,G,B
G R, G
Different-color constraint V1
V2
V3
V1>V2
none V2>V1
V2(G) V2 -V3
V1(G) V1-V3
none V1 – V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R, B
G R
V2
V3 V1
Arcs to examine
• Delete unmentioned tail values
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
27
R,G,B
G R, G
Different-color constraint V2
V3
V1(R) V1>V2
none V2>V1
V2(G) V2 -V3
V1(G) V1-V3
none V1 – V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R, B
G R
V2
V3 V1
Arcs to examine
• Delete unmentioned tail values
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
28
Constraint Propagation Example
R,G,B
G R, G
Different-color constraint V1
V2
V3
V1(R) V1>V2
none V2>V1
V2(G) V2 -V3
V1(G) V1-V3
none V1 – V2
Value deleted Arc examined
Graph Coloring
Initial Domains
R, B
G R
V2
V3 V1
Arcs to examine V2>V1, V3>V1
• Delete unmentioned tail values
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
29
V3>V1 V2>V1
V1(R) V2-V1
V2(G) V2 -V3
V1(G) V1-V3
none V1 – V2
Value deleted Arc examined
B
G R
V2
V3 V1
Arcs to examine
• Delete unmentioned tail values
IF An element of a variable’s domain is removed,
THEN add all arcs tothat variableto the examination queue.
30
Constraint Propagation Example
R,G,B
G R, G
Different-color constraint V1
V2
V3
none V3>V1
none V2>V1
V1(R) V2-V1
V2(G) V2 -V3
V1(G) V1-V3
none V1 – V2
Value deleted Arc examined
Graph Coloring
Initial Domains
B
G R
V2
V3 V1
Arcs to examine
IF examination queue is empty THEN arc(pairwise) consistent.
31
• Solving CSPs
• Arc-consistency and propagation
• Analysis of constraint propagation
• Search
32
What is the Complexity of Constraint Propagation?
Assume:
• domains are of size at most d
•there are e binary constraints.
Which is the correct complexity?
1. O(d2) 2. O(ed2 ) 3. O(ed3) 4. O(ed)
33
Complexity:
• Straight forward arc consistency is O(ed3)
• There are 2 * e arcs to check
• Verifying arc consistency takes O(d2) for each arc.
• An arc is checked at most O(d) times.
34
Is arc consistency sound and complete?
R, G
R, G R, G
Each arc consistent solution selects a value for every variable from the arc consistent domains.
Completeness: Does arc consistency rule out any valid solutions?
•Yes
• No
Soundness: Is every arc-consistent solution a solution to the CSP?
• Yes
• No
35
R, G
R, G R, G
R, G R, G B, G
Graph Coloring
arc consistent but
no
solutions
arc consistent but
2
solutions, not 8.
B,R,G B,G,R
36
Next: To Solve CSPs we combine arc consistency and search
1. Arc consistency (Constraint propagation),
• eliminates values that are shown locally to not be a part of any solution.
2. Search
• explores consequences of committing to particular assignments.
Methods Incorporating Search:
• Standard Search
• BackTrack search (BT)
• BT with Forward Checking (FC)
• Dynamic Variable Ordering (DV)
• Iterative Repair
• Backjumping (BJ)