You are on page 1of 88

Constraint Satisfaction Problems

1
Agenda
o Intuition
o Formulation
o Backtracking
o Improvements
o Consistencies
o Structural Improvement

2
Intuition

3
Recall
o Search problems:
o Find the sequence of actions that leads to the goal.
o Sequence of actions means a path in the search space.
o Paths come with different costs and depths.
o We use “rules of thumb” aka heuristics to guide the search effici
ently.
o Constraint satisfaction problems:
o A search problem too!
o We care about the goal itself, Just like local searches
4
Definition
o Search problem:
o The state is represented as a black box i.e. we do not know the un
derlying data structure used to represent the state
o The goal test is also a black box i.e. the search algorithm does not
know what happens when a goal is declared
o The same could be said about the successor function

A C

5
Definition
o CSP problems:
o A state: defined by variables Xi with values from domain Di. As
we saw in factored representation
o A goal test is a set of constraints specifying allowable combinati
ons of values for subsets of variables.

6
B C
Definitions
o A Constraint Satisfaction Problem can be characterized usin
g three elements:
o A set of variables, X = {X1, X2, … , Xn}
o A set of domains for each variable: D = {D1, D2, … Dn}
o A set of constraints C that specify allowable combinations of value
s.
o The solution to a CSP problem is to find a valid assignment
of allowable values for every variable, such that all the cons
traints are satisfied i.e. we want a solution that is a consiste
nt assignment
o= 7
Example
Crossword Puzzle
o Variables: 1 2 3
o Eight Variables X = {1, 2 … 8}
4 5
o Domains: 6 7
o 1, 2, 3, 8
o {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
8
o 4, 5
o {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
o 6, 7
o {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’} AFT HOSE LINE
S
o Constraints ALE KEEL SAILS
o 1[3] = 2[1], 1[5] = 3[1]
o
EEL KNOT SHEE
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
T
o 7[1] = 2[4], 7[2] = 5[2], 7[3] = 3[4]
o 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5] HEEL LASE STEE
R R
8 HIKE LEE TIE
Example
8-Queen problem
o Place N-Queens on a NxN Chess board such that no queen a
ttacks other queens
o Variables
o Domains
o Constraints

9
Example
8-Queen problem Alternate
o Place N-Queens on a NxN Chess board such that no queen a
ttacks other queens
o Variables
o Domains
o Constraints

Implicit:

Explicit:

10
Example –
Map Coloring
o Variables: E
o All the tiles X = {A , B, C, D, E}
D A
o Domains B
o D = {Red, Green, Blue} C
o Constraints
o A != B, A != C, A != D, A != E
E
o B != C, C != D, D != E
D A
B
C
11
Example –
Map Coloring (Book)
o Variables:

o Domains:

o Constraints: adjacent regions must have


different colors
Implicit:

Explicit:
o Solutions are assignments satisfying all
constraints, e.g.:

12
CSP - Applications
o Scheduling
o Building design
o Planning
o Optimization/Satisfaction
o Vision
o Graph layout
o Network management
o VLSI design …etc…

13
Constraint Graph

14
Constraint Graph
o Binary CSP: each constraint relates (at most) two variables

o Binary constraint graph: nodes are variables, arcs show cons


traints

o General-purpose CSP algorithms use the graph structure to


speed up search. E.g., Tasmania is an independent subprobl
em!

15
CSP Applet
(from airspaces.org)

16
Constraint Graph
E E
7
4
D A
B D 3 1 B
A
C
6 5
2

o Binary Constraint C
1) A != B
2) A != C
3) A != D
4) A != E
5) B != C
6) C != D
7) D != E

17
Example:
Cryptarithmetic
o Variables:
S E N D M O R X1 X2 X3
S E N D
o Domains: +M OR E
MO N EY
o Constraints:
alldiff( S E N D M O R )
S E N D M O R
D + E = Y + 10 * X1

X1
18 X2 X3
Example:
Sudoku
 Variables:
 Each (open) square
 Domains:
 {1,2,…,9}
 Constraints:
