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

breadth first search uniform cost search
SMART_READER_LITE
LIVE PREVIEW

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:


slide-1
SLIDE 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
slide-2
SLIDE 2

What is graph search?

Start state Goal state

slide-3
SLIDE 3

What is a graph?

Graph: Edges: Vertices: Directed graph

slide-4
SLIDE 4

What is a graph?

Graph: Edges: Vertices: Undirected graph

slide-5
SLIDE 5

Graph search

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

slide-6
SLIDE 6

A search tree

Start at A

slide-7
SLIDE 7

A search tree

Successors of A

slide-8
SLIDE 8

A search tree

Successors of A parent children

slide-9
SLIDE 9

A search tree

Let's expand S next

slide-10
SLIDE 10

A search tree

Successors

  • f S
slide-11
SLIDE 11

A search tree

A was already visited!

slide-12
SLIDE 12

A search tree

A was already visited!

So, prune it!

slide-13
SLIDE 13

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

slide-14
SLIDE 14

Breadth first search (BFS)

Slide: Adapted from Berkeley CS188 course notes (downloaded Summer 2015)

slide-15
SLIDE 15

Breadth first search (BFS)

slide-16
SLIDE 16

Breadth first search (BFS)

Start node

slide-17
SLIDE 17

Breadth first search (BFS)

slide-18
SLIDE 18

Breadth first search (BFS)

slide-19
SLIDE 19

Breadth first search (BFS)

slide-20
SLIDE 20

Breadth first search (BFS)

We're going to maintain a queue called the fringe – initialize the fringe as an empty queue Fringe

slide-21
SLIDE 21

Breadth first search (BFS)

– add A to the fringe fringe Fringe A

slide-22
SLIDE 22

Breadth first search (BFS)

  • - remove A from the fringe
  • - add successors of A to the fringe

fringe Fringe B C

slide-23
SLIDE 23

Breadth first search (BFS)

  • - remove B from the fringe
  • - add successors of B to the fringe

fringe Fringe C D E

slide-24
SLIDE 24

Breadth first search (BFS)

fringe Fringe D E F G

  • - remove C from the fringe
  • - add successors of C to the fringe
slide-25
SLIDE 25

Breadth first search (BFS)

fringe Fringe D E F G Which state gets removed next from the fringe?

slide-26
SLIDE 26

Breadth first search (BFS)

fringe Fringe D E F G Which state gets removed next from the fringe? What kind of a queue is this?

slide-27
SLIDE 27

Breadth first search (BFS)

fringe Fringe D E F G Which state gets removed next from the fringe? What kind of a queue is this?

FIFO Queue! (first in first out)

slide-28
SLIDE 28

Breadth first search (BFS)

slide-29
SLIDE 29

Breadth first search (BFS)

What is the purpose of the explored set?

slide-30
SLIDE 30

BFS Properties

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

slide-31
SLIDE 31

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 = ???

slide-32
SLIDE 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 =

slide-33
SLIDE 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 = What is the space complexity of BFS? – how much memory is required? – complexity = ???

slide-34
SLIDE 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 =

slide-35
SLIDE 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 = Is BFS optimal? – is it guaranteed to find the best solution (shortest path)?

slide-36
SLIDE 36

Another BFS example...

slide-37
SLIDE 37

Uniform Cost Search (UCS)

Slide: Adapted from Berkeley CS188 course notes (downloaded Summer 2015)

slide-38
SLIDE 38

Uniform Cost Search (UCS)

Notice the distances between cities

slide-39
SLIDE 39

Uniform Cost Search (UCS)

Notice the distances between cities – does BFS take these distances into account?

slide-40
SLIDE 40

Uniform Cost Search (UCS)

Notice the distances between cities – does BFS take these distances into account? – does BFS find the path w/ shortest milage?

slide-41
SLIDE 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? – compare S-F-B with S-R-P-B. Which costs less?

slide-42
SLIDE 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?

How do we fix this?

slide-43
SLIDE 43

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?

How do we fix this? UCS!

slide-44
SLIDE 44

Uniform Cost Search (UCS)

Same as BFS except: expand node w/ smallest path cost Length of path

slide-45
SLIDE 45

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:

slide-46
SLIDE 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: BFS: expands states in order of hops from start UCS: expands states in order of

slide-47
SLIDE 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

How?

slide-48
SLIDE 48

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.

slide-49
SLIDE 49

Uniform Cost Search (UCS)

slide-50
SLIDE 50

UCS

Fringe A Path Cost Explored set:

slide-51
SLIDE 51

UCS

140 118 75

Explored set: A Fringe A S T Z Path Cost 140 118 75

slide-52
SLIDE 52

UCS

140 118 75 146

Explored set: A, Z Fringe A S T Z T Path Cost 140 118 75 146

slide-53
SLIDE 53

UCS

140 118 75 146 229

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

slide-54
SLIDE 54

UCS

140 118 75 239 220 146 229

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

slide-55
SLIDE 55

UCS

140 118 75 239 220 146 229

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

slide-56
SLIDE 56

UCS

140 118 75 239 220 336 317 146 229

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

slide-57
SLIDE 57

UCS

140 118 75 239 220 336 317 146 229 299

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

slide-58
SLIDE 58

UCS

140 118 75 239 220 336 317 146 229 299

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

When does this end?

slide-59
SLIDE 59

UCS

140 118 75 239 220 336 317 146 229 299

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

When does this end? – when the goal state is removed from the queue

slide-60
SLIDE 60

UCS

140 118 75 239 220 336 317 146 229 299

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

When does this end? – when the goal state is removed from the queue – NOT when the goal state is expanded

slide-61
SLIDE 61

UCS

slide-62
SLIDE 62

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)?

slide-63
SLIDE 63

S

a b d p a c e p h f r q q c

G

a q e p h f r q q c

G

a Strategy: expand a cheapest node first: Fringe is a priority queue (priority: cumulative cost) S G

d b p q c e h a f r

3 9 1 16 4 11 5 7 13 8 10 11 17 11 6 3 9 1 1 2 8 8 2 15 1 2 Cost contours 2

UCS vs BFS

Slide: Adapted from Berkeley CS188 course notes (downloaded Summer 2015)

slide-64
SLIDE 64

UCS vs BFS

S

a b d p a c e p h f r q q c

G

a q e p h f r q q c

G

a

S

G d b p q c e h a f r Search Tiers Strategy: expand a shallowest node fjrst Implementation: Fringe is a FIFO queue Slide: Adapted from Berkeley CS188 course notes (downloaded Summer 2015)

slide-65
SLIDE 65

UCS vs BFS

Start Goal … c ≤ 3 c ≤ 2 c ≤ 1

  • Remember: UCS explores

increasing cost contours

  • The good: UCS is complete and
  • ptimal!
  • The bad:
  • Explores options in every

“direction”

  • No information about goal

location

  • We’ll fjx that soon!

Slide: Adapted from Berkeley CS188 course notes (downloaded Summer 2015)