Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

25
Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002
  • date post

    21-Dec-2015
  • Category

    Documents

  • view

    222
  • download

    3

Transcript of Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

Page 1: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

Introduction to Artificial Intelligence

Blind Search

Ruth Bergman

Fall 2002

Page 2: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

Searching for Solutions

• Partial search tree for route finding from Arad to Bucharest.

Arad(a) The initial state (search node)

(b) After expanding Arad

(c) After expanding Sibiu

Arad

Sibiu Timisoara Zerind

Arad

Sibiu Timisoara Zerind

Arad Fagaras OradeaRimnicu Vilcea

goal test

choosing one option

• Which node to expand?• Which nodes to store in memory?

Page 3: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

Depth-first Search

Searching Strategies

• Expand deepest node first.• DFS (state path)

if goalp(state) return pathelse for c in succ(state)

return DFS(c, path | state)

Page 4: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

DFS implementation in Lisp

(defun dfs (state) (cond

((goalp state) (list state))(t (do* ((children (new-states state) (cdr children))) (solution (dfs (car children)) (dfs (car children))) ((or solution (null children))

(if solution (cons state solution) nil))))))

Page 5: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

• Criteria– Completeness: if there is a solution will

the algorithm find it?– Time complexity: how much time does the

algorithm take to arrive at a solution, if one exists?

– Space complexity: how much space does the algorithm require?

– Optimality: is the solution optimal?

Search Strategies

Page 6: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

In-Completeness of DFS

• DFS is not complete– fails in infinite-depth spaces, spaces with

loops

• Variants– limit depth of search– avoid re-visiting nodes.– avoid repeated states along path

=> complete in finite spaces

Page 7: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

DFS with depth limit

(defun dfs-d (state depth) (cond

((goalp state) (list state)) ((zerop depth) nil)

(t (do* ((children (new-states state) (cdr children))) (solution (dfs (car children) (1- depth)) (dfs (car children) (1- depth))) ((or solution (null children))

(if solution (cons state solution) nil))))))

Page 8: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

• Properties – Complete: No

• Guaranteed to stop• Complete only if exists solution at level L<d (where d is the

maximum depth)

– Time complexity: O(b^d) • Best case L• Worst case (b^(d+1)-1)/(b-1)

Where b is the branching factor

• improved performance when there are many solutions

– Space complexity: O(bd) • i.e., linear space

– Optimal: No

DFS with depth limit Performance

Searching Strategies

Page 9: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

DFS with no revisits

• avoid nodes that have already been expanded.=> exponential space complexity.

– Not practical.

Page 10: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

DFS with no repeated states

(defun dfs-d-g (state depth path) (cond

((goalp state) (list state)) ((zerop depth) nil)

(t (do* ((children (new-states state) (cdr children))) (solution (if (member (car children) path)

nil (dfs (car children) (1- depth) (cons state path))

…)) ((or solution (null children))

(if solution (cons state solution) nil))))))

1

87

6

54

3

2

=> Complete in finite spaces

Page 11: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

Backtracking Search

Searching Strategies

• When states are expanded by applying operators• The algorithm expands one child at a time (by applying one operator)• If search fails, backtrack and expand other children• Backtracking search results in even lower memory requirements than DFS

1

9

13

1187

6

54

3

2

10

151412

1

3

11

1298

5

76

4

2

10

151413

DFS node discovery

Backtracking searchnode discovery

Page 12: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

• Advantages – Low space complexity – Good chance of success when there are many solutions.– Complete if there is a solution shorter than the depth limit.

• Disadvantages– Without the depth limit search may continue down an infinite

branch.– Solutions longer than the depth limit will not be found.– The solution found may not be the shortest solution.

DFS Summary

Searching Strategies

Page 13: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

Breadth-first Search

Searching Strategies

• Expand node with minimal depth.• avoid revisting nodes. Since every node is in memory, the

additional cost is negligible.

Page 14: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

BFS implementation in Lisp

