breadth first search uniform cost search
play

Breadth first search Uniform cost search Robert Platt Northeastern - PowerPoint PPT Presentation

Breadth first search Uniform cost search Robert Platt Northeastern University Some images and slides are used from: 1. CS188 UC Berkeley 2. RN, AIMA What is graph search? Goal state Start state What is a graph? Graph: Vertices: Edges:


  1. Breadth first search Uniform cost search Robert Platt Northeastern University Some images and slides are used from: 1. CS188 UC Berkeley 2. RN, AIMA

  2. What is graph search? Goal state Start state

  3. What is a graph? Graph: Vertices: Edges: Directed graph

  4. What is a graph? Graph: Vertices: Edges: Undirected graph

  5. Graph search Given: a graph, G Problem: find a path from A to B – A: start state – B: goal state

  6. Graph search How? Given: a graph, G Problem: find a path from A to B – A: start state – B: goal state

  7. A search tree Start at A

  8. A search tree Successors of A

  9. A search tree Successors of A parent children

  10. A search tree Let's expand S next

  11. A search tree Successors of S

  12. A search tree A was already visited!

  13. A search tree A was already So, prune it! visited!

  14. A search tree In what order should we expand states? – here, we expanded S , but we could also have expanded Z or T – different search algorithms expand in different orders

  15. Breadth first search (BFS) Slide: Adapted from Berkeley CS188 course notes (downloaded Summer 2015)

  16. Breadth first search (BFS)

  17. Breadth first search (BFS) Start node

  18. Breadth first search (BFS)

  19. Breadth first search (BFS)

  20. Breadth first search (BFS)

  21. Breadth first search (BFS) We're going to maintain a queue called the fringe Fringe – initialize the fringe as an empty queue

  22. Breadth first search (BFS) fringe Fringe A – add A to the fringe

  23. Breadth first search (BFS) Fringe B C fringe -- remove A from the fringe -- add successors of A to the fringe

  24. Breadth first search (BFS) Fringe C D E fringe -- remove B from the fringe -- add successors of B to the fringe

  25. Breadth first search (BFS) Fringe D E F G fringe -- remove C from the fringe -- add successors of C to the fringe

  26. Breadth first search (BFS) Fringe D E F G fringe Which state gets removed next from the fringe?

  27. Breadth first search (BFS) Fringe D E F G fringe Which state gets removed next from the fringe? What kind of a queue is this?

  28. Breadth first search (BFS) Fringe D E F G fringe Which state gets removed next from the fringe? What kind of a queue is this? FIFO Queue! (first in first out)

  29. Breadth first search (BFS)

  30. Breadth first search (BFS) What is the purpose of the explored set?

  31. BFS Properties Is BFS complete? – is it guaranteed to find a solution if one exists?

  32. BFS Properties Is BFS complete? – is it guaranteed to find a solution if one exists? What is the time complexity of BFS? – how many states are expanded before finding a sol'n? – b: branching factor – d: depth of shallowest solution – complexity = ???

  33. BFS Properties Is BFS complete? – is it guaranteed to find a solution if one exists? What is the time complexity of BFS? – how many states are expanded before finding a sol'n? – b: branching factor – d: depth of shallowest solution – complexity =

  34. BFS Properties Is BFS complete? – is it guaranteed to find a solution if one exists? What is the time complexity of BFS? – how many states are expanded before finding a sol'n? – b: branching factor – d: depth of shallowest solution – complexity = What is the space complexity of BFS? – how much memory is required? – complexity = ???

  35. BFS Properties Is BFS complete? – is it guaranteed to find a solution if one exists? What is the time complexity of BFS? – how many states are expanded before finding a sol'n? – b: branching factor – d: depth of shallowest solution – complexity = What is the space complexity of BFS? – how much memory is required? – complexity =

  36. BFS Properties Is BFS complete? – is it guaranteed to find a solution if one exists? What is the time complexity of BFS? – how many states are expanded before finding a sol'n? – b: branching factor – d: depth of shallowest solution – complexity = What is the space complexity of BFS? – how much memory is required? – complexity = Is BFS optimal? – is it guaranteed to find the best solution (shortest path)?

  37. Another BFS example...

  38. Uniform Cost Search (UCS) Slide: Adapted from Berkeley CS188 course notes (downloaded Summer 2015)

  39. Uniform Cost Search (UCS) Notice the distances between cities

  40. Uniform Cost Search (UCS) Notice the distances between cities – does BFS take these distances into account?

  41. Uniform Cost Search (UCS) Notice the distances between cities – does BFS take these distances into account? – does BFS find the path w/ shortest milage?

  42. Uniform Cost Search (UCS) Notice the distances between cities – does BFS take these distances into account? – does BFS find the path w/ shortest milage? – compare S-F-B with S-R-P-B. Which costs less?

  43. Uniform Cost Search (UCS) Notice the distances between cities How do we fix this? – does BFS take these distances into account? – does BFS find the path w/ shortest milage? – compare S-F-B with S-R-P-B. Which costs less?

  44. Uniform Cost Search (UCS) Notice the distances between cities How do we fix this? – does BFS take these distances into account? UCS! – does BFS find the path w/ shortest milage? – compare S-F-B with S-R-P-B. Which costs less?

  45. Uniform Cost Search (UCS) Same as BFS except: expand node w/ smallest path cost Length of path

  46. Uniform Cost Search (UCS) Same as BFS except: expand node w/ smallest path cost Length of path Cost of going from state A to B: Minimum cost of path going from start state to B:

  47. Uniform Cost Search (UCS) Same as BFS except: expand node w/ smallest path cost Length of path Cost of going from state A to B: Minimum cost of path going from start state to B: BFS: expands states in order of hops from start UCS: expands states in order of

  48. Uniform Cost Search (UCS) Same as BFS except: expand node w/ smallest path cost Length of path Cost of going from state A to B: Minimum cost of path going from start state to B: BFS: expands states in order of hops from start How? UCS: expands states in order of

  49. Uniform Cost Search (UCS) Simple answer: change the FIFO to a priority queue – the priority of each element in the queue is its path cost.

  50. Uniform Cost Search (UCS)

  51. UCS Fringe Path Cost A 0 Explored set:

  52. UCS Fringe Path Cost 75 A 0 140 118 S 140 T 118 Z 75 Explored set: A

  53. UCS Fringe Path Cost 75 A 0 140 118 S 140 T 118 Z 75 T 146 146 Explored set: A, Z

  54. UCS Fringe Path Cost 75 A 0 140 118 S 140 T 118 Z 75 T 146 L 229 229 146 Explored set: A, Z, T

  55. UCS Fringe Path Cost 75 A 0 140 118 S 140 T 118 Z 75 T 146 239 220 L 229 229 146 F 239 R 220 Explored set: A, Z, T, S

  56. UCS Fringe Path Cost 75 A 0 140 118 S 140 T 118 Z 75 T 146 239 220 L 229 229 146 F 239 R 220 Explored set: A, Z, T, S

  57. UCS Fringe Path Cost 75 A 0 140 118 S 140 T 118 Z 75 T 146 239 220 L 229 229 146 F 239 R 220 C 336 P 317 336 317 Explored set: A, Z, T, S, R

  58. UCS Fringe Path Cost 75 A 0 140 118 S 140 T 118 Z 75 T 146 239 220 L 229 229 146 F 239 R 220 C 336 P 317 M 299 299 336 317 Explored set: A, Z, T, S, R, L

  59. UCS Fringe Path Cost 75 A 0 140 118 S 140 T 118 Z 75 T 146 239 220 L 229 When does this end? 229 146 F 239 R 220 C 336 P 317 M 299 299 336 317 Explored set: A, Z, T, S, R, L

  60. UCS Fringe Path Cost 75 A 0 140 118 S 140 T 118 Z 75 T 146 When does this end? 239 220 L 229 229 146 – when the goal state is removed from the queue F 239 R 220 C 336 P 317 M 299 299 336 317 Explored set: A, Z, T, S, R, L

  61. UCS Fringe Path Cost 75 A 0 140 118 S 140 T 118 Z 75 T 146 When does this end? 239 220 L 229 229 146 – when the goal state is removed from the queue F 239 R – NOT when the goal state is expanded 220 C 336 P 317 M 299 299 336 317 Explored set: A, Z, T, S, R, L

  62. UCS

  63. UCS Properties Is UCS complete? – is it guaranteed to find a solution if one exists? What is the time complexity of UCS? – how many states are expanded before finding a sol'n? – b: branching factor – C*: cost of optimal sol'n – e: min one-step cost – complexity = What is the space complexity of BFS? – how much memory is required? – complexity = Is BFS optimal? – is it guaranteed to find the best solution (shortest path)?

  64. UCS vs BFS 2 G a Strategy: expand a c b 8 1 cheapest node first: 2 2 e 3 d f Fringe is a priority queue 9 2 8 S h 1 (priority: cumulative cost) 1 p r q 15 0 S 1 9 e p 3 d q 16 11 5 17 4 e h r b c 11 Cost 7 6 13 h r p q f a a contours q c 8 p q f G a q c 11 10 G a Slide: Adapted from Berkeley CS188 course notes (downloaded Summer 2015)

Recommend


More recommend