Title: CSPs: Search and Arc Consistency
1CSPs Search and Arc Consistency Computer Science
cpsc322, Lecture 12 (Textbook Chpt
4.3-4.5) February, 1, 2008
2Lecture Overview
- Recap Search vs. CSPs
- Generate-and-Test
- Search
- Consistency
- Arc Consistency
3Recap Search vs. CSPs
- While search strategies (BFS, MBA, etc.)
- do not make any assumptions on how states are
represented - require three problem specific routines
- In CSPs
- the representation of states conforms to a
standard pattern - goal function can be specified in a generic way
- Same for heuristics
4Recap Search vs. CSPs
Standard Representation for States and Goals
Formal structures that can be used to simplify
the solution process (exponential reduction in
complexity)
5Example Map-Coloring
- Variables WA, NT, Q, NSW, V, SA, T
- Domains Di red,green,blue
- Constraints adjacent regions must have different
colors - e.g., WA ? NT, or
- (WA,NT) ? (red,green),(red,blue),(green,red),
(green,blue),(blue,red),(blue,green)
6Example Map-Coloring
- Models / Solutions are complete and consistent
assignments, e.g., WA red, NT green, Q red,
NSW green, V red,SA blue, T green
7Lecture Overview
- Recap
- Generate-and-Test
- Search
- Consistency
- Arc Consistency
8Generate-and-Test Algorithm
- The assignment space of a CSP is the space of
possible worlds - Algorithm
- Generate possible worlds one at a time from the
assignment space - Test them to see if they violate any constraints
- This procedure is able to solve any CSP
- However, the running time is proportional to the
size of the state space - always exponential in the number of variables
- far too long for many CSPs
9Lecture Overview
- Recap
- Generate-and-Test
- Search
- Consistency
- Arc Consistency
10CSPs as search problems
- CSPs can be mapped into search problems
- nodes assignments of values to a subset of the
variables - neighbours of a node nodes in which values are
assigned to one additional variable - start node the empty assignment (no variables
assigned values) - goal node a node which assigns a value to each
variable, and satisfies all of the constraints
Note the path to a goal node is not important
11CSPs as Search Problems
- What search strategy will work well for a CSP?
- there's no role for a heuristic function (every
solution is at depth n if there are n variables
(WHY?)) - the tree is always finite and has no cycles, so
DFS is better than BFS - DFS is one way of implementing generate-and-test
12CSPs as Search Problems
How can we prune the DFS Search tree?
- once we reach a node that violates one or more
constraints, we know that a solution cannot exist
below that point - thus we should prune/backtrack rather than
continuing to search - this can yield us exponential savings over
generate-and-test, though it's still exponential
13Solving CSPs by DFS Example
- Problem
- Variables A,B,C
- Domains 1, 2, 3, 4
- Constraints A lt B, B lt C
14Solving CSPs by DFS Example Efficiency
- Problem
- Variables A,B,C
- Domains 1, 2, 3, 4
- Constraints A lt B, B lt C
Note the algorithm's efficiency depends on the
order in which variables are expanded
Degree Heuristics
Minimum Remaining Heuristics
A1
A4
A2
A3
C1
C2
C3
C4
C1
C2
C3
C4
C1
C2
C3
C4
C1
C2
C3
C4
15Summary CSPs as Search Problems
- Any CSP can be solved by DFS
- General purpose successor function
- General purpose heuristics
- General purpose pruning strategy (based on goal
definition, i.e., the constraints)
16Lecture Overview
- Recap
- Generate-and-Test Recap
- Search
- Consistency
- Arc Consistency
17Can we do better than DFS with general heuristics?
- Key ideas
- prune the domains as much as possible before
searching for a solution.
Simple when using constraints involving single
variables (technically enforcing domain
consistency)
Definition A variable is domain consistent if no
value of its domain is ruled impossible by any
unary constraints.
- Example DB 1, 2, 3, 4 . domain consistent
if we have the constraint B ? 3.
18How do we deal with constraints involving
multiple variables?
- Definition (constraint network)
- A constraint network is defined by a graph, with
- one node for every variable
- one node for every constraint
- and undirected edges running between variable
nodes and constraint nodes whenever a given
variable is involved in a given constraint.
19Example Constraint Network
- Recall
- Variables A,B,C
- Domains 1, 2, 3, 4
- Constraints A lt B, B lt C
20Example Constraint Network for Map-Coloring
- Variables WA, NT, Q, NSW, V, SA, T
- Domains Di red,green,blue
- Constraints adjacent regions must have different
colors
21Lecture Overview
- Recap
- Generate-and-Test Recap
- Search
- Consistency
- Arc Consistency
22Arc Consistency
Definition (arc consistency) An arc
is arc consistent if for each value in
there is some value in such
that is satisfied.
23How can we enforce Arc Consistency?
- A network is arc consistent if all its arcs are
arc consistent. - If an arc is not arc consistent, all
values in for which there is no
corresponding value in may be deleted
from to make the arc
consistent. - This removal can never rule out any models (do
you see why?)
Y
X
Xlt Y
1,2,3
2,3,4
- A network is arc consistent if all its arcs are
arc consistent.
24Feedback ? or ?
- Lectures
- Slides
- Assignments
- AIspace
- Textbook
- Course Topics
- TAs
-
25Next class
- How to make a constraint network arc consistent?
Arc Consistency Algorithm