















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
















Chapter 5
Modified for Fall 2006
Chapter 5
CSP examples
uninformed search and informed search
General search applied to CSPs
Backtracking
Forward checking
Heuristics for CSPs
Modified for Fall 2006
Chapter 5
Standard search problem:
state
is a “black box”—any old data structure
that supports goal test, eval, successor
state
is defined by
variables
i with
values
from
domain
i
That is,
i defines possible values for
i .
goal test
is a set of
constraints
specifying
allowable combinations of values for subsets of variables
Allows useful
general-purpose
algorithms with more power
Modified for Fall 2006 than standard search algorithms
Chapter 5
Assume one queen in each column. Which row does each one go in? Variables
Domains
D i = { 1 ,
Constraints
i 6 =
Q
j (cannot be in same row)
i −
(^) Q
j | 6 =
| i −
(^) j | (or same diagonal)
1
2
E.g., possible values for Translate each constraint into set of allowable values for its variables
1 , Q
2 ) are
Modified for Fall 2006
Chapter 5
Variables
Domains
Constraints
unary
constraints)
or
, etc.
(^) , etc.
Modified for Fall 2006
Chapter 5
Color a map so that no adjacant countries have the same color Variables
Countries
i
Domains
Red, Blue, Green
Constraints
1 6 = C 2 , C 1 6
5 , etc.
1
C
2
C
3
C
C 5
C 6
4
C
Constraint graph:
1
C
2
C
3
C C 5 C 6 4
C
Modified for Fall 2006
Chapter 5
Initial stateStates are defined by the values assigned so far We can still use standard search algorithms for CSPs.
: all variables unassigned
Operators
: assign a value to an unassigned variable
Goal test
: all variables assigned, no constraints violated
Modified for Fall 2006 Notice that this is the same for all CSPs!
Chapter 5
ASSIGNED UNASSIGNED
C1 C2 C
ASSIGNED UNASSIGNED
C1 = RED C2 C
ASSIGNED UNASSIGNED
ASSIGNED UNASSIGNED
C2 = BLUE C1 C
C3 = GREENC1 C
Modified for Fall 2006
Chapter 5
Use depth-first search, but
⇒ b = | D i |
(can be done in the
Successors
function)
The constraint violation check can be implemented in two ways:
Successors
to assign only values that
are allowed, given the values already assigned
or 2) check constraints are satisfied before expanding a state
Can solveBacktracking search is the basic uninformed algorithm for CSPs
n -queens for
n
≈
Modified for Fall 2006
Chapter 5
Idea
: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values
Simplified map-coloring example:
red
blue
green
1
2
3
4
5
1
C
2
C
3
C
C 5
4
C
Can solve
n -queens up to
n
≈
Modified for Fall 2006
Chapter 5
Idea
: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values
Simplified map-coloring example:
red
blue
green
1
2
3
4
5
1
C
2
C
3
C
C 5
4
C
Modified for Fall 2006
Chapter 5
Idea
: Keep track of remaining legal values for unassigned variables Terminate search when any variable has no legal values
Simplified map-coloring example:
red
blue
green
1
2
3
4
C
2
C
3
C
C 5
4
C
Modified for Fall 2006
Chapter 5
least-constraining-value heuristic. (i.e., which color to use first?)
Try to give more freedom for future choices. Given
1 (^) =
(^) Green
2 (^) =
(^) Red
, choose what for
3 (^) =
(^) ??
3 (^) =
(^) Red
over
Blue
least-constraining-value
1
C
2
C
3
C
C 5
C 6
C
Can solve
n -queens for
n
≈
Modified for Fall 2006
Chapter 5
19
To apply to CSPs:“complete” states, i.e., all variables assigned Hill-climbing, simulated annealing typically work with
operatorsallow states with unsatisfied constraints
reassign
variable values
min-conflictsVariable selection: randomly select any conflicted variable
heuristic:
i.e., hillclimb withchoose value that violates the fewest constraints
h ( n ) = total number of violated constraints
Modified for Fall 2006
Chapter 5