search algorithm

41

Upload: jerzy

Post on 22-Feb-2016

29 views

Category:

Documents


0 download

DESCRIPTION

Search Algorithm. If GOAL?(initial-state) then return initial-state INSERT( initial-node,FRINGE) Repeat: If FRINGE is empty then return failure n  REMOVE(FRINGE) s  STATE( n ) For every state s’ in SUCCESSORS( s ) Create a node n’ If GOAL?( s’ ) then return path or goal state - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Search Algorithm
Page 2: Search Algorithm

Search Algorithm1. If GOAL?(initial-state) then return initial-state2. INSERT(initial-node,FRINGE)3. Repeat:

If FRINGE is empty then return failuren REMOVE(FRINGE)s STATE(n)For every state s’ in SUCCESSORS(s) Create a node n’ If GOAL?(s’) then return path or goal state INSERT(n’,FRINGE)

Page 3: Search Algorithm

Search Strategies• A strategy is defined by picking the order of node expansion• Performance Measures:

– Completeness – does it always find a solution if one exists?– Time complexity – number of nodes generated/expanded– Space complexity – maximum number of nodes in memory– Optimality – does it always find a least-cost solution

• Time and space complexity are measured in terms of– b – maximum branching factor of the search tree– d – depth of the least-cost solution– m – maximum depth of the state space (may be ∞)

Page 4: Search Algorithm

Search Strategies

• Blind Search• Heuristic Search

Page 5: Search Algorithm

Remark

• Some problems formulated as search problems are NP-hard (non-deterministic polynomial-time hard) problems. We cannot expect to solve such a problem in less than exponential time in the worst-case

• But we can nevertheless strive to solve as many instances of the problem as possible

Page 6: Search Algorithm

Blind vs. Heuristic Strategies

• Blind (or uninformed) strategies do not exploit any of the information contained in a state (or use only the information available in the problem definition)

• Heuristic (or informed) strategies exploits such information to assess that one node is “more promising” than another

Page 7: Search Algorithm

Blind Strategies

• Breadth-first– Bidirectional

• Depth-first– Depth-limited – Iterative deepening

• Uniform-Cost

Step cost = 1

Step cost = c(action) > 0

Page 8: Search Algorithm

Breadth-First Strategy

New nodes are inserted at the end of FRINGE

2 3

4 5

1

6 7

FRINGE = (1)

Page 9: Search Algorithm

Breadth-First Strategy

New nodes are inserted at the end of FRINGE

FRINGE = (2, 3)2 3

4 5

1

6 7

Page 10: Search Algorithm

Breadth-First Strategy

New nodes are inserted at the end of FRINGE

FRINGE = (3, 4, 5)2 3

4 5

1

6 7

Page 11: Search Algorithm

Breadth-First Strategy

New nodes are inserted at the end of FRINGE

FRINGE = (4, 5, 6, 7)2 3

4 5

1

6 7

Page 12: Search Algorithm

Evaluation

• b: branching factor• d: depth of shallowest goal node • Complete• Optimal if step cost is 1• Number of nodes generated:

1 + b + b2 + … + bd + b(bd-1) = O(bd+1) • Time and space complexity is O(bd+1)

Page 13: Search Algorithm

Time and Memory Requirements

d #Nodes Time Memory2 111 .01 msec 11 Kbytes4 11,111 1 msec 1 Mbyte6 ~106 1 sec 100 Mb8 ~108 100 sec 10 Gbytes10 ~1010 2.8 hours 1 Tbyte12 ~1012 11.6 days 100 Tbytes14 ~1014 3.2 years 10,000 Tb

Assumptions: b = 10; 1,000,000 nodes/sec; 100bytes/node

Page 14: Search Algorithm

Bidirectional Strategy

2 fringe queues: FRINGE1 and FRINGE2

Time and space complexity = O(bd/2) << O(bd)

Page 15: Search Algorithm

Depth-First Strategy

New nodes are inserted at the front of FRINGE

1

2 3

4 5FRINGE = (1)

Page 16: Search Algorithm

Depth-First Strategy

New nodes are inserted at the front of FRINGE

1

2 3

4 5FRINGE = (2, 3)

Page 17: Search Algorithm

Depth-First Strategy New nodes are inserted at the front of FRINGE

1

2 3