9-way alldiff for each column
9-way alldiff for each row
9-way alldiff for each region
(or can have a bunch of
pairwise inequality
constraints)
19
Varieties of variables
o Discrete variables:
o Finite domains:
o assume n variables, d values, then the number of complete assignments is O(dn).
o e.g., map coloring, 8-queens problem
o Infinite domains (integers, strings, etc.):
o need to use a constraint language,
o e.g., job scheduling. T1 + d <= T2.
o Continuous variables:
o Common in operations research
o Linear programming problems with linear or non linear equalities

20
Varieties of constraints
o Unary constraints: involve a single variable e.g., SA 6= green
o Binary constraints: involve pairs of variables e.g., SA 6= WA
o Global constraints: involve 3 or more variables e.g., Alldiff t
hat specifies that all variables must have different values (e.
g., cryptarithmetic puzzles, Sudoku)
o Preferences (soft constraints):
o Example: red is better than green
o Often represented by a cost for each variable assignment
o constrained optimization problems
21
Generate and Test
o Can we use a brute-force approach?
o It would require to check 35 combinations
E A = ‘R’, B = ‘R’, C = ‘R’, D = ‘R’, E = ‘R’ Constraint Failing A != B
D A A = ‘R’, B = ‘R’, C = ‘R’, D = ‘R’, E = ‘G’ Constraint Failing A != B
B
C
A = ‘R’, B = ‘R’, C = ‘R’, D = ‘R’, E = ‘B’ Constraint Failing A != B

A = ‘R’, B = ‘R’, C = ‘R’, D = ‘G’, E = ‘R’ Constraint Failing A != B

Too much time spent on useless solutions

22
Generate and Test

23
Solving CSPs
State-space search algorithms: search!

24
Solving CSPs
o CSP Algorithms: Algorithm can do two things:
o Search: choose a new variable assignment from many possibilities
o Inference: constraint propagation, use the constraints to spread the
word: reduce the number of values for a variable which will reduc
e the legal values of other variables etc.
o As a preprocessing step, constraint propagation can someti
mes solve the problem entirely without search.
o Constraint propagation can be intertwined with search.

25
Backtracking Search
o BTS: Backtracking search is the basic uninformed search for
CSPs. It’s a DFS s.t.
o 1. Assign one variable at a time: assignments are commutative. e.
g., (WA=red, NT=green) is same as (NT=green, WA=red)
o 2. Check constraints on the go: consider values that do not conflict
with previous assignments.

26
Backtracking Search
o Initial state: empty assignment {}
o States: are partial assignments
o Successor function: assign a value to an unassigned variable
o Goal test: the current assignment is complete and satisfies al
l constraints

27
Backtracking
E
D A B
C
E E E
D A B D A B D A B
C C C

E E E
D A B D A B D A B
C C C

E E E
D A B D A B D A B
C C C

28
Backtracking

29
Backtracking

30
Backtracking

31
Backtracking

32
Backtracking Search

33
How can we improve
Backtracking Search?
Make use of Heuristics for deciding:
o Which variables will be selected next for assignment?
o In what order the selected variable’s values will be tried?
o Can we detect which paths will fail, before the failure?
o Can we make use of the structure of the problem to improve
search?

34
Which variable to
select first?
o Minimum Remaining Values
Choose the variable with the fewest legal values in its domain

35
Which value to
select first?
o Least constraining value
o LCV: Given a variable, choose the least constraining value: the one
that rules out the fewest values in the remaining variables

Pick the ones that are likely to work!

36
Can we detect failure
early?
o YES!
o Forward checking
o Arc-consistency

37
Forward checking
o Keep track of remaining legal values for the unassigned vari
ables.
o Terminate when any variable has no legal values.
o After a assigning a value ‘x’ to a variable ‘X’
o Check the variables that are in-constraint with ‘X’. Let us say that a
variable ‘Y’ is in constraint with ‘X’
o Apply the impact of the value ‘x’ on the domain of ‘Y’ for e.g. if are
solving the map coloring problem, then this would imply to remo
ve the value ‘x’ from the domain of ‘Y’

38
Forward Checking
5 1 2 3 4 5
4 1 2
3 5
4 1 2
5
4 1 2 3
3
5
4 1 2
3

5
4 1 2
3
5
4 1 2
3

5
4 1 2
3

39
Forward Checking

NT Q

WA NW

