CS 312: Algorithm Analysis
description
Transcript of CS 312: Algorithm Analysis
![Page 1: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/1.jpg)
Slides by: Eric Ringger, adapted from slides by Stuart Russell of UC Berkeley.
CS 312: Algorithm Analysis
Lecture #36: Best-first State-space Search: A*
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
![Page 2: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/2.jpg)
Announcements Homework #26 optional
Homework #27 due Wednesday
Project #7: TSP Early: Wednesday Due: Friday Respond to survey by end of day Friday Questions?
Will accept late project submissions up through next Tuesday at midnight!
![Page 3: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/3.jpg)
Project #7
![Page 4: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/4.jpg)
HW #26 Problem #1
4 6 0 2
3 0 4 75 2 6 04 0 8 20 3 1 2
M
![Page 5: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/5.jpg)
HW #26 Problem #1
4 6 0 2
3 0 4 75 2 6 04 0 8 20 3 1 2
M
![Page 6: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/6.jpg)
Objectives
Understand Best-first search as a sub-class of state-space search algorithms
Introduce A* Search Compare and contrast with Branch &
Bound Understand Admissible Heuristics
![Page 7: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/7.jpg)
Acknowledgment
Russell & Norvig: 4.1-4.2
![Page 8: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/8.jpg)
Review: State-Space Search Basic idea:
Represent partial solutions (and solutions) as states Find a solution by searching the state space Search involves generating successors of states (i.e.,
“expanding” states) and pruning wisely
A search strategy is defined by specifying the following: The manner of state expansion The order of state expansion
![Page 9: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/9.jpg)
Uninformed search strategies
Use only the information available in the problem definition
Are not informed by discoveries during the search.
Examples: Breadth-first search Depth-first search Depth-limited search Iterative deepening search
![Page 10: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/10.jpg)
Informed: Best-first search A type of informed search strategy
Use an evaluation function f(n) for each state Estimate of "desirability"
Basic idea: Explore (expand) most desirable / promising state, according to the evaluation function
Examples: Without agenda:
Greedy best-first search With agenda:
Uniform-cost search Single goal, State-space variant of Dijkstra’s
A* search
![Page 11: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/11.jpg)
State-space search algorithms
![Page 12: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/12.jpg)
Problem: Shortest Path
Map of Romania, distances in km
Admittedly, not a hard problem.
![Page 13: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/13.jpg)
Greedy best-first search Evaluation function (heuristic) = estimate of cost from state to
e.g., straight-line distance from to Bucharest
Greedy best-first search expands the state that appears to be closest to goal
No agenda
Contrast with Simple Scissors (from proj. #4)
![Page 14: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/14.jpg)
Greedy best-first search example
![Page 15: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/15.jpg)
Greedy best-first search example
![Page 16: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/16.jpg)
Greedy best-first search example
![Page 17: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/17.jpg)
Greedy best-first search example
![Page 18: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/18.jpg)
Analysis of Search Strategies We analyze search strategies in the following terms:
completeness: does it always find a solution if one exists? optimality: does it always find an optimal solution, guaranteed? time efficiency: number of states generated space efficiency: maximum number of states in memory
“high water” mark on the agenda
Time and space efficiency are measured in terms of b: maximum branching factor of the search tree d: depth of the least-cost solution m: maximum depth of the state space (may be ∞)
![Page 19: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/19.jpg)
Properties of greedy best-first search
Complete? No – can get stuck in loops, e.g., Iasi Neamt Iasi Neamt …
or in dead ends Optimal?
No
Time? O(m*b)
Space? O(m)
![Page 20: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/20.jpg)
A* search Idea: avoid expanding paths that are already too
expensive (at best)
Very similar to Branch and Bound! But no BSSF And no eager update of the BSSF Solutions just go onto the agenda (always a priority queue) First solution settled from the agenda wins
Also: Split the bound function into two parts: Evaluation function f(n) = g(n) + h(n)
= estimated total cost of path through n to goal g(n) = cost so far to reach state n h(n) = estimated cost to go from state n to goal
![Page 21: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/21.jpg)
A* search example
![Page 22: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/22.jpg)
A* search example
![Page 23: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/23.jpg)
A* search example
![Page 24: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/24.jpg)
A* search example
![Page 25: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/25.jpg)
A* search example
![Page 26: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/26.jpg)
A* search example
Contrast with Dijkstra’s.
Contrast with B&B.
![Page 27: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/27.jpg)
Properties of A* Complete?
Yes unless there are infinitely many states n such that f(n) ≤
f(G)
Optimal? Yes, given an admissible heuristic
Time? O(bm), Exponential
Space? O(bm), worst case: keeps all states on agenda
![Page 28: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/28.jpg)
For Comparison:Uniform Cost Search
How does A* compare with Dijkstra’s algorithm? Both use priority queue as agenda A* solved shortest path (singular); Dijkstra’s solves shortest paths
(plural) A* has better heuristic function; Dijkstra’s: h(n)=0
0 is uniformly the estimated remaining cost for every state A* searches graph or state-space; Dijkstra’s explores a graph
In state-space search: Uniform cost search is the single-goal version of Dijkstra’s
How could you have used A* in project #4? What about project #5?
![Page 29: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/29.jpg)
Admissible heuristics A heuristic h(n) is admissible iff for every state n,
h(n) ≤ h*(n) where h*(n) is the true cost to reach the goal state from n.
An admissible heuristic never overestimates the cost to reach the goal it is optimistic it is a lower bound for minimization (upper bound for maximization)
Example: hSLD(n) for the shortest path problem never overestimates the actual road distance
Theorem: If h(n) is admissible, then A* is optimal
![Page 30: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/30.jpg)
For Project #7 Would you use A* for Project #7?
Why not?
What happens if you use a simple priority queue for your agenda in B&B?
Would it be correct?
Will you win?
![Page 31: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/31.jpg)
For comparison:Branch and Bound Optimization
Not best-first!
Idea: avoid expanding paths that are already too expensive at best, and prune them!
BSSF = best solution so far Allows pruning Permits any-time solution
Bound function f(n) Estimated total cost of path through state n to goal (an optimistic bound)
You know this well!
![Page 32: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/32.jpg)
Properties of Branch and Bound Complete?
Yes
Optimal? Yes
As long as it runs to completion As long as bound function is optimistic (a lower bound)
Time? O(bm), Exponential
Space? O(bm)
At worst, keeps all states in memory and does not prune. At best?
![Page 33: CS 312: Algorithm Analysis](https://reader036.fdocuments.in/reader036/viewer/2022062315/5681613f550346895dd0ab2c/html5/thumbnails/33.jpg)
Assignment
HW #27: A* for the 8-puzzle