Lecture 5
Lecture 5
Spring 2025
Universidad Francisco de Vitoria
[These slides were created by Dan Klein and Pieter Abbeel for CS188 Intro to AI at UC Berkeley. All CS188 materials are available at http://ai.berkeley.edu.]
What is Search For?
Assumptions about the world: a single agent, deterministic actions, fully observed
state, discrete state space
Domains:
Explicit:
Constraints
Example: N-Queens
Formulation 2:
Variables:
Domains:
Constraints:
Implicit:
Explicit:
Constraint Graphs
Constraint Graphs
Variables:
Domains:
Constraints:
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)
Example: The Waltz Algorithm
The Waltz algorithm is for interpreting
line drawings of solid polyhedra as 3D
objects
An early example of an AI computation
posed as a CSP
?
Approach:
Each intersection is a variable
Adjacent intersections impose constraints
on each other
Solutions are physically realizable 3D
interpretations
Varieties of CSPs and Constraints
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
(see cs170 for a bit of this theory)
Varieties of Constraints
Varieties of Constraints
Unary constraints involve a single variable (equivalent to
reducing domains), e.g.:
Ordering:
Which variable should be assigned next?
In what order should its values be tried?
NT Q
WA
SA
NSW
V
NT Q
WA
SA
NSW
V
NT Q
WA SA
NSW
V
Arc V to NSW is consistent: for every x in the tail there is some y in the head which
could be assigned without violating a constraint
Arc Consistency of an Entire CSP (2/6)
A simple form of propagation makes sure all arcs are consistent:
NT Q
WA SA
NSW
V
Arc SA to NSW is consistent: for every x in the tail there is some y in the head which
could be assigned without violating a constraint
Arc Consistency of an Entire CSP (3/6)
A simple form of propagation makes sure all arcs are consistent:
NT Q
WA SA
NSW
V
Arc NSW to SA is not consistent: if we assign NSW = blue, there is no valid assignment
left for SA
To make this arc consistent, we delete NSW = blue from the tail
Arc Consistency of an Entire CSP (4/6)
A simple form of propagation makes sure all arcs are consistent:
NT Q
WA SA
NSW
V
Remember that arc V to NSW was consistent, when NSW had red and blue in its
domain
After removing blue from NSW, this arc might not be consistent anymore! We need to
recheck this arc.
Important: If X loses a value, neighbors of X need to be rechecked!
Arc Consistency of an Entire CSP (5/6)
A simple form of propagation makes sure all arcs are consistent:
NT Q
WA SA
NSW
V
Arc SA to NT is inconsistent. We make it consistent by deleting from the tail (SA = blue).
Arc Consistency of an Entire CSP (6/6)
A simple form of propagation makes sure all arcs are consistent:
NT Q
WA SA
NSW
V
SA has an empty domain, so we detect failure. There is no way to solve this CSP with
WA = red and Q = green, so we backtrack.
Arc consistency detects failure earlier than forward checking
Can be run as a preprocessor or after each assignment
Enforcing Arc Consistency in a CSP