SA
V

Constraint Graph
40
Forward Checking (2)

NT Q

WA NW

WA Q V NT SA NW T SA
V

• Forward Checking Helps to cut values of variables that have not been
searched. But unable to investigate the problem
41
Constraint propagation
o Forward checking propagates information from assigned to unassigned variable
s.
o Observe:

o Forward checking does not check interaction between unassigned variables! Her
e SA and NT! (They both must be blue but can’t be blue!).
o Forward checking improves backtracking search but does not look very far in th
e future, hence does not detect all failures.
o We use constraint propagation, reasoning from constraint to constraint. e.g., arc
consistency test.

42
Different kinds of
Consistencies
o Node-consistency (unary constraints): A variable Xi is node
consistent if all the values of Domain(Xi) satisfy all unary co
nstraints
o Arc-consistency (binary constraints): X  Y is arc-consisten
t if and only if every value x of X is consistent with some val
ue y of Y .
o Path-consistency (n-ary constraints): generalizes arc-consist
ency from binary to multiple constraints.
Note: It is always possible to transform all n-ary constraints into binary constraints. Often, CSPs solvers
are designed to work with binary constraints.
43
Arc consistency
o Simplest form of propagation makes each arc consistent.
o X  Y is consistent IFF for every value x of X, there is some
allowed y.

44
Arc consistency
o Simplest form of propagation makes each arc consistent.
o X  Y is consistent IFF for every value x of X, there is some
allowed y.

45
Arc consistency
o Simplest form of propagation makes each arc consistent.
o X  Y is consistent IFF for every value x of X, there is some
allowed y.

46
Arc consistency
o Simplest form of propagation makes each arc consistent.
o X  Y is consistent IFF for every value x of X, there is some
allowed y.

47
Arc consistency

48
Complexity of AC-3
o Let n be the number of variables, and d be the domain size.
o If every node (variable) is connected to the rest of the variabl
es, then we have n * (n − 1) arcs (constraints)  O(n2)
o Each arc can be inserted in the queue d times  O(d)
o Checking the consistency of an arc costs  O(d2).
o Overall complexity is O(n2d3).

49
Backtracking w/ inference

