Slides

advertisement
Last bit on A*-search.
8 Puzzle I
 Heuristic: Number of
tiles misplaced
 Why is it admissible?
Average nodes expanded when
optimal path has length…
 h(start) = 8
…4 steps …8 steps …12 steps
 This is a relaxedproblem heuristic
UCS
112
TILES 13
6,300
39
3.6 x 106
227
8 Puzzle II
 What if we had an
easier 8-puzzle where
any tile could slide any
direction at any time,
ignoring other tiles?
 Total Manhattan
distance
 Why admissible?
 h(start) =
3 + 1 + 2 + … TILES
= 18
MANHATTAN
Average nodes expanded when
optimal path has length…
…4 steps
…8 steps
…12 steps
13
12
39
25
227
73
[demo: eight-puzzle]
8 Puzzle III
 How about using the actual cost as a
heuristic?
 Would it be admissible?
 Would we save on nodes expanded?
 What’s wrong with it?
 With A*: a trade-off between quality of
estimate and work per node!
Trivial Heuristics, Dominance
 Dominance: ha ≥ hc if
 Heuristics form a semi-lattice:
 Max of admissible
Graph Search
Tree Search: Extra Work!
 Failure to detect repeated states can cause
exponentially more work. Why?
Graph Search
 In BFS, for example, we shouldn’t bother
expanding the circled nodes (why?)
S
e
d
b
c
a
a
e
h
p
q
q
c
a
h
r
p
f
q
G
p
q
r
q
f
c
a
G
Graph Search
 Very simple fix: never expand a state twice
Graph Search
 Idea: never expand a state twice
 How to implement:
 Tree search + list of expanded states (closed list)
 Expand the search tree node-by-node, but…
 Before expanding a node, check to make sure its state is new
 Python trick: store the closed list as a set, not a list
 Can graph search wreck completeness? Why/why not?
 How about optimality?
Consistency
1
A
h=4
1
h=1
S
h=6
C
1
B
2
h=1
 What went wrong?
 Taking a step must not reduce f value!
3
G
h=0
Consistency
 Stronger than admissability
 Definition:
 C(A→C)+h(C)≧h(A)
 C(A→C)≧h(A)-h(C)
 Consequence:
 The f value on a path never
decreases
 A* search is optimal
h=4
A
1
h=0
C
h=1
3
G
Optimality of A* Graph Search
Proof:
 New problem (with graph instead of tree
search): nodes on path to G* that would have
been in queue aren’t, because some worse n’
for the same state as some n was dequeued
and expanded first (disaster!)
 Take the highest such n in tree
 Let p be the ancestor which was on the queue
when n’ was expanded
 Assume f(p) ≦ f(n) (consistency!)
 f(n) < f(n’) because n’ is suboptimal
 p would have been expanded before n’
 So n would have been expanded before n’, too
 Contradiction!
Optimality
 Tree search:
 A* optimal if heuristic is admissible (and nonnegative)
 UCS is a special case (h = 0)
 Graph search:
 A* optimal if heuristic is consistent
 UCS optimal (h = 0 is consistent)
 Consistency implies admissibility
 In general, natural admissible heuristics tend to
be consistent
Summary: A*
 A* uses both backward costs and
(estimates of) forward costs
 A* is optimal with admissible heuristics
 Heuristic design is key: often use relaxed
problems
Quiz 2 : A* search
(All heuristics are are non-negative and bounded by some B, i.e. h(x) ≦B.)





T/F: A* is optimal with any h(). False
T/F: A* is complete with any h(). True
T/F: A* with the zero heuristic is UCS.
True
T/F: Admissibility implies consistency.
False
T/F: If n’ is a sub-optimal path to n, then f(n)<f(n’) for any
heuristic. True h(n)=h(n’) but g(n)<g(n’)
 T/F: Admissibility is necessary for Graph-Search to be
optimal. True
Search Recap
Uniform Cost Search / BFS
Greedy Search / DFS
A* Search
A* applications
 http://pacman.elstonj.com/index.cgi?dir=vi
deos&num=&perpage=&section=
 http://www.youtube.com/watch?feature=pl
ayer_embedded&v=JnkMyfQ5YfY#!
CSE 511A: Artificial Intelligence
Spring 2013
Lecture 4: Constraint Satisfaction
Programming
Jan 29, 2012
Robert Pless, slides from Kilian Weinberger, Ruoyun Huang, adapted
from Dan Klein, Stuart Russell or Andrew Moore
Announcements
 Projects:
 Project 1 out. Due Thursday 10 days from now,
