Professional Documents
Culture Documents
Part I
Constraint Satisfaction Problems
• What is a CSP?
– Finite set of variables, X1, X2, …, Xn
– Nonempty domain of possible values for each: D1, ..., Dn
– Finite set of constraints, C1...Cm
• Each constraint Ci limits the values that variables can take, e.g., X1 ≠ X2
– Each constraint Ci is a pair: Ci = (scope, relation)
• Scope = tuple of variables that participate in the constraint
• Relation = list of allowed combinations of variables
May be an explicit list of allowed combinations
May be an abstract relation allowing membership testig & listing
• CSP benefits
– Standard representation pattern
– Generic goal and successor functions
– Generic heuristics (no domain-specific expertise required)
Example: Sudoku
• Problem specification
1 2 3 4 5 6 7 8 9
A
Variables: {A1, A2, A3, … I7, I8, I9}
B
Domains: { 1, 2, 3, … , 9 }
C
Constraints:
D
each row, column “all different”
E
alldiff(A1,A2,A3…,A9), ...
F
each 3x3 block “all different”
G
alldiff(G7,G8,G9,H7,…I9), ...
H
I
• Examples of applications
– Scheduling the time of observations on the Hubble Space Telescope
– Airline schedules
– Cryptography
– Computer vision, image interpretation
Example: Map Coloring
Variables:
Domains: { red, green, blue }
Constraints: bordering regions must have different colors:
A solution is any setting of the variables that satisfies all the constraints, e.g.,
Example: Map Coloring
• Constraint graph
– Vertices: variables
– Edges: constraints
(connect involved variables)
• Graphical model
– Abstracts the problem to a canonical form
– Can reason about problem through graph connectivity
– Ex: Tasmania can be solved independently (more later)
• Binary CSP
– Constraints involve at most two variables
– Sometimes called “pairwise”
Aside: Graph coloring
• More general problem than map coloring
• Planar graph:
graph in 2D plane with no
edge crossings
• Continuous variables
– Ex: Building an airline schedule or class schedule
– Linear constraints: solvable in polynomial time by LP methods
Varieties of constraints
• Unary constraints involve a single variable,
– e.g., SA ≠ green
9
Simplify…
• We restrict attention to:
T W O Non-pairwise CSP:
+ T W O O O+O = R + 10*C1
= F O U R
R C1 C1 = {0,1}
For example:
O = 4 all-different W W+W+C1 = U + 10*C2
R = 8
W = 3 7 3 4 U C2 C2 = {0,1}
U = 6 + 7 3 4
T = 7 = 1 4 6 8 T T+T+C2 = O + 10*C3
F = 1 C3 C3 = {0,1}
F
Note: not unique – how many solutions? C3 = F
Example: Cryptarithmetic problems
• Try it yourself at home:
S E N D
+ M O R E
= M O N E Y
• Incremental formulation
– Initial State: the empty assignment {}
– Actions: Assign a value to an unassigned variable provided that it does not
violate a constraint
– Goal test: the current assignment is complete
(by construction it is consistent)
– Path cost: constant cost for every step (not really relevant)
BUT: solution is at depth n (# of variables)
For BFS: branching factor at top level is nd
next level: (n-1)d
…
Total: n! dn leaves! But there are only dn complete assignments!
• Uninformed algorithm
– Poor general performance
Backtracking search
(R&N Fig. 6.5)
22
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
23
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
24
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
25
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
26
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
27
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
28
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
29
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
30
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
31
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
32
Backtracking search
• Expand deepest unexpanded node
• Generate only one child at a time.
• Goal-Test when inserted.
– For CSP, Goal-test at bottom
Future= green dotted circles
Frontier=white nodes
Expanded/active=gray nodes
Forgotten/reclaimed= black nodes
33
Backtracking search
(R&N Fig. 6.5)
• Before search:
– Reduce the search space
– Arc-consistency, path-consistency, i-consistency
– Variable ordering (fixed)
• During search:
– Look-ahead schemes:
• Detecting failure early; reduce the search space if possible
• Which variable should be assigned next?
• Which value should we explore first?
– Look-back schemes:
• Backjumping
• Constraint recording
• Dependency-directed backtracking
Look-ahead: Variable and value orderings
• Intuition:
– Apply propagation at each node in the search tree (reduce future branching)
– Choose a variable that will detect failures early (low branching factor)
– Choose value least likely to yield a dead-end (find solution early if possible)
• Forward-checking
– (check each unassigned variable separately)
• Maintaining arc-consistency (MAC)
– (apply full arc-consistency)
36
Dependence on variable ordering
• Example: coloring
39
Degree heuristic
• Another heuristic for selecting the next variable
– a.k.a. most constraining variable heuristic
41
Variable and value orderings
• Minimum remaining values for variable ordering
• Least constraining value for value ordering
– Why do we want these? Is there a contradiction?
• Intuition:
– Choose a variable that will detect failures early (low branching factor)
– Choose value least likely to yield a dead-end (find solution early if possible)
42
Summary
• CSPs
– special kind of problem: states defined by values of a fixed set of variables,
goal test defined by constraints on variable values
• Heuristics
– Variable ordering and value selection heuristics help significantly