50
AC-3 Algorithm (1)
procedure AC-3
Q = {(D1,D2), (D1,D3), (D2,D1), (D2,D4),
Q = { (Di, Dj) in arcs(G) }
(D2,D7), (D2,D8), (D3,D1), (D3,D4),
while not Q empty
(D3,D7), (D3,D8), (D4,D2), (D4,D3),
select and delete (Dk, Dm) from Q;
(D4,D5), (D5,D4), (D5,D7), (D5,D8),
(D6,D8), (D7,D2), (D7,D3), (D7,D5),
if REVISE(Dk, Dm) then
(D8,D2), (D8,D3), (D8,D5), (D8,D6) }
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
51 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (2)
procedure AC-3
Q = {(D1,D2), (D1,D3), (D2,D1), (D2,D4),
Q = { (Di, Dj) in arcs(G) }
(D2,D7), (D2,D8), (D3,D1), (D3,D4),
while not Q empty
(D3,D7), (D3,D8), (D4,D2), (D4,D3),
select and delete (Dk, Dm) from Q;
(D4,D5), (D5,D4), (D5,D7), (D5,D8),
(D6,D8), (D7,D2), (D7,D3), (D7,D5),
if REVISE(Dk, Dm) then
(D8,D2), (D8,D3), (D8,D5), (D8,D6)}
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
52 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (3)
procedure AC-3
Q = {(D1,D3), (D2,D1), (D2,D4),
Q = { (Di, Dj) in arcs(G) }
(D2,D7), (D2,D8), (D3,D1), (D3,D4),
while not Q empty
(D3,D7), (D3,D8), (D4,D2), (D4,D3),
select and delete (Dk, Dm) from Q;
(D4,D5), (D5,D4), (D5,D7), (D5,D8),
(D6,D8), (D7,D2), (D7,D3), (D7,D5),
if REVISE(Dk, Dm) then
(D8,D2), (D8,D3), (D8,D5), (D8,D6)}
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
53 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (4)
procedure AC-3
Q = {(D2,D1), (D2,D4),
Q = { (Di, Dj) in arcs(G) }
(D2,D7), (D2,D8), (D3,D1), (D3,D4),
while not Q empty
(D3,D7), (D3,D8), (D4,D2), (D4,D3),
select and delete (Dk, Dm) from Q;
(D4,D5), (D5,D4), (D5,D7), (D5,D8),
(D6,D8), (D7,D2), (D7,D3), (D7,D5),
if REVISE(Dk, Dm) then ,(D1,D2)
(D8,D2), (D8,D3), (D8,D5), (D8,D6)}
Q = Q union {(Dx, Dk) in }
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
54 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (5)
procedure AC-3
Q = {(D2,D4),
Q = { (Di, Dj) in arcs(G) }
(D2,D7), (D2,D8), (D3,D1), (D3,D4),
while not Q empty
(D3,D7), (D3,D8), (D4,D2), (D4,D3),
select and delete (Dk, Dm) from Q;
(D4,D5), (D5,D4), (D5,D7), (D5,D8),
(D6,D8), (D7,D2), (D7,D3), (D7,D5),
if REVISE(Dk, Dm) then ,(D1,D2)
(D8,D2), (D8,D3), (D8,D5), (D8,D6)}
Q = Q union {(Dx, Dk) in }
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
55 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (6)
procedure AC-3
Q = {(D2,D7), (D2,D8), (D3,D1), (D3,D4),
Q = { (Di, Dj) in arcs(G) }
(D3,D7), (D3,D8), (D4,D2), (D4,D3),
while not Q empty
(D4,D5), (D5,D4), (D5,D7), (D5,D8),
select and delete (Dk, Dm) from Q;
(D6,D8), (D7,D2), (D7,D3), (D7,D5),
(D8,D2), (D8,D3), (D8,D5), (D8,D6),
if REVISE(Dk, Dm) then
(D1,D2) }
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
56 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (7)
procedure AC-3
Q = {(D2,D8), (D3,D1), (D3,D4),
Q = { (Di, Dj) in arcs(G) }
(D3,D7), (D3,D8), (D4,D2), (D4,D3),
while not Q empty
(D4,D5), (D5,D4), (D5,D7), (D5,D8),
select and delete (Dk, Dm) from Q;
(D6,D8), (D7,D2), (D7,D3), (D7,D5),
(D8,D2), (D8,D3), (D8,D5), (D8,D6),
if REVISE(Dk, Dm) then
(D1,D2) }
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
57 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (8)
procedure AC-3
Q = {(D3,D1), (D3,D4), (D3,D7), (D3,D8),
Q = { (Di, Dj) in arcs(G) }
(D4,D2), (D4,D3), (D4,D5), (D5,D4),
while not Q empty
(D5,D7), (D5,D8), (D6,D8), (D7,D2),
select and delete (Dk, Dm) from Q;
(D7,D3), (D7,D5), (D8,D2), (D8,D3),
,(D1,D3)
(D8,D5), (D8,D6), (D1,D2) }
if REVISE(Dk, Dm) then }
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
58 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (9)
procedure AC-3
Q = {(D3,D4), (D3,D7), (D3,D8),
Q = { (Di, Dj) in arcs(G) }
(D4,D2), (D4,D3), (D4,D5), (D5,D4),
while not Q empty
(D5,D7), (D5,D8), (D6,D8), (D7,D2),
select and delete (Dk, Dm) from Q;
(D7,D3), (D7,D5), (D8,D2), (D8,D3),
(D8,D5), (D8,D6), (D1,D2), (D1,D3) }
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
59 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (10)
procedure AC-3
Q = {(D3,D7), (D3,D8),
Q = { (Di, Dj) in arcs(G) }
(D4,D2), (D4,D3), (D4,D5), (D5,D4),
while not Q empty
(D5,D7), (D5,D8), (D6,D8), (D7,D2),
select and delete (Dk, Dm) from Q;
(D7,D3), (D7,D5), (D8,D2), (D8,D3),
(D8,D5), (D8,D6), (D1,D2), (D1,D3) }
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
60 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (11)
procedure AC-3
Q = {(D3,D8),
Q = { (Di, Dj) in arcs(G) }
(D4,D2), (D4,D3), (D4,D5), (D5,D4),
while not Q empty
(D5,D7), (D5,D8), (D6,D8), (D7,D2),
select and delete (Dk, Dm) from Q;
(D7,D3), (D7,D5), (D8,D2), (D8,D3),
(D8,D5), (D8,D6), (D1,D2), (D1,D3) }
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
61 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (12)
procedure AC-3
Q = {(D4,D2), (D4,D3), (D4,D5), (D5,D4),
Q = { (Di, Dj) in arcs(G) }
(D5,D7), (D5,D8), (D6,D8), (D7,D2),
while not Q empty
(D7,D3), (D7,D5), (D8,D2), (D8,D3),
select and delete (Dk, Dm) from Q;
(D8,D5), (D8,D6), (D1,D2), (D1,D3)
, }
(D2,D4), (D3,D4)
if REVISE(Dk, Dm) then }
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
62 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (13)
procedure AC-3
Q = {(D4,D3), (D4,D5), (D5,D4),
Q = { (Di, Dj) in arcs(G) }
(D5,D7), (D5,D8), (D6,D8), (D7,D2),
while not Q empty
(D7,D3), (D7,D5), (D8,D2), (D8,D3),
select and delete (Dk, Dm) from Q;
(D8,D5), (D8,D6), (D1,D2), (D1,D3),
(D2, D4), (D3, D4) }
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
63 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (14)
procedure AC-3
Q = {(D4,D5), (D5,D4),
Q = { (Di, Dj) in arcs(G) }
(D5,D7), (D5,D8), (D6,D8), (D7,D2),
while not Q empty
(D7,D3), (D7,D5), (D8,D2), (D8,D3),
select and delete (Dk, Dm) from Q;
(D8,D5), (D8,D6), (D1,D2), (D1,D3),
(D2, D4), (D3, D4) }
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
64 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (15)
procedure AC-3
Q = {(D5,D4),
Q = { (Di, Dj) in arcs(G) }
(D5,D7), (D5,D8), (D6,D8), (D7,D2),
while not Q empty
(D7,D3), (D7,D5), (D8,D2), (D8,D3),
select and delete (Dk, Dm) from Q;
(D8,D5), (D8,D6), (D1,D2), (D1,D3),
(D2, D4), (D3, D4) }
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
65 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (16)
procedure AC-3
Q = {(D5,D7), (D5,D8), (D6,D8), (D7,D2),
Q = { (Di, Dj) in arcs(G) }
(D7,D3), (D7,D5), (D8,D2), (D8,D3),
while not Q empty
(D8,D5), (D8,D6), (D1,D2), (D1,D3),
select and delete (Dk, Dm) from Q; ,
(D2, D4), (D3, D4) }
(D4,D5) }
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
66 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (17)
procedure AC-3
Q = {(D5,D8), (D6,D8), (D7,D2),
Q = { (Di, Dj) in arcs(G) }
(D7,D3), (D7,D5), (D8,D2), (D8,D3),
while not Q empty
(D8,D5), (D8,D6), (D1,D2), (D1,D3),
select and delete (Dk, Dm) from Q;
(D2, D4),(D3, D4),(D4,D5) }
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
67 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (18)
procedure AC-3
Q = {(D6,D8), (D7,D2),
Q = { (Di, Dj) in arcs(G) }
(D7,D3), (D7,D5), (D8,D2), (D8,D3),
while not Q empty
(D8,D5), (D8,D6), (D1,D2), (D1,D3),
select and delete (Dk, Dm) from Q;
(D2, D4),(D3, D4),(D4,D5) }
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
68 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (19)
procedure AC-3
Q = {(D7,D2),
Q = { (Di, Dj) in arcs(G) }
(D7,D3), (D7,D5), (D8,D2), (D8,D3),
while not Q empty
(D8,D5), (D8,D6), (D1,D2), (D1,D3),
select and delete (Dk, Dm) from Q;
(D2, D4),(D3, D4),(D4,D5)
, }
(D2,D7), (D3,D7),
if REVISE(Dk, Dm) then (D5,D7) }
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
69 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (20)
procedure AC-3
Q = {(D7, D3), (D7, D5), (D8,D2), (D8,D3),
Q = { (Di, Dj) in arcs(G) }
(D8, D5), (D8, D6), (D1,D2), (D1,D3),
while not Q empty
(D2, D4), (D3, D4), (D4,D5),
select and delete (Dk, Dm) from Q;
(D2, D7), (D3, D7), (D5, D7) }
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
70 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (21)
procedure AC-3
Q = {(D7, D5), (D8,D2), (D8,D3),
Q = { (Di, Dj) in arcs(G) }
(D8, D5), (D8, D6), (D1,D2), (D1,D3),
while not Q empty
(D2, D4), (D3, D4), (D4,D5),
select and delete (Dk, Dm) from Q;
(D2, D7), (D3, D7), (D5, D7) }
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
71 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (22)
procedure AC-3
Q = {(D8,D2), (D8,D3),
Q = { (Di, Dj) in arcs(G) }
(D8, D5), (D8, D6), (D1,D2), (D1,D3),
while not Q empty
(D2, D4), (D3, D4), (D4,D5),
select and delete (Dk, Dm) from Q;
(D2, D7), (D3, D7), (D5, D7)
, }
(D2,D8), (D3,D8), (D5,D8), (D6,
if REVISE(Dk, Dm) then D8) }
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
72 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (23)
procedure AC-3
Q = {(D8,D3),
Q = { (Di, Dj) in arcs(G) }
(D8, D5), (D8, D6), (D1,D2), (D1,D3),
while not Q empty
(D2, D4), (D3, D4), (D4,D5),
select and delete (Dk, Dm) from Q;
(D2, D7), (D3, D7), (D5, D7),
(D2, D8), (D3, D8), (D5, D8), (D6, D8)
if REVISE(Dk, Dm) then
}
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
73 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (24)
procedure AC-3
Q = {(D8, D5), (D8, D6), (D1,D2), (D1,D3),
Q = { (Di, Dj) in arcs(G) }
(D2, D4), (D3, D4), (D4,D5),
while not Q empty
(D2, D7), (D3, D7), (D5, D7),
select and delete (Dk, Dm) from Q;
(D2, D8), (D3, D8), (D5, D8), (D6, D8)
}
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
74 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (25)
procedure AC-3
Q = {(D8, D6), (D1,D2), (D1,D3),
Q = { (Di, Dj) in arcs(G) }
(D2, D4), (D3, D4), (D4,D5),
while not Q empty
(D2, D7), (D3, D7), (D5, D7),
select and delete (Dk, Dm) from Q;
(D2, D8), (D3, D8), (D5, D8), (D6, D8)
}
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
75 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (26)
procedure AC-3
Q = {(D1,D2), (D1,D3),
Q = { (Di, Dj) in arcs(G) }
(D2, D4), (D3, D4), (D4,D5),
while not Q empty
(D2, D7), (D3, D7), (D5, D7),
select and delete (Dk, Dm) from Q;
(D2, D8), (D3, D8), (D5, D8), (D6, D8)
}
if REVISE(Dk, Dm) then
Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
76 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
AC-3 Algorithm (27)
procedure AC-3
, }
Q = {(D3, D8), (D5, D8), (D6, D8)
Q = { (Di, Dj) in arcs(G) } (D1,D3), (D4,D3), (D7,D3), (D8,
while not Q empty D3) }
select and delete (Dk, Dm) from Q;

