• Keine Ergebnisse gefunden

10. State-Space Search: Breadth-first Search

N/A
N/A
Protected

Academic year: 2022

Aktie "10. State-Space Search: Breadth-first Search"

Copied!
8
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Foundations of Artificial Intelligence

10. State-Space Search: Breadth-first Search

Malte Helmert

University of Basel

March 17, 2021

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 1 / 32

Foundations of Artificial Intelligence

March 17, 2021 — 10. State-Space Search: Breadth-first Search

10.1 Blind Search

10.2 Breadth-first Search: Introduction 10.3 BFS-Tree

10.4 BFS-Graph

10.5 Properties of Breadth-first Search 10.6 Summary

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 2 / 32

State-Space Search: Overview

Chapter overview: state-space search I 5.–7. Foundations

I 8.–12. Basic Algorithms

I 8. Data Structures for Search Algorithms I 9. Tree Search and Graph Search I 10. Breadth-first Search

I 11. Uniform Cost Search

I 12. Depth-first Search and Iterative Deepening I 13.–19. Heuristic Algorithms

10. State-Space Search: Breadth-first Search Blind Search

10.1 Blind Search

(2)

10. State-Space Search: Breadth-first Search Blind Search

Blind Search

In Chapters 10–12 we consider blind search algorithms:

Blind Search Algorithms

Blind search algorithms use no information

about state spaces apart from the black box interface.

They are also called uninformed search algorithms.

contrast: heuristic search algorithms (Chapters 13–19)

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 5 / 32

10. State-Space Search: Breadth-first Search Blind Search

Blind Search Algorithms: Examples

examples of blind search algorithms:

I breadth-first search ( this chapter) I uniform cost search ( Chapter 11) I depth-first search ( Chapter 12) I depth-limited search ( Chapter 12) I iterative deepening search ( Chapter 12)

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 6 / 32

10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction

10.2 Breadth-first Search:

Introduction

10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction

Breadth-first Search

Breadth-first search expands nodes in order of generation (FIFO).

e.g., open list as linked list or deque

A

open: A

I searches state space layer by layer

I always finds shallowest goal state first

(3)

10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction

Breadth-first Search

Breadth-first search expands nodes in order of generation (FIFO).

e.g., open list as linked list or deque

A

B C

open: B, C

I searches state space layer by layer I always finds shallowest goal state first

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 9 / 32

10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction

Breadth-first Search

Breadth-first search expands nodes in order of generation (FIFO).

e.g., open list as linked list or deque

A

B

D E

C

open: C, D, E

I searches state space layer by layer I always finds shallowest goal state first

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 10 / 32

10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction

Breadth-first Search

Breadth-first search expands nodes in order of generation (FIFO).

e.g., open list as linked list or deque

A

B

D E

C

F G H

open: D, E, F, G, H

I searches state space layer by layer I always finds shallowest goal state first

10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction

Breadth-first Search

Breadth-first search expands nodes in order of generation (FIFO).

e.g., open list as linked list or deque

A

B

D

I J

E

C

F G H

open: E, F, G, H, I, J

I searches state space layer by layer

I always finds shallowest goal state first

(4)

10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction

Breadth-first Search

Breadth-first search expands nodes in order of generation (FIFO).

e.g., open list as linked list or deque

A

B

D

I J

E

C

F G H

I searches state space layer by layer I always finds shallowest goal state first

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 13 / 32

10. State-Space Search: Breadth-first Search Breadth-first Search: Introduction

Breadth-first Search: Tree Search or Graph Search?

Breadth-first search can be performed

I without duplicate elimination (as a tree search) BFS-Tree

I or with duplicate elimination (as a graph search) BFS-Graph

(BFS = breadth-first search).

We consider both variants.

German: Breitensuche

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 14 / 32

10. State-Space Search: Breadth-first Search BFS-Tree

10.3 BFS-Tree

10. State-Space Search: Breadth-first Search BFS-Tree

