Chapter 06
Chapter 06
Chapter 6
TB Artificial Intelligence
1 / 31
Outline
I CSP examples
I Backtracking search for CSPs
I Problem structure and problem decomposition
I Local search for CSPs
2 / 31
Constraint satisfaction problems (CSPs)
I Standard search problem: state is a “black box”—any old data structure that supports goal
test, eval, successor
I CSP:
I state is defined by variables Xi
I with values from domain Di
I goal test is a set of constraints specifying allowable combinations of values for subsets of
variables
I Simple example of a formal representation language
I Allows useful general-purpose algorithms with more power
than standard search algorithms
3 / 31
Example: Map-Coloring
Northern
Territory
Western Queensland
Australia
South
Australia
New South Wales
Victoria
4 / 31
Example: Map-Coloring contd.
Northern
Territory
Western Queensland
Australia
South
Australia
New South Wales
Victoria
Tasmania
NT
Q
WA
SA NSW
V
Victoria
General-purpose CSP algorithms use the graph structure to speed up search. E.g., Tasmania is
an independent subproblem!
6 / 31
Varieties of CSPs
I Discrete variables
I finite domains; size d =⇒ O(d n ) complete assignments
I e.g., Boolean CSPs, incl. Boolean satisfiability (NP-complete)
I infinite domains (integers, strings, etc.)
I e.g., job scheduling, variables are start/end days for each job
I need a constraint language, e.g., StartJob1 + 5 ≤ StartJob3
I linear constraints solvable, nonlinear undecidable
I Continuous variables
I e.g., start/end times for Hubble Telescope observations
I linear constraints solvable in poly time by LP methods
7 / 31
Varieties of constraints
8 / 31
Example: Cryptarithmetic
T WO F T U W R O
+ T WO
F O U R
X3 X2 X1
I Variables: F T U W R O X1 X2 X3
I Domains: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
I Constraints
alldiff(F , T , U, W , R, O)
O + O = R + 10 · X1
...
9 / 31
Real-world CSPs
I Assignment problems
e.g., who teaches what class
I Timetabling problems
e.g., which class is offered when and where?
I Hardware configuration
I Spreadsheets
I Transportation scheduling
I Factory scheduling
I Floorplanning
I ...
10 / 31
Standard search formulation (incremental)
11 / 31
Backtracking search
12 / 31
Backtracking search
13 / 31
Backtracking example
14 / 31
Backtracking example
14 / 31
Backtracking example
14 / 31
Backtracking example
14 / 31
Improving backtracking efficiency
15 / 31
Minimum remaining values
16 / 31
Degree heuristic
Degree heuristic:
choose the variable with the most constraints on remaining variables
17 / 31
Least constraining value
18 / 31
Forward checking
WA NT Q NSW V SA T
19 / 31
Forward checking
WA NT Q NSW V SA T
19 / 31
Forward checking
WA NT Q NSW V SA T
19 / 31
Forward checking
WA NT Q NSW V SA T
19 / 31
Constraint propagation
Forward checking propagates information from assigned to unassigned variables, but doesn’t
provide early detection for all failures:
WA NT Q NSW V SA T
20 / 31
Arc consistency
WA NT Q NSW V SA T
21 / 31
Arc consistency
WA NT Q NSW V SA T
21 / 31
Arc consistency
WA NT Q NSW V SA T
21 / 31
Arc consistency
WA NT Q NSW V SA T
21 / 31
Arc consistency
WA NT Q NSW V SA T
function AC-3( csp) returns the CSP, possibly with reduced domains
inputs: csp, a binary CSP with variables {X1 , X2 , . . . , Xn }
local variables: queue, a queue of arcs, initially all the arcs in csp
22 / 31
Problem structure
NT
Q
WA
SA NSW
V
Victoria
23 / 31
Problem structure contd.
24 / 31
Tree-structured CSPs
A E
B D
C F
Theorem
If the constraint graph has no loops, the CSP can be solved in O(n d 2 ) time
25 / 31
Algorithm for tree-structured CSPs
1. Choose a variable as root, order variables from root to leaves such that every node’s parent
precedes it in the ordering
A E
B D A B C D E F
C F
2. For j from n down to 2, apply RemoveInconsistent(Parent(Xj ), Xj )
3. For j from 1 to n, assign Xj consistently with Parent(Xj )
26 / 31
Nearly tree-structured CSPs
Conditioning: instantiate a variable, prune its neighbors’ domains
NT NT
Q Q
WA WA
SA NSW NSW
V
Victoria V
Victoria
T T
27 / 31
Iterative algorithms for CSPs
To apply to CSPs:
28 / 31
Example: 4-Queens
29 / 31
Performance of min-conflicts
Given random initial state, can solve n-queens in almost constant time for arbitrary n with high
probability (e.g., n = 10,000,000)
CPU
time
R
critical
ratio
30 / 31
Summary
I CSPs are a special kind of problem: states defined by values of a fixed set of variables goal
test defined by constraints on variable values
I Backtracking = depth-first search with one variable assigned per node
I Variable ordering and value selection heuristics help significantly
I Forward checking prevents assignments that guarantee later failure
I Constraint propagation (e.g., arc consistency) does additional work to constrain values and
detect inconsistencies
I The CSP representation allows analysis of problem structure
I Tree-structured CSPs can be solved in linear time
I Iterative min-conflicts is usually effective in practice
31 / 31