if REVISE(Dk, Dm) then


Q = Q union {(Dx, Dk) in
arc(G)} D1 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end if D2 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end while D3 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
end AC-3 D4 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
D5 = {‘HEEL’, ‘HIKE’, ‘KEEL’, ‘KNOT’, ‘LINE’}
7
D6 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
5 6
D7 = {‘AFT, ‘ALE’, ‘EEL’, ‘LEE’, ‘TIE’}
2 D8 = {‘HOSES’, ‘LASER’, ‘SAILS’, ‘SHEET’, STEER’}
4
Constraints
1[3] = 2[1], 1[5] = 3[1]
1 8
4[2] = 2[3], 4[3] = 5[1], 4[4] = 3[3]
7[1] = 2[4], 7[2] = 5[2], 7[3]
77 = 3[4]
3 8[1] = 6[2], 8[3] = 2[5], 8[4] = 5[3], 8[5] = 3[5]
Algorithm AC-3
o Can we use AC-3 for map coloring?
5
4 1 2
3 1 2 3 4 5
5
4 1 2

3
procedure AC-3
Q = { (Di, Dj) in arcs(G) } Q = {(D1, D2), (D1, D3), (D1, D4), (D1,
while not Q empty D5),
select and delete (Dk, Dm) from Q; (D2, D1), (D2, D3), (D3, D1), (D3,
D2),
if REVISE(Dk, Dm) then (D3, D4), (D4, D1), (D4, D3), (D4,
Q = Q union {(Dx, Dk) in D5), = {‘R’, ‘G’, ‘B’} Constraints
D1
D2 = {‘R’, ‘G’, ‘B’}
arc(G)} (D5, D1), (D5, D4) } 1 != 2, 1 != 3,
D3 = {‘R’, ‘G’, ‘B’} 1 != 4, 1 != 5,
end if D4 = {‘R’, ‘G’, ‘B’} 2 != 3, 3 != 4,
D5 = {‘R’, ‘G’, ‘B’}
end while 78 4 != 5
end AC-3
Can we take advantage
of the Problem Structure?