Reminder: Generic Tree Search Algorithm

reminder from Chapter 9:

Generic Tree Search open := new OpenList open.insert(make root node()) while not open.is empty():

n := open.pop() if is goal(n.state):

return extract path(n) for each ha, s

0

i ∈ succ(n.state):

n

0

:= make node(n, a, s

0

) open.insert(n

0

)

return unsolvable

(5)

10. State-Space Search: Breadth-first Search BFS-Tree

BFS-Tree (1st Attempt)

breadth-first search without duplicate elimination (1st attempt):

BFS-Tree (1st Attempt) open := new Deque

open.push back(make root node()) while not open.is empty():

n := open.pop front() if is goal(n.state):

return extract path(n) for each ha, s

0

i ∈ succ(n.state):

n

0

:= make node(n, a, s

0

) open.push back(n

0

) return unsolvable

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 17 / 32

10. State-Space Search: Breadth-first Search BFS-Tree

BFS-Tree (1st Attempt): Discussion

This is almost a usable algorithm, but it wastes some effort:

I In a breadth-first search, the first generated goal node is always the first expanded goal node. (Why?)

I Hence it is more efficient to already perform the goal test upon generating a node (rather than upon expanding it).

How much effort does this save?

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 18 / 32

10. State-Space Search: Breadth-first Search BFS-Tree

BFS-Tree (2nd Attempt)

breadth-first search without duplicate elimination (2nd attempt):

BFS-Tree (2nd Attempt) open := new Deque

open.push back(make root node()) while not open.is empty():

n := open.pop front() if is goal(n.state):

return extract path(n) for each ha, s

0

i ∈ succ(n.state):

n

0

:= make node(n, a, s

0

) if is goal(s

0

):

return extract path(n

0

) open.push back(n

0

)

return unsolvable

10. State-Space Search: Breadth-first Search BFS-Tree

BFS-Tree (2nd Attempt): Discussion

Where is the bug?

(6)

10. State-Space Search: Breadth-first Search BFS-Tree

BFS-Tree (Final Version)

breadth-first search without duplicate elimination (final version):

BFS-Tree if is goal(init()):

return hi open := new Deque

open.push back(make root node()) while not open.is empty():

n := open.pop front()

for each ha, s

0

i ∈ succ(n.state):

n

0

:= make node(n, a, s

0

) if is goal(s

0

):

return extract path(n

0

) open.push back(n

0

)

return unsolvable

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 21 / 32

10. State-Space Search: Breadth-first Search BFS-Graph

10.4 BFS-Graph

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 22 / 32

10. State-Space Search: Breadth-first Search BFS-Graph

Reminder: Generic Graph Search Algorithm

reminder from Chapter 9:

Generic Graph Search open := new OpenList open.insert(make root node()) closed := new ClosedList while not open.is empty():

n := open.pop()

if closed.lookup(n.state) = none:

closed.insert(n) if is goal(n.state):

return extract path(n) for each ha, s

0

i ∈ succ(n.state):

n

0

:= make node(n, a, s

0

) open.insert(n

0

)

return unsolvable

10. State-Space Search: Breadth-first Search BFS-Graph

Adapting Generic Graph Search to Breadth-First Search

Adapting the generic algorithm to breadth-first search:

I similar adaptations to BFS-Tree (deque as open list, early goal test)

I as closed list does not need to manage node information, a set data structure suffices

I for the same reasons why early goal tests are a good idea,

we should perform duplicate tests against the closed list

and updates of the closed lists as early as possible

(7)

10. State-Space Search: Breadth-first Search BFS-Graph

BFS-Graph (Breadth-First Search with Duplicate Elim.)

BFS-Graph if is goal(init()):

return hi open := new Deque

open.push back(make root node()) closed := new HashSet

closed.insert(init()) while not open.is empty():

n := open.pop front()

for each ha, s

0

i ∈ succ(n.state):

n

0