midnight.
21
1.What is a CSP?
What is Search For?
 Models of the world: single agents, deterministic actions,
fully observed state, discrete state space
 Planning: sequences of actions
 The path to the goal is the important thing
 Paths have various costs, depths
 Heuristics to guide, fringe to keep backups
 Identification: assignments to variables
 The goal itself is important, not the path
 All paths at the same depth (for some formulations)
 CSPs are specialized for identification problems
23
Search Problems
 A search problem consists of:
 A state space
 A successor function
“N”,
1.0
 A start state and a goal test
“E”, 1.0
 A cost function (for now we set cost=1 for all steps)
 A solution is a sequence of actions (a plan)
which transforms the start state to a goal state
One Example
 Schedule Lectures at Washburn University
Courses:
-A: Intro to AI
-B: Bioinformatics
-C: Computational Geometry
-D: Discrete Math
Constraints:
-Only one course per room / slot
-Each course meets one two hours slot
-A can only be in Jelly 204
-B must be scheduled before noon
-D must be in the afternoon
Time-table:
Lop101
9:00
10:00
11:00
12:00
13:00
14:00
Jolley 305
Search Problem
 State Space:
 (partially filled in) time schedule
 Successor Function:
 Assign time slot to unassigned course
 Start State:
Time-table:
 Empty schedule
Jelly 204
Lap101
 Goal test:
9:00
B
A
 All constraints are met
10:00
11:00
 All courses scheduled
C
12:00
13:00
14:00
D
Naïve Search Tree
A
A
B
A
B
A
B
A
AB
B
B
Tree is gigantic!
Depth?
Width?
Where is a solution?
Constraint Satisfaction Problems
 Standard search problems:
 State is a “black box”: arbitrary data structure
 Goal test: any function over states
 Successor function can be anything
 Constraint satisfaction problems (CSPs):
 A special subset of search problems
 State is defined by variables Xi with values from a
Search
domain D (sometimes D depends on i)
Problems
 Goal test is a set of constraints specifying
allowable combinations of values for subsets of
variables
 Path cost irrelevant!
CSPs
 Simple example of a formal representation
language
 Allows useful general-purpose algorithms with
more power than standard search algorithms
28
Example 1: Map-Coloring
 Variables:
 Domain:
 Constraints: adjacent regions must have
different colors
Implicit:
-or-
Explicit:
 Solutions are assignments satisfying all
constraints, e.g.:
29
Constraint Graphs
 Binary CSP: each constraint
relates (at most) two variables
 Binary constraint graph: nodes
are variables, arcs show
constraints
 General-purpose CSP
algorithms use the graph
structure to speed up search.
E.g., Tasmania is an
independent subproblem!
30
Example 2: Cryptarithmetic
 Variables:
 Domains:
 Constraints (boxes):
31
Example 2: Cryptarithmetic II
 Variables:
T, W, O, F, U, R
 Domains:
 Constraints:
(T * 100 + W * 10 + O) * 2= F * 1000 + O * 100 + U * 10 + R
32
Example 3: N-Queens
 Formulation 1:
 Variables:
 Domains:
 Constraints
33
Example 3: N-Queens
 Formulation 1.5:
 Variables:
 Domains:
 Constraints:
Implicit:
-orExplicit:
… there’s an even better way! What is it?
Example 3: N-Queens
 Formulation 2:
 Variables:
 Domains:
 Constraints:
Implicit:
-or-
Explicit:
Example 4: 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
Check out Peter Norvig’s homepage http://norvig.com/sudoku.html
Example 5: The Waltz Algorithm
 The Waltz algorithm is for interpreting line drawings of
solid polyhedra
 An early example of a computation posed as a CSP
?
 First, look at all intersections
Four types of junctions:
L, fork, T, arrow
37
38
Waltz on Simple Scenes
 3 Types of Lines:
 Boundary line (edge of an
object) () with right hand of
arrow denoting “solid” and left
hand denoting “space”
 Interior convex edge (+)
 Interior concave edge (-)
 4 types of junctions
 L, fork, T, arrow
 Adjacent intersections impose
constraints on each other
All the valid conjunction labeling:
Waltz on Simple Scenes
L Junctions
fork Junctions
fork Junctions
arrow Junctions
 Variable (edges):
All the valid conjunction labeling
(AB, AC, AE, BA, BD, …, )
 Domain: {+,-,,}
 Constraints (both ends have the same label):
arrow (AC, AE, AB), fork(BA, BF, BD), L(CA, CD),
arrow(DG, DC, DB), …
Waltz on Simple Scenes
At least 4 valid labeling choices
42
Example 6: Temporal Logic Reasoning
 Problem: The meeting ran non-stop the whole day. Each