(defun bfs (state) (let ((queue (list (list state nil)))) (do* ((state (caar queue) …)

(children (new-states state) …))((or (null queue) (goalp state)) (if (null queue) nil (car state))(setq queue (append

(cdr queue) (mapcar

#'(lambda (state) (cons state (car queue))) children)))))))

1

3

7

121110

5

98

4

2

6

151413

Page 15: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

BFS Performance

Searching Strategies

• Properties– Complete: Yes (if b is finite)– Time complexity: 1+b+b^2+…+b^l = O(b^l)– Space complexity: O(b^l) (keeps every node in

memory) – Optimal: Yes (if cost=1 per step); not optimal in

general• where b is branching factor and • l is the depth of the shortest solution

Page 16: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

Uniform cost Search

A

GS

C

551 10

15 5

B

S SS S

AA A

BB B

CC C

G G G

0

1 5 1511

155

11 10

15

• Expand least-cost unexpanded node– the breadth-first search is just uniform cost search

with g(n)=DEPTH(n)

Searching Strategies

Page 17: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

Uniform cost Search

• Properties of Depth-first Search– Complete: Yes, if step cost >= e (epsilon)– Time complexity: # of nodes with g <= cost

of optimal solution, O(b^l)– Space complexity: # of nodes with g <=

cost of optimal solution, O(b^l)– Optimal: Yes, if step cost >= e (epsilon)

Searching Strategies

Page 18: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

• Combine the best of both worlds– Depth first search has linear memory requirements– Breadth first search gives an optimal solution.

• Iterative Deepening Search executes depth first search with depth limit 1, then 2, 3, etc. until a solution is found.

• The algorithm has no memory between searches.

Iterative Deepening Search

Searching Strategies

Page 19: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

• Limit=0

• Limit=1

• Limit=2

• Limit=3

Iterative Deepening Search

Searching Strategies

Page 20: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

• Properties– Complete: Yes– Time complexity: (l+1)*b^0+l*b+(l-

1)*b^2+…+1*b^l = O(b^l) – Space complexity: O(bl)– Optimal: Yes, if step cost = 1

• Can be modified to explore uniform-cost tree

Iterative Deepening Search

Searching Strategies

Page 21: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

• Numerical demonstration:Let b=10, l=5.– BFS resource use (memory and # nodes

expanded)1+10+100+1000+10000+100000 = 111,111

– Iterative Deepening resource use• Memory requirement: 10*5 = 50• # expanded nodes6+50+400+3000+20000+100000 = 123,456

=> re-searching cost is small compared with the cost of expanding the leaves

Iterative Deepening Search - Discussion

Searching Strategies

Page 22: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

• Simultaneously search both forward from the initial state and backward from the goal, and stop when the two searches meet in the middle.

Bidirectional Search

Start Goal

Searching Strategies

Page 23: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

• Properties– Complete: Yes (using a complete search

procedure for each half)– Time complexity: O(b^(l/2))– Space complexity: O(b^(l/2))– Optimal: Yes, if step cost = 1

• Can be modified to explore uniform-cost tree

Bidirectional Search Performance

Searching Strategies

Page 24: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

Bidirectional Search Discussion

• Numerical Example (b=10, l = 5)– Bi-directional search finds solution at d=3 for both

forward and backward search. Assuming BFS in each half 2222 nodes are expanded.

• Implementation issues:– Operators are reversible.– There may be many possible goal states.– Check if a node appears in the “other” search tree.– What’s the best search strategy in each half.

Page 25: Introduction to Artificial Intelligence Blind Search Ruth Bergman Fall 2002.

– b is the branching factor;– l is the depth of solution;– m is the maximum depth of the search tree;– d is the depth limit.

Comparison Search Strategies

CriterionBreadth-

FirstUniform-

CostDepth-First

Depth-Limited

Iterative Deepenin

g

Bidirectional (if

applicable)

Time b^l b^l b^m b^d b^l b^(l/2)

Space b^l b^l bm bd bl b^(l/2)

Optimal? Yes Yes No No Yes Yes

Complete?

Yes Yes NoYes, if d>=l

Yes Yes

Searching Strategies