:= make node(n, a, s

0

) if is goal(s

0

):

return extract path(n

0

) if s

0

∈ / closed:

closed.insert(s

0

) open.push back(n

0

) return unsolvable

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 25 / 32

10. State-Space Search: Breadth-first Search Properties of Breadth-first Search

10.5 Properties of Breadth-first Search

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 26 / 32

10. State-Space Search: Breadth-first Search Properties of Breadth-first Search

Properties of Breadth-first Search

Properties of Breadth-first Search:

I BFS-Tree is semi-complete, but not complete. (Why?) I BFS-Graph is complete. (Why?)

I BFS (both variants) is optimal

if all actions have the same cost (Why?), but not in general (Why not?).

I complexity: next slides

10. State-Space Search: Breadth-first Search Properties of Breadth-first Search

Breadth-first Search: Complexity

The following result applies to both BFS variants:

Theorem (time complexity of breadth-first search) Let b be the branching factor and d be the minimal solution length of the given state space. Let b ≥ 2.

Then the time complexity of breadth-first search is

1 + b + b 2 + b 3 + · · · + b d = O (b d )

Reminder: we measure time complexity in generated nodes.

It follows that the space complexity of both BFS variants

also is O(b d ) (if b ≥ 2). (Why?)

(8)

10. State-Space Search: Breadth-first Search Properties of Breadth-first Search

Breadth-first Search: Example of Complexity

example: b = 10; 100 000 nodes/second; 32 bytes/node

d nodes time memory

3 1 111 0.01 s 35 KiB

5 111 111 1 s 3.4 MiB

7 10

7

2 min 339 MiB

9 10

9

3 h 33 GiB

11 10

11

13 days 3.2 TiB 13 10

13

3.5 years 323 TiB 15 10

15

350 years 32 PiB

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 29 / 32

10. State-Space Search: Breadth-first Search Properties of Breadth-first Search

BFS-Tree or BFS-Graph?

What is better, BFS-Tree or BFS-Graph?

advantages of BFS-Graph:

I complete

I much (!) more efficient if there are many duplicates advantages of BFS-Tree:

I simpler

I less overhead (time/space) if there are few duplicates

Conclusion

BFS-Graph is usually preferable, unless we know that there is a negligible number of duplicates in the given state space.

M. Helmert (University of Basel) Foundations of Artificial Intelligence March 17, 2021 30 / 32

10. State-Space Search: Breadth-first Search Summary

10.6 Summary

10. State-Space Search: Breadth-first Search Summary

Summary

I blind search algorithm: use no information except black box interface of state space

I breadth-first search: expand nodes in order of generation I search state space layer by layer

I can be tree search or graph search

I complexity O(b

d

) with branching factor b, minimal solution length d (if b ≥ 2)

I complete as a graph search; semi-complete as a tree search

I optimal with uniform action costs

Referenzen

ÄHNLICHE DOKUMENTE

recognize duplicates: when a state is reached on multiple paths, only keep one search node search nodes correspond 1:1 to reachable states search tree bounded, as number of states

I recognize duplicates: when a state is reached on multiple paths, only keep one search node I search nodes correspond 1:1 to reachable states I search tree bounded, as number of

breadth-first search ( this chapter) uniform cost search ( Chapter 11) depth-first search ( Chapter 12) depth-limited search ( Chapter 12) iterative deepening search ( Chapter

breadth-first search optimal if all action costs equal otherwise no optimality guarantee example:.. remedy: uniform

uniform cost search: expand nodes in order of ascending path costs. I usually as a

space complexity O(bm) if m maximal search depth reached low memory complexity main reason why depth-first search interesting despite its disadvantages.. Depth-first

Theorem (time complextive of iterative deepening DFS) Let b be the branching factor and d be the minimal solution length of the given state space. State-Space Search: Depth-first

I In IDDFS, we grow the limit from the smallest limit that gives a non-empty search tree (0) by 1 at a time. I This usually leads to exponential growth of