person stayed at the meeting for a continuous period of
time. Ms White arrived after the meeting has began. In
turn, Director Smith was also present but he arrived after
Jones had left. Mr. Brown talked to Ms. White in
presence of Smith. Could possibly Jones and White
have talked during this meeting?
43
Example 6: Temporal Logic Reasoning
 Possible Relations:
before, meets, overlap,
start, during, finish, equal
truly-overlap()= overlaps + overlaps-by + starts + started-by + during +
contains+ finishes+ finished-by + equal
44
Example 6: Temporal Logic Reasoning
Event(s)
Variable(s)
The duration of the meeting
M
The period Jones, Brown, Smith, White was present
J, B, S, W
1. Ms White arrived after the meeting has began.
during(W,M) or finishes(W,M) or equals(W,M)
2. Director Smith was also present but he arrived after Jones had left.
after(S, J)
3. Mr. Brown talked to Ms. White in presence of Smith.
truly-overlap(B,M), truly-overlap(B,S), truly-overlap(W,S)
4. Could possibly Jones and White have talked during this meeting?
truly-overlap(J,W)
Real-World CSPs
 Assignment problems: e.g., who teaches what class
 Timetabling problems: e.g., which class is offered when
and where?
 Hardware configuration/verification
 Transportation scheduling
 Factory scheduling
 Floorplanning
 Fault diagnosis
 … lots more!
 Many real-world problems involve real-valued
variables…
45
46
Varieties of CSPs
 Discrete Variables
 Finite domains (Most cases!)
 Size d means O(dn) complete assignments
 E.g., Boolean CSPs, including Boolean satisfiability (NP-complete)
 Infinite domains (integers, strings, etc.)
 E.g., our temporal logic reasoning
 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 ESE505 Operation Research for a bit of this theory)
 There might be objective functions:
 Branch-and-Bound method
47
Varieties of Constraints
 Varieties of Constraints
 Unary constraints involve a single variable (equiv. to shrinking domains):
 Binary constraints involve pairs of variables:
 Higher-order constraints involve 3 or more variables:
e.g., 9-way different constraints in sudoku
 Preferences (soft constraints):




E.g., red is better than green
Often representable by a cost for each variable assignment
Gives constrained optimization problems
(We’ll ignore these until we get to Bayes’ nets)
2. How can we solve CSPs
fast?
By taking advantage of their
specific structure!
Standard Search Formulation
 Standard search formulation of CSPs (incremental)
 Let's start with the straightforward, dumb approach, then
fix it
 States are defined by the values assigned so far
 Initial state: the empty assignment, {}
 Successor function: assign a value to an unassigned variable
 Goal test: the current assignment is complete and satisfies all
constraints
 Simplest CSP ever: two bits, constrained to be equal
51
Search Methods
 What does BFS do?
 What does DFS do?
 What’s the obvious problem here?
 The order of assignment does not matter.
 What’s the other obvious problem?
 We are checking constraints too late.
52
Backtracking Search
 Idea 1: Only consider a single variable at each point




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
How many leaves are there?
 Idea 2: Only allow legal assignments at each point
 I.e. consider only values which do not conflict previous assignments
 Might have to do some computation to figure out whether a value is ok
 “Incremental goal test”
 Depth-first search for CSPs with these two improvements is called
backtracking search (useless name, really)
 Backtracking search is the basic uninformed algorithm for CSPs
 Can solve n-queens for n  25
54
Backtracking Example
 What are the choice points?
55
Improving Backtracking
 General-purpose ideas can give huge gains in
speed:




Which variable should be assigned next?
In what order should its values be tried?
Can we detect inevitable failure early?
Can we take advantage of problem structure?
NT
WA
SA
Q
NSW
V
56
Which Variable: Minimum Remaining Values
 Minimum remaining values (MRV):
 Choose the variable with the fewest legal values
 Why min rather than max?
 Also called “most constrained variable”
 “Fail-fast” ordering
57
Which Variable: Degree Heuristic
 Tie-breaker among MRV variables
 Degree heuristic:
 Choose the variable participating in the most
constraints on remaining variables
 Why most rather than fewest constraints?
58
Which Value: Least Constraining Value
 Given a choice of variable:
 Choose the least constraining
value
 The one that rules out the fewest
values in the remaining variables
 Note that it may take some
computation to determine this!
Better choice
 Why least rather than most?
 Combining these heuristics
makes 1000 queens feasible
59
Download