Download Slides on Constraint Satisfaction Problems | CS 440 and more Study notes Computer Science in PDF only on Docsity!
Constraint SatisfactionConstraint Satisfaction
Problems^ Problems
Introduction to Artificial
Intelligence
CS440/ECE
Lecture 5
FIRST HOMEWORK OUT
CHECK CLASS WEB PAGE!
Mid TermMid Term
The mid term will be on
Thursday March 9
in class
A* SearchA* Search
-^
Idea: avoid expanding paths that are already expensive
-^
Evaluation function:
f(n) = g(n) + h(n)
g(n)
= path cost so far to reach
n.
(used in uniform-cost search)
h(n)
= estimated path cost to goal from
n.
(used in greedy search)
f(n)
= estimated total cost of path through n to goal
Admissible HeuristicsAdmissible Heuristics
-^
A* search uses an
admissible
heuristic in which
h(n)
≤
h*(n)
where
h*(n)
is the TRUE cost from n.
root
Goal
n^
g(n) : cost of path
h*(n): true minimum cost to goal
h(n) : Heuristic (expected) minimum
cost to goal
Implementation of Search AlgorithmsImplementation of Search Algorithms^ Function
GENERAL-SEARCH (
problem, queing-fn)
returns
a solution or failure
queue
MAKE-QUEUE (MAKE-NODE(INITIAL-STATE[
problem
]))
loop do
if
queue
is empty,
then return
failure
node
Remove-Front(
queue
)
if
GOAL-TEST [
problem
]^
applied to STATE
(node)
succeeds
then return
node
if
STATE
(node)
is not in
closed
then
add
STATE(node)
to
closed;
queue
QUEING-FN(
queue
,EXPAND(
node
,operators[problem]))
end Function
GENERAL-SEARCH (
problem, queing-fn)
returns
a solution or failure
queue
MAKE-QUEUE (MAKE-NODE(INITIAL-STATE[
problem
]))
loop do
if
queue
is empty,
then return
failure
node
Remove-Front(
queue
)
if
GOAL-TEST [
problem
]^
applied to STATE
(node)
succeeds
then return
node
if
STATE
(node)
is not in
closed
then
add
STATE(node)
to
closed;
queue
QUEING-FN(
queue
,EXPAND(
node
,operators[problem]))
end
Consistency (=Consistency (=
MonotonicityMonotonicity
-^
A heuristic is said to be
consistent
when for any node
n
successor
n’
of
n
, we have
h(n) ≤ c(n,n’) + h(n’)
, where
c(n,n’)
is the (minimum) cost of a step from
n
to
n’.
-^
This is a form of triangular inequality:
-^
Consistent heuristics are admissible. Not all admissibleheuristics are consistent.
-^
When a heuristic is consistent, the values of
f(n)
along any
path are nondecreasing.
-^
A* with a consistent heuristic is optimal.
n
n’
g
h(n)
h(n’)
c(n,n’)
Admissible Heuristics:Admissible Heuristics:
Example: the 8^ Example: the 8
PuzzlePuzzle
-^
Path cost: total number of vertical or horizontal moves
-^
Two different heuristics:–
h1(n)
= number of misplaced tiles
h2(n)
= total
Manhattan
distance
(number of squares to desired location for each tile)
So, what are
h1(start
) and
h2(start)
h1(s) = 7h2(s) = 2 + 3 + 3 + 2 + 4 + 2 + 0 + 2 = 18
Start
Goal
DominanceDominance
-^
Given two admissible heuristics
h1(n)
and
h2(n),
which is better?
-^
If
h’(n)
≥
h(n)
for all
n
, then
h’
is said to dominate
h
h’
is better for search
-^
For our 8-puzzle heuristic, does h2 dominate h1?
Each data point corresponds to 100 instances of the8-puzzle problem in which the solution depth varies.
Constraint Satisfaction Problems (Constraint Satisfaction Problems (
CSPsCSPs
))
-^
Standard search problem:State is a “black box” --- any old data structure that
supports goal test, eval, successor.
-^
CSP:– State is defined by
variables
V
withi
values
from
domain
D
.i
constraints
specifying allowable
combinations of values for subsets of variables.
-^
Allows useful general-purpose algorithms with more powerthan standard search algorithms.
Example: 4Example: 4
Queens as a CSPQueens as a CSP
-^
Place 4 queens on a 4 by 4 chess boardsuch that no queen can take another
-^
Assume one queen in each column.Which row does each one go in?
-^
Variables: Q
= row of queen # ii
-^
Domains: D
= {1, 2, 3, 4}i
-^
Constraints–
Q
≠i Q
j^
(cannot be in same row)
-^
|Q
|^ j ≠^
|i - j| (or same diagonal)
-^
Translate each constraint into set of allowable values for its variablesE.g., values for (Q
, Q 1
) are (1,3) (1,4) (2,4) (3,1) (4,1) (4,2) 2
Example:Example:
CryptarithmeticCryptarithmetic
-^
Variables^ D, E, M, N, O, R, S, Y
-^
Domains^ {0, 1, 2, 3 ,4, 5, 6, 7, 8, 9 }
-^
Constraints^ M
0, S
0 (unary constraints)
Y = D + E
or
Y = D + E – 10.
D
E, D
M, D
N, etc.
S E N D
+ M O R E M O N E Y
Example: Map coloringExample: Map coloring
-^
Color a map so that no adjacantcountries have the same color
-^
Variables:^ Countries
C
i
-^
Domains:^ {Red, Blue, Green}
-^
Constraints:^ C
C
, C 2
1
C
, etc. 5
-^
Constraint graph:
C
1
C
2
C
3
C
C
6
C
4
Applying standard searchApplying standard search
- Initial state: all variables unassigned.– Operators: assign one value in domain to one of
the unassigned variables if the result does notconflict with previous assignments.
- Goal test: all variables assigned, no constraints
violated.
-^
Notice that this is the same for all CSPs! Let's start with the straightforward, dumb approach,and then fix it.
ImplementationImplementation
-^
CSP state keeps track of which variables have values so far.
-^
Each variable has a domain and a current value.
-^
Constraints can be represented–
explicitly as sets of allowable values, or
-^
implicitly by a function that tests for satisfaction of the constraint.
Datatype CSP-STATE
components
UNASSIGNED: a list of variables not yet assignedASSIGNED: a list of variables that have values
Datatype CSP-VAR
components
NAME, for I/O purposesDOMAIN: a list of possible valuesVALUE, current value (if any)