• Keine Ergebnisse gefunden

12. State-Space Search: Depth-first Search & Iterative Deepening

N/A
N/A
Protected

Academic year: 2022

Aktie "12. State-Space Search: Depth-first Search & Iterative Deepening"

Copied!
9
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Foundations of Artificial Intelligence

12. State-Space Search: Depth-first Search & Iterative Deepening

Malte Helmert

University of Basel

March 22, 2021

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

Foundations of Artificial Intelligence

March 22, 2021 — 12. State-Space Search: Depth-first Search & Iterative Deepening

12.1 Depth-first Search 12.2 Iterative Deepening 12.3 Summary

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

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

12. State-Space Search: Depth-first Search & Iterative Deepening Depth-first Search

12.1 Depth-first Search

(2)

Depth-first Search

Depth-first search (DFS) expands nodes in opposite order of generation (LIFO).

deepest node expanded first open list implemented as stack German: Tiefensuche

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

Depth-first Search: Example

A

open: A

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

12. State-Space Search: Depth-first Search & Iterative Deepening Depth-first Search

Depth-first Search: Example

A

B C

open: C, B

12. State-Space Search: Depth-first Search & Iterative Deepening Depth-first Search

Depth-first Search: Example

A

B

D E

C

open: C, E, D

(3)

Depth-first Search: Example

A

B

D

I J

E

C

open: C, E, J, I

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

Depth-first Search: Example

A

B

D

I J

E

C

open: C, E, J

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

12. State-Space Search: Depth-first Search & Iterative Deepening Depth-first Search

Depth-first Search: Example

A

B

D

I J

E

C

open: C, E

12. State-Space Search: Depth-first Search & Iterative Deepening Depth-first Search

Depth-first Search: Example

A

B

D

I J

E

C

open: C

(4)

Depth-first Search: Example

A

B

D

I J

E

C

F G H

open: H, G, F

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

Depth-first Search: Example

A

B

D

I J

E

C

F G H

solution found!

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

12. State-Space Search: Depth-first Search & Iterative Deepening Depth-first Search

Depth-first Search: Some Properties

I almost always implemented as a tree search (we will see why) I not complete, not semi-complete, not optimal (Why?)

I complete for acyclic state spaces, e.g., if state space directed tree

12. State-Space Search: Depth-first Search & Iterative Deepening Depth-first Search

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)

Depth-first Search (Non-recursive Version)

depth-first search (non-recursive version):

Depth-first Search (Non-recursive Version) open := new Stack

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

n := open.pop back() 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 22, 2021 17 / 35

Non-recursive Depth-first Search: Discussion

discussion:

I there isn’t much wrong with this pseudo-code

(as long as we ensure to release nodes that are no longer required when using programming languages without garbage collection)

I however, depth-first search as a recursive algorithm is simpler and more efficient

CPU stack as implicit open list no search node data structure needed

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

12. State-Space Search: Depth-first Search & Iterative Deepening Depth-first Search

Depth-first Search (Recursive Version)

function depth first search(s ) if is goal(s):

return hi

for each ha, s

0

i ∈ succ(s):

solution := depth first search(s

0

) if solution 6= none:

solution.push front(a) return solution return none

main function:

Depth-first Search (Recursive Version) return depth first search(init())

12. State-Space Search: Depth-first Search & Iterative Deepening Depth-first Search

Depth-first Search: Complexity

time complexity:

I If the state space includes paths of length m, depth-first search can generate O(b m ) nodes,

even if much shorter solutions (e.g., of length 1) exist.

