Artificial Intelligence: Russell & Norvig, AI: A Modern Approach, 3rd Ed
Artificial Intelligence: Russell & Norvig, AI: A Modern Approach, 3rd Ed
6 CONSTRAINT
SATISFACTION PROBLEMS
Russell & Norvig, AI: A Modern Approach, 3rd Ed
01/18/2021 1
Constraint Satisfaction Problems
• Standard search problems:
• State is a “black box”: arbitrary data structure
• Goal test can be any function over states
• Successor function can also be anything
3
CSP Examples
4
Example: Map Coloring
• Variables:
• Domains:
Implicit:
Explicit:
5
Constraint Graphs
6
Constraint Graphs
• Binary CSP: each constraint relates (at most) two
variables
7
Example: Cryptarithmetic
• Variables:
• Domains:
• Constraints:
8
Example: Cryptarithmetic
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)
10
Varieties of CSPs and Constraints
11
Varieties of CSPs
• Discrete Variables
• Finite domains
• Size d means O(dn) complete assignments
• E.g., Boolean CSPs, including Boolean satisfiability (NP-
complete)
• Infinite domains (integers, strings, etc.)
• E.g., job scheduling, variables are start/end times for each job
• Linear constraints solvable, nonlinear undecidable
• Continuous variables
• E.g., start/end times for Hubble Telescope observations
• Linear constraints solvable in polynomial time by LP methods
12
Types of Constraint
• Unary Constraint
• Binary
• Ternary
• Global Constraint- alldiff
• Absolute Constraint
• Preference Constraint – Constraint Optimization Problem
13
Varieties of Constraints
• Varieties of Constraints
• Unary constraints involve a single variable (equivalent to
reducing domains), e.g.:
15
Standard Search Formulation
• Standard search formulation of CSPs
16
Search Methods
17
Backtracking Search
18
Backtracking Search
• Backtracking search is the basic uninformed algorithm for solving
CSPs
• Idea 1: One variable at a time
• Variable assignments are commutative, so fix ordering
• I.e., [WA = red then NT = green] same as [NT = green then WA =
red]
• Only need to consider assignments to a single variable at each step
• Idea 2: Check constraints as you go
• I.e. consider only values which do not conflict previous assignments
• Might have to do some computation to check the constraints
• “Incremental goal test”
• Depth-first search with these two improvements
is called backtracking search (not the best name)
• Can solve n-queens for n 25 19
Backtracking Example
20
Backtracking Search
• Ordering:
• Which variable should be assigned next?
• In what order should its values be tried?
22
Ordering: Minimum Remaining Values
• Variable Ordering: Minimum remaining values (MRV):
• Fail-first heuristic
• Choose the variable with the fewest legal left values in its domain, thereby pruning
the search tree. If there is a variable X with 0 legal values remaining, then MRV
heuristic will select X and failure will be detected immediately. That helps avoiding
pointless searches through other variables which will always fail when X is finally
selected.
• Also called “most constrained variable”
23
Ordering: Least Constraining Value
• Value Ordering: Least Constraining Value
• Given a choice of variable, choose the least
constraining value
• I.e., the one that rules out the fewest values in the
remaining variables
• Note that it may take some computation to
determine this! (E.g., rerunning filtering)
24
Filtering
25
Filtering: Forward Checking
• Filtering: Keep track of domains for unassigned variables and cross off bad options
• Forward checking: Whenever a variable X is assigned, the fwd checking process looks at
each unassigned variable Y that is assigned to X by a constraint & deletes from Y’s
domain any value that is inconsistent with the value chosen for X
NT Q
WA
SA NSW
V
26
Filtering: Constraint Propagation
• Forward checking propagates information from assigned to unassigned variables, but
doesn't provide early detection for all failures:
NT Q
WA
SA
NSW
V
27
Arc Consistency
29
Path Consistency
30
K-Consistency
31
K-Consistency
32
K-Consistency
33
K-Consistency
34
Ordering
35
Interleaving Search and inference - Forward checking
36
Interleaving Search and inference - Forward checking
37
MAC(Maintaining arc consistency)
38
Intelligent Backtracking: Looking backward
• Chronological backtracking
• Backjumping: conflict set
39
Local Search for CSPs
• Min-conflicts
• Constraint weighting
40