4 5FRINGE = (4, 5, 3)

Page 18: Search Algorithm

Depth-First Strategy

New nodes are inserted at the front of FRINGE

1

2 3

4 5

Page 19: Search Algorithm

Depth-First Strategy

New nodes are inserted at the front of FRINGE

1

2 3

4 5

Page 20: Search Algorithm

Depth-First Strategy

New nodes are inserted at the front of FRINGE

1

2 3

4 5

Page 21: Search Algorithm

Depth-First Strategy New nodes are inserted at the front of FRINGE

1

2 3

4 5

Page 22: Search Algorithm

Depth-First Strategy

New nodes are inserted at the front of FRINGE

1

2 3

4 5

Page 23: Search Algorithm

Depth-First Strategy

New nodes are inserted at the front of FRINGE

1

2 3

4 5

Page 24: Search Algorithm

Depth-First Strategy

New nodes are inserted at the front of FRINGE

1

2 3

4 5

Page 25: Search Algorithm

Depth-First Strategy

New nodes are inserted at the front of FRINGE

1

2 3

4 5

Page 26: Search Algorithm

Evaluation

• b: branching factor• d: depth of shallowest goal node • m: maximal depth of a leaf node• Complete only for finite search tree• Not optimal• Number of nodes generated:

1 + b + b2 + … + bm = O(bm) • Time complexity is O(bm) • Space complexity is O(bm)

Page 27: Search Algorithm

Depth-Limited Strategy

• Depth-first with depth cutoff k (maximal depth below which nodes are not expanded)

• Three possible outcomes:– Solution– Failure (no solution)– Cutoff (no solution within cutoff)

Page 28: Search Algorithm

Iterative Deepening Strategy

Repeat for k = 0, 1, 2, …:Perform depth-first with depth cutoff k

• Complete• Optimal if step cost =1• Time complexity is:

(d+1)(1) + db + (d-1)b2 + … + (1) bd = O(bd)• Space complexity is: O(bd)

Page 29: Search Algorithm

CS 3243 - Blind Search 2914 Jan 2004

Iterative deepening search

Page 30: Search Algorithm

CS 3243 - Blind Search 3014 Jan 2004

Iterative deepening search l =0

Page 31: Search Algorithm

CS 3243 - Blind Search 3114 Jan 2004

Iterative deepening search l =1

Page 32: Search Algorithm

CS 3243 - Blind Search 3214 Jan 2004

Iterative deepening search l =2

Page 33: Search Algorithm

CS 3243 - Blind Search 3314 Jan 2004

Iterative deepening search l =3

Page 34: Search Algorithm

Comparison of Strategies

• Breadth-first is complete and optimal, but has high space complexity

• Depth-first is space efficient, but neither complete nor optimal

• Iterative deepening is asymptotically optimal

Page 35: Search Algorithm

Repeated States

8-queens

No

assembly planning

Few

1 2 34 5

67 8

8-puzzle and robot navigation

Many

search tree is finitesearch tree is infinite

Page 36: Search Algorithm

Avoiding Repeated States

• Requires comparing state descriptions• Breadth-first strategy:

– Keep track of all generated states– If the state of a new node already exists, then

discard the node

Page 37: Search Algorithm

Avoiding Repeated States• Depth-first strategy:

– Solution 1:• Keep track of all states associated with nodes in current tree• If the state of a new node already exists, then discard the node

Avoids loops– Solution 2:

• Keep track of all states generated so far• If the state of a new node has already been generated, then

discard the node Space complexity of breadth-first

Page 38: Search Algorithm

Detecting Identical States

• Use explicit representation of state space

• Use hash-code or similar representation

Page 39: Search Algorithm

Uniform-Cost Strategy

• Each step has some cost > 0.• The cost of the path to each fringe node N is g(N) = costs of all steps.• The goal is to generate a solution path of minimal cost.• The queue FRINGE is sorted in increasing cost.

S0

1A

5B

15CS G

A

B

C

51

15

10

55

G11

G10

Page 40: Search Algorithm

Uniform-Cost Strategy

Page 41: Search Algorithm

Summary

• Search tree state space• Search strategies: breadth-first, depth-first,

and variants• Evaluation of strategies: completeness,

optimality, time and space complexity• Avoiding repeated states• Optimal search with variable step costs