I On the other hand: in the best case, solutions of length ` can be found with O(b`) generated nodes. (Why?) I improvable to O(`) with incremental successor generation space complexity:

I only need to store nodes along currently explored path (“along”: nodes on path and their children)

space complexity O(bm) if m maximal search depth reached

I low memory complexity main reason why depth-first search

(6)

12. State-Space Search: Depth-first Search & Iterative Deepening Iterative Deepening

12.2 Iterative Deepening

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

12. State-Space Search: Depth-first Search & Iterative Deepening Iterative Deepening

Depth-limited Search

depth-limited search:

I depth-first search which prunes (does not expand) all nodes at a given depth d

not very useful on its own, but important ingredient of more useful algorithms

German: tiefenbeschr¨ ankte Suche

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

12. State-Space Search: Depth-first Search & Iterative Deepening Iterative Deepening

Depth-limited Search: Pseudo-Code

function depth limited search(s, depth limit):

if is goal(s):

return hi if depth limit > 0:

for each ha, s

0

i ∈ succ(s):

solution := depth limited search(s

0

, depth limit − 1) if solution 6= none:

solution.push front(a) return solution return none

12. State-Space Search: Depth-first Search & Iterative Deepening Iterative Deepening

Iterative Deepening Depth-first Search

iterative deepening depth-first search (iterative deepening DFS):

I idea: perform a sequence of depth-limited searches with increasing depth limit

I sounds wasteful (each iteration repeats all the useful work of all previous iterations)

I in fact overhead acceptable ( analysis follows)

Iterative Deepening DFS for depth limit ∈ {0, 1, 2, . . . }:

solution := depth limited search(init(), depth limit) if solution 6= none:

return solution

German: iterative Tiefensuche

(7)

Iterative Deepening DFS: Properties

combines advantages of breadth-first and depth-first search:

I (almost) like BFS: semi-complete (however, not complete) I like BFS: optimal if all actions have same cost

I like DFS: only need to store nodes along one path

space complexity O(bd ), where d minimal solution length I time complexity only slightly higher than BFS

( analysis soon)

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

Iterative Deepening DFS: Example

depth limit: 0

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

12. State-Space Search: Depth-first Search & Iterative Deepening Iterative Deepening

Iterative Deepening DFS: Example

depth limit: 1

generated in this round: 3 total generated: 1 + 3

12. State-Space Search: Depth-first Search & Iterative Deepening Iterative Deepening

Iterative Deepening DFS: Example

depth limit: 2

generated in this round: 7

total generated: 1 + 3 + 7

(8)

Iterative Deepening DFS: Example

depth limit: 3

generated in this round: 12 total generated: 1 + 3 + 7 + 12

solution found!

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

Iterative Deepening DFS: Complexity Example

time complexity (generated nodes):

breadth-first search 1 + b + b

2

+ · · · + b

d−1

+ b

d

iterative deepening DFS (d + 1) + db + (d − 1)b

2

+ · · · + 2b

d−1

+ 1b

d

example: b = 10, d = 5

breadth-first search 1 + 10 + 100 + 1000 + 10000 + 100000

= 111111

iterative deepening DFS 6 + 50 + 400 + 3000 + 20000 + 100000

= 123456

for b = 10, only 11% more nodes than breadth-first search

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

12. State-Space Search: Depth-first Search & Iterative Deepening Iterative Deepening

Iterative Deepening DFS: Time Complexity

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. Let b ≥ 2.

Then the time complexity of iterative deepening DFS is

(d + 1) + db + (d − 1)b 2 + (d − 2)b 3 + · · · + 1b d = O(b d ) and the memory complexity is

O(bd).

12. State-Space Search: Depth-first Search & Iterative Deepening Iterative Deepening

Iterative Deepening DFS: Evaluation

Iterative Deepening DFS: Evaluation

Iterative Deepening DFS is often the method of choice if

I tree search is adequate (no duplicate elimination necessary), I all action costs are identical, and

I the solution depth is unknown.

(9)

12.3 Summary

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

Summary

depth-first search: expand nodes in LIFO order I usually as a tree search

I easy to implement recursively I very memory-efficient

I can be combined with iterative deepening to combine many of the good aspects of breadth-first and depth-first search

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

12. State-Space Search: Depth-first Search & Iterative Deepening Summary

Comparison of Blind Search Algorithms

completeness, optimality, time and space complexity

search algorithm

criterion breadth- uniform depth- depth- iterative

first cost first limited deepening

complete? yes

*

yes no no semi

optimal? yes

**

yes no no yes

**

time O(b

d

) O(b

bc/εc+1

) O(b

m

) O(b

`

) O(b

d

) space O(b

d

) O(b

bc/εc+1

) O(bm) O(b`) O(bd )

b ≥ 2 branching factor d minimal solution depth m maximal search depth

` depth limit

c

optimal solution cost

remarks:

*

for BFS-Tree: semi-complete

**

only with uniform action costs

Referenzen

ÄHNLICHE DOKUMENTE

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

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 (

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

Helmert (University of Basel) Foundations of Artificial Intelligence March 24, 2021 2 / 16.. State-Space

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

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