79
Can we take advantage
of the Problem Structure?
Complexity:
Let d be the size of the domain and n be the number of variables.
Time complexity for BTS is O(dn).
Suppose we decompose into subproblems, with c variables per
subproblem.
Then we have n/c subproblems.
c variables per subproblem takes O(dc).
The total for all subproblems takes O(n/c dc ) in the worst case

80
Problem structure
o Example
o Let us take 80 Boolean variables i.e. n = 80, d = 2
o If we do not decompose into sub problems, the even if we are com
puting @ 10 million nodes per second. It would takes about
280 = 1.2 * 1024 which would take 3.83 million years
o Assume we can decompose into 4 subproblems with c = 20.
4 * 220 = 4.2 * 106
0.4 seconds

81
Problem structure
o Turning a problem into independent subproblems is not always poss
ible.
o Can we leverage other graph structures?
o Yes, if the graph is tree-structured or nearly tree-structured.
o A graph is a tree if any two variables are connected by only one path
.
o Idea: use DAC, Directed Arc Consistency
o A CSP is said to be directed arc-consistent under an ordering X1,X2, .
. . ,Xn IFF every Xi is arc-consistent with each Xj for j > i.

82
Tree-Structured CSPs

o Theorem: if the constraint graph has no loops, the CSP can be solved in O(n d2)
time
o Compare to general CSPs, where worst-case time is O(dn)

