Search George Konidaris gdk@cs.duke.edu Spring 2016 (pictures: - - PowerPoint PPT Presentation

search
SMART_READER_LITE
LIVE PREVIEW

Search George Konidaris gdk@cs.duke.edu Spring 2016 (pictures: - - PowerPoint PPT Presentation

Search George Konidaris gdk@cs.duke.edu Spring 2016 (pictures: Wikipedia) Search Basic to problem solving: How to take action to reach a goal? Search Specifically: Problem can be in various states . Start in an initial state .


slide-1
SLIDE 1

Search

George Konidaris gdk@cs.duke.edu

Spring 2016

(pictures: Wikipedia)

slide-2
SLIDE 2

Search

Basic to problem solving:

  • How to take action to reach a goal?
slide-3
SLIDE 3

Search

Specifically:

  • Problem can be in various states.
  • Start in an initial state.
  • Have some actions available.
  • Each action has a cost.
  • Want to reach some goal, minimizing cost.

Happens in simulation. Not web search.

slide-4
SLIDE 4

Formal Definition

Set of states

  • Start state
  • Set of actions and action rules
  • Goal test
  • Cost function
  • So a search problem is specified by a tuple, .

S s ∈ S A a(s) → s0 g(s) → {0, 1} C(s, a, s0) → R+ (S, s, A, g, C)

slide-5
SLIDE 5

Problem Statement

Find a sequence of actions and corresponding states

  • … such that:
  • while minimizing:

a1, ..., an s1, ..., sn si = ai(si−1), i = 1, ..., n s0 = s g(sn) = 1

n

X

i=1

C(si−1, a, si)

slide-6
SLIDE 6

Problem Statement

Find a sequence of actions and corresponding states

  • … such that:
  • while minimizing:

a1, ..., an s1, ..., sn si = ai(si−1), i = 1, ..., n s0 = s g(sn) = 1

n

X

i=1

C(si−1, a, si)

start state

slide-7
SLIDE 7

Problem Statement

Find a sequence of actions and corresponding states

  • … such that:
  • while minimizing:

a1, ..., an s1, ..., sn si = ai(si−1), i = 1, ..., n s0 = s g(sn) = 1

n

X

i=1

C(si−1, a, si)

start state legal moves

slide-8
SLIDE 8

Problem Statement

Find a sequence of actions and corresponding states

  • … such that:
  • while minimizing:

a1, ..., an s1, ..., sn si = ai(si−1), i = 1, ..., n s0 = s g(sn) = 1

n

X

i=1

C(si−1, a, si)

start state legal moves end at the goal

slide-9
SLIDE 9

Problem Statement

Find a sequence of actions and corresponding states

  • … such that:
  • while minimizing:

a1, ..., an s1, ..., sn si = ai(si−1), i = 1, ..., n s0 = s g(sn) = 1

n

X

i=1

C(si−1, a, si)

start state legal moves end at the goal minimize sum of costs - rational agent

slide-10
SLIDE 10

Example

Sudoku

  • States: all legal Sudoku boards.
  • Start state: a particular, partially filled-in, board.
  • Actions: inserting a valid number into the board.
  • Goal test: all cells filled and no collisions.
  • Cost function: 1 per move.
slide-11
SLIDE 11

Example

Flights - e.g., ITA Software.

  • States: airports.
  • Start state: RDU.
  • Actions: available flights from each airport.
  • Goal test: reached Tokyo.
  • Cost function: time and/or money.
slide-12
SLIDE 12

The Search Tree

Classical conceptualization of search.

s0 s1 s2 s3 s4 s5 s6 s8 s7 s10 s9

slide-13
SLIDE 13

The Search Tree

3 3 5 1 6 9 8 3 1 4

slide-14
SLIDE 14

Important Quantities

Breadth (branching factor)

s0 s1 s2 s3 s4 s5 s6 s8 s7 s10 s9

breadth

slide-15
SLIDE 15

The Search Tree

Depth

  • min solution depth m

s0 s1 s2 s3 s4 s5 s6 s8 s7 s10 s9

depth

leaves in a search tree of breadth b, depth d.

O(bd)

slide-16
SLIDE 16

The Search Tree

Expand the tree one node at a time. Frontier: set of nodes in tree, but not expanded.

s0 s1 s2 s3 s4 s5 s6 s8 s7 s10 s9

Key to a search algorithm: which node to expand next?

slide-17
SLIDE 17

How to Expand?

Uninformed strategy:

  • nothing known about likely solutions in the tree.
  • What to do?
  • Expand deepest node (depth-first search)
  • Expand closest node (breadth-first search)
  • Properties
  • Completeness
  • Optimality
  • Time Complexity (total number of nodes visited)
  • Space Complexity (size of frontier)
slide-18
SLIDE 18

Depth-First Search

s0 s1

Expand deepest node

slide-19
SLIDE 19

Depth-First Search

s0 s1 s2

Expand deepest node

slide-20
SLIDE 20

Depth-First Search

s0 s1 s2 X

Expand deepest node

slide-21
SLIDE 21

Depth-First Search

s0 s1 s2 X s3

Expand deepest node

slide-22
SLIDE 22

DFS: Time

worst case: solution on this branch

O(bd+1 − bd−m) = O(bd+1)

slide-23
SLIDE 23

DFS: Space

worst case: search is here

b-1 nodes open at each level

  • d levels

O((b − 1)d) = O(bd)

slide-24
SLIDE 24

DFS: Space

worst case: search is here

b-1 nodes open at each level

  • d levels

O((b − 1)d) = O(bd)

slide-25
SLIDE 25

DFS: Space

worst case: search is here

b-1 nodes open at each level

  • d levels

O((b − 1)d) = O(bd)

slide-26
SLIDE 26

DFS: Space

worst case: search is here

b-1 nodes open at each level

  • d levels

O((b − 1)d) = O(bd)

slide-27
SLIDE 27

DFS: Space

worst case: search is here

b-1 nodes open at each level

  • d levels

O((b − 1)d) = O(bd)

slide-28
SLIDE 28

Depth-First Search

Properties:

  • Completeness: Only for finite trees.
  • Optimality: No.
  • Time Complexity:
  • Space Complexity:
  • Here m is depth of found solution (not necessarily min solution

depth).

  • The deepest node happens to be the one you most recently visited -

easy to implement recursively OR manage frontier using LIFO queue. O(bd+1) O(bd)

slide-29
SLIDE 29

Breadth-First Search

s0 s1

Expand shallowest node

slide-30
SLIDE 30

Breadth-First Search

s0 s1 s2

Expand shallowest node

slide-31
SLIDE 31

Breadth-First Search

s0 s1 s2 s3

Expand shallowest node

slide-32
SLIDE 32

Breadth-First Search

s0 s1 s2 s3 s4

Expand shallowest node

slide-33
SLIDE 33

Breadth-First Search

s0 s1 s2 s3 s4 s5

Expand shallowest node

slide-34
SLIDE 34

BFS: Time

O(bm+1)

slide-35
SLIDE 35

BFS: Space

O(bm+1)

slide-36
SLIDE 36

Breadth-First Search

Properties:

  • Completeness:

Yes.

  • Optimality:

Yes for constant cost.

  • Time Complexity:
  • Space Complexity:
  • Better than depth-first search in all respects except memory

cost - must maintain a large frontier.

  • Manage frontier using FIFO queue.

O(bm+1) O(bm+1)

slide-37
SLIDE 37

Iterative Deepening Search

Combine these two strengths.

  • The core problems in DFS are a) not optimal, and b) not

