CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted...

22
CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics it: adapted from slides by Stuart Russell of UC Berkeley. This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License .

Transcript of CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted...

Page 1: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

CS 312: Algorithm Design & Analysis

Lecture #37: A* (cont.); Admissible Heuristics

Credit: adapted from slides by Stuart Russell of UC Berkeley.

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.

Page 2: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Announcements

Project #7: TSP Whiteboard: due today Early: next Wednesday (4/8) Due: next Friday (4/10)

Competition (“The Bake-Off”) Big 3 problems in the Competition set survey 3 problems in the One-Time Competition set survey

Hall of Fame (Bake-Off results) presented last day of class (4/13)

Optional: Cookie Bake-Off Bring to final exam A bit of extra HW credit for winning this bake-off

Page 3: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Objectives

Prove the optimality of A*

Understand Admissible Heuristics

Revisit the idea of “Relaxed Problems” more deeply

Page 4: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Search algorithms

Page 5: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

A. Beam Search

Q. How could you change A* or B&B to be more memory efficient?

Various forms of Beam search: Agenda size Threshold from best

Sacrifices guarantees of optimality

Page 6: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Theorem

If is admissible, then A* is optimal

Page 7: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Proof of Optimality of A*

Suppose some sub-optimal goal state G2 has been generated and is on the agenda. Let n be an unexpanded state on the agenda such that n is on a shortest (optimal) path to the optimal goal state G. Assume h() is admissible.

Focus on G2:

f(G2) = g(G2) since h(G2) = 0

g(G2) > g(G) since G2 is suboptimal

Page 8: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Proof of Optimality of A*

Suppose some sub-optimal goal state G2 has been generated and is on the agenda. Let n be an unexpanded state on the agenda such that n is on a shortest (optimal) path to the optimal goal state G. Assume h() is admissible.

f(G2) = g(G2) since h(G2) = 0

g(G2) > g(G) since G2 is suboptimal

Focus on G:

f(G) = g(G) since h(G) = 0

f(G2) > f(G) substitution

Page 9: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Proof of Optimality of A*

Suppose some sub-optimal goal state G2 has been generated and is on the agenda. Let n be an unexpanded state on the agenda such that n is on a shortest (optimal) path to the optimal goal state G. Assume h() is admissible.

Now focus on n:

h(n) ≤ h*(n) since h is admissible

g(n) + h(n) ≤ g(n) + h*(n) algebra

f(n) = g(n) + h(n) definition

f(G) = g(n) + h*(n) by assumption

f(n) ≤ f(G) substitution

Hence f(G2) > f(n), and A* will never select G2 for expansion.

f(G2) = g(G2) since h(G2) = 0

g(G2) > g(G) since G2 is suboptimal

f(G) = g(G) since h(G) = 0

f(G2) > f(G) substitution

Page 10: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Optimality of A*

A* expands states in order of increasing f value Gradually adds "f-contours" of states

Like Uniform cost search, but more directed!

Contour i has all states with f=fi, where fi < fi+1

Page 11: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Solving the 8-puzzle with A*

states? actions? goal test? path cost g(n)?

Page 12: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Example: The 8-puzzle

states? locations of tiles actions? move blank left, right, up, down goal test? = goal state (given) path cost g(n)? 1 per move

Page 13: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Example: The 8-puzzle

What does the state space look like? How deep? Note: optimal solution of n-Puzzle family is NP-

hard Not known to be in NP

Page 14: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Admissible heuristics?

Page 15: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Admissible heuristics?

total pieces out of place manhattan distance(blank, g_blank) (or other norm) optimal solution to problem with w/ 2 blanks (possibly solved

recursively by A*!) look-up in pattern database if goal; 1 otherwise total manhattan distance x 2 (-1) if blank involved total of: optimal number of moves between any two locations on

board # of pieces lower and after me

Page 16: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Relaxed problems A problem with fewer restrictions is called a

relaxed problem

Theorem:The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem E.g., our bound function for TSP

Page 17: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Relaxed problems

If the rules of the 8-puzzle are relaxed so that a tile can move anywhere then h1(n) gives the shortest solution

If the rules are relaxed so that a tile can move to any adjacent

square then h2(n) gives the shortest solution

Page 18: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Admissible heuristics

E.g., for the 8-puzzle: h1(n) = number of misplaced tiles h2(n) = total Manhattan distance (i.e., no. of squares from desired location of each tile)

h1(S) = ? h2(S) = ?

Page 19: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Admissible heuristics

E.g., for the 8-puzzle: h1(n) = number of misplaced tiles h2(n) = total Manhattan distance (i.e., no. of squares from desired location of each tile)

h1(S) = ? 8 h2(S) = ? 3+1+2+2+2+3+3+2 = 18

Page 20: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Dominance; i.e. Tighter Bounds If h2(n) ≥ h1(n) for all n (both admissible)

then h2 dominates h1 h2 is better for search

Typical search costs (average number of states expanded) for d-puzzle:

d=11 (3x4)Iterative Deepening Search (IDS) = 3,644,035 statesA*(h1) = 227 states A*(h2) = 73 states

d=24 (5 x 5)IDS = too many statesA*(h1) = 39,135 states A*(h2) = 1,641 states

Page 21: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Compare and Contrast

A* vs. Branch & Bound Reasoning about an admissible heuristic in A*

is like reasoning about optimistic bounds in B&B

A* doesn’t include a BSSF Thus, B&B is potentially more memory

efficient

Page 22: CS 312: Algorithm Design & Analysis Lecture #37: A* (cont.); Admissible Heuristics Credit: adapted from slides by Stuart Russell of UC Berkeley. This work.

Assignment

HW #28