notes dijstra s algorithm corrected syllabus. tree search implementation strategies require data...

34
Notes Dijstra’s Algorithm Corrected syllabus

Upload: ebony-atwill

Post on 29-Mar-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Notes

Dijstra’s Algorithm Corrected syllabus

Page 2: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Tree Search Implementation Strategies

Require data structure to model search tree

Tree Node: State (e.g. Sibiu) Parent (e.g. Arad) Action (e.g. GoTo(Sibiu)) Path cost or depth (e.g. 140) Children (e.g. Faragas, Oradea) (optional,

helpful in debugging)

Page 3: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Queue

Methods: Empty(queue)

Returns true if there are no more elements Pop(queue)

Remove and return the first element Insert(queue, element)

Inserts element into the queue InsertFIFO(queue, element) – inserts at the end InsertLIFO(queue, element) – inserts at the front InsertPriority(queue, element, value) – inserts

sorted by value

Page 4: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

INFORMED SEARCH

Page 5: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Search

goal

start

Uninformed search Informed search

Page 6: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Informed Search

What if we had an evaluation function h(n) that gave us an estimate of the cost associated with getting from n to the goal h(n) is called a heuristic

Page 7: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Romania with step costs in km

h(n)

Page 8: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Greedy best-first search

Evaluation function f(n) = h(n) (heuristic) e.g., f(n) = hSLD(n) = straight-line distance

from n to Bucharest

Greedy best-first search expands the node that is estimated to be closest to goal

Page 9: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Romania with step costs in km

n h(n)

f(n)

Page 10: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Best-First Algorithm

Page 11: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Performance of greedy best-first search

Complete?

Optimal?

Page 12: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Failure case for best-first search

Page 13: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Performance of greedy best-first search

Complete? No – can get stuck in loops, e.g., Iasi

Neamt Iasi Neamt

Optimal? No

Page 14: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Complexity of greedy best first search

Time? O(bm), but a good heuristic can give

dramatic improvement

Space? O(bm) -- keeps all nodes in memory

Page 15: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

What can we do better?

Page 16: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

A* search

Ideas: Avoid expanding paths that are already

expensive Consider

Cost to get here (known) – g(n) Cost to get to goal (estimate from the heuristic)

– h(n)

Page 17: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

A * Evaluation functions

Evaluation function f(n) = g(n) + h(n) g(n) = cost so far to reach n h(n) = estimated cost from n to goal f(n) = estimated total cost of path

through n to goal

start goaln

g(n) h(n)

f(n)

Page 18: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

n g(n)

h(n)

f(n)

Page 19: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e
Page 20: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

A* Heuristics

A heuristic h(n) is admissible if for every node 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, i.e., it is optimistic Example: hSLD(n) (never overestimates the

actual road distance)

Page 21: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

What happens if heuristic is not admissible?

Will still find solution (complete)

But might not find best solution (not optimal)

Page 22: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Properties of A* (w/ admissible heuristic)

Complete? Yes (unless there are infinitely many nodes with f ≤ f(G) )

Optimal? Yes

Time? Exponential, approximately O(bd) in the worst case

Space? O(bm) Keeps all nodes in memory

Page 23: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

The heuristic h(x) guides the performance of A*

Let d(x) be the actual distance between S and G h(x) = 0 :

A* is equivalent to Uniform-Cost Search h(x) <= d (x) :

guarantee to compute the shortest path; the lower the value h(x), the more node A* expands

h(x) = d (x) : follow the best path; never expand anything else;

difficult to compute h(x) in this way! h(x) > d(x) :

not guarantee to compute a best path; but very fast h(x) >> g(x) :

h(n) dominates -> A* becomes the best first search

Page 24: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Admissible heuristics

Page 25: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Admissible heuristics

E.g., for the 8-puzzle:

Page 26: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Admissible heuristics

E.g., for the 8-puzzle: h1(n) = number of misplaced tiles h2(n) = summed Manhattan distance for all tiles (i.e., no. of

squares from desired location of each tile)

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

Page 27: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

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 Which is better?

Page 28: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Dominance

If h2(n) ≥ h1(n) for all n (both admissible) then h2 dominates h1 h2 is better for search

What does better mean? All searches we’ve discussed are

exponential in time

Page 29: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Comparison of algorithms(number of nodes expanded)

D Iterative deepening

A*(teleporting tiles)

A* (manhattan distance)

2 10 6 6

6 112 13 12

10 680 20 18

12 364035 227 73

14 2896689 539 113

18 1.8 * 108 3056 363

24 8.6 * 1010 39135 1641

Page 30: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Visually

0

1 0 0

2 0 0

3 0 0

4 0 0

5 0 0

6 0 0

7 0 0

8 0 0

9 0 0

1 0 0 0

1 2 3 4 5 6 7 8 9 1 0

Number

of expe

cted exp

ansions

S e a r c h d e p t h

U n i n f o r m e d

H 1

H 2

Page 31: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Where do heuristics come from? From people

Knowledge of the problem

From computers By considering a simpler version of the

problem Called a relaxation

Page 32: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Relaxed problems

8-puzzle 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

Consider the example of straight line distance (Romania navigation) Is that a relaxation?

Page 33: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Iterative-Deepening A* (IDA*) Further reduce memory requirements of

A*

Regular Iterative-Deepening: regulated by depth

IDA*: regulated by f(n)=g(n)+h(n)

Page 34: Notes Dijstra s Algorithm Corrected syllabus. Tree Search Implementation Strategies Require data structure to model search tree Tree Node : State ( e

Questions?