83
Tree-Structured CSPs
o Algorithm for tree-structured CSPs:
o Order: Choose a root variable, order variables so that parents precede
children

o Remove backward: For i = n : 2, apply RemoveInconsistent(Parent(Xi),Xi)


o Assign forward: For i = 1 : n, assign Xi consistently with Parent(Xi)

Runtime: O(n d2) (why?)


84
Nearly Tree-Structured CSPs

o Conditioning: instantiate a variable, prune its neighbors' domains


o Cutset conditioning: instantiate (in all ways) a set of variables such
that the remaining constraint graph is a tree
o Cutset size c gives runtime O( (dc) (n-c) d2 ), very fast for small c
85
Summary
o CSPs are a special kind of search problems:
o states defined by values of a fixed set of variables
o goal test defined by constraints on variable values
o Backtracking = depth-first search with one variable assigned
per node
o Variable ordering and value selection heuristics help
o Forward checking prevents assignments that guarantee later
failure

86
Summary
o Constraint propagation (e.g., arc consistency) is an important mecha
nism in CSPs.
o It does additional work to constrain values and detect inconsistencies
.
o Tree-structured CSPs can be solved in linear time
o Further exploration: How can local search be used for CSPs?
o The power of CSPs: domain-independent, that is you only need to de
fine the problem and then use a solver that implements CSPs mechan
isms.
o Play with CSP solver? Try http://aispace.org/constraint/.
87
Credits
o Artificial Intelligence: a modern approach, 3rd edition \
By Stuart Russell. And Peter Norvig

http://aima.cs.berkeley.edu/

88

You might also like