complete … because it fails to explore other branches.

  • Otherwise it’s a very nice algorithm!
  • Iterative Deepening:
  • Run DFS to a fixed depth z.
  • Start at z=1. If no solution, increment z and rerun.
slide-38
SLIDE 38

IDS

s0 s1 s2 s3 s4 s5 s6 s8 s7 s10 s9

run DFS to this depth

slide-39
SLIDE 39

IDS

s0 s1 s2 s3 s4 s5 s6 s8 s7 s10 s9

run DFS to this depth

slide-40
SLIDE 40

IDS

s0 s1 s2 s3 s4 s5 s6 s8 s7 s10 s9

run DFS to this depth

slide-41
SLIDE 41

IDS

s0 s1 s2 s3 s4 s5 s6 s8 s7 s10 s9

run DFS to this depth

slide-42
SLIDE 42

IDS

Optimal for constant cost! Proof?

  • How can that be a good idea?

It duplicates work.

  • Sure but:
  • Low memory requirement (equal to DFS).
  • Not many more nodes expanded than BFS. (About twice as

many for binary tree.)

slide-43
SLIDE 43

IDS

visited m + 1 times visited m times

slide-44
SLIDE 44

IDS (Reprise)

m

X

i=0

bi(m − i + 1) = b(bm+1 − m − 2) + m + 1 (b − 1)2

# nodes at level i # revisits

bm+1 − 1 b − 1

DFS worst case:

slide-45
SLIDE 45

IDS

Key Insight:

  • Many more nodes at depth m+1 than at depth m.
  • MAGIC.
  • “In general, iterative deepening search is the preferred uninformed

search method when the state space is large and the depth of the solution is unknown.” (R&N)

slide-46
SLIDE 46

Next Week

Informed searches … what if you know something about the the solution?

  • What form should such knowledge take?
  • How should you use it?