Search George Konidaris gdk@cs.brown.edu Fall 2019 (pictures: - - PowerPoint PPT Presentation

search
SMART_READER_LITE
LIVE PREVIEW

Search George Konidaris gdk@cs.brown.edu Fall 2019 (pictures: - - PowerPoint PPT Presentation

Search George Konidaris gdk@cs.brown.edu Fall 2019 (pictures: Wikipedia) Search Basic to problem solving: How to take action to reach a goal? Search Choices have consequences! Search Formalizing the problem statement Problem


slide-1
SLIDE 1

Search

George Konidaris gdk@cs.brown.edu

Fall 2019

(pictures: Wikipedia)

slide-2
SLIDE 2

Search

Basic to problem solving:

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

Search

Choices have consequences!

slide-4
SLIDE 4

Search

Formalizing the problem statement …

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

Happens in simulation. Not web search.

slide-5
SLIDE 5

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-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

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

n

X

i=1

C(si−1, ai, si)

slide-7
SLIDE 7

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-8
SLIDE 8

Example

States: airports, times. Start state: TF Green at 5pm. Actions: available flights from each airport after each time. Goal test: reached Tokyo by midnight tomorrow. Cost function: time and/or money.

slide-9
SLIDE 9

The Search Tree

Classical conceptualization of search.

s0 s1 s2 s3 s4 s5 s6 s8 s7 s10 s9

slide-10
SLIDE 10

The Search Tree

3 3 5 1 6 9 8 3 1 4

slide-11
SLIDE 11

Important Quantities

Branching factor (breadth)

s0 s1 s2 s3 s4 s5 s6 s8 s7 s10 s9

breadth

slide-12
SLIDE 12

The Search Tree

Depth

  • min solution depth m
  • depth d

s0 s1 s2 s3 s4 s5 s6 s8 s7 s10 s9

depth (no. edges)

leaves in a tree of breadth b, depth d.

O(bd)

total nodes in the same tree

d

X

i=0

bi ∈ O(bd)

slide-13
SLIDE 13

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-14
SLIDE 14

Searching

visited = {} frontier = {s0} goal_found = false while not goal_found: node = frontier.next() frontier.del(node) if(g(node)): goal_found = true else: visited.add(node) for child in node.children: if(not visited.contains(child)): frontier.add(child)

expand tree! goal test add children

slide-15
SLIDE 15

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-16
SLIDE 16

Depth-First Search

s0 s1

Expand deepest node

slide-17
SLIDE 17

Depth-First Search

s0 s1 s2

Expand deepest node

slide-18
SLIDE 18

Depth-First Search

s0 s1 s2 X

Expand deepest node

slide-19
SLIDE 19

Depth-First Search

s0 s1 s2 X s3

Expand deepest node

slide-20
SLIDE 20

Depth-First Search

s0 s1 s2 X s3

Expand deepest node

s4

slide-21
SLIDE 21

DFS: Time

worst case: solution on this branch

O(bd − bd−m) = O(bd)

slide-22
SLIDE 22

DFS: Space

worst case: search reaches bottom

b-1 nodes open at each level d levels

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

slide-23
SLIDE 23

Depth-First Search

Properties:

  • Completeness: Only for finite trees.
  • Optimality: No.
  • Time Complexity:
  • Space Complexity:

Note that when reasoning about DFS, 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) O(bd)

slide-24
SLIDE 24

Breadth-First Search

s0 s1

Expand shallowest node

slide-25
SLIDE 25

Breadth-First Search

s0 s1 s2

Expand shallowest node

slide-26
SLIDE 26

Breadth-First Search

s0 s1 s2 s3

Expand shallowest node

slide-27
SLIDE 27

Breadth-First Search

s0 s1 s2 s3 s4

Expand shallowest node

slide-28
SLIDE 28

Breadth-First Search

s0 s1 s2 s3 s4 s5

Expand shallowest node

slide-29
SLIDE 29

BFS: Time

O(bm)

slide-30
SLIDE 30

BFS: Space

O(bm+1)

slide-31
SLIDE 31

Breadth-First Search

Properties:

  • Completeness:

Yes.

  • Optimality:

Yes for constant cost.

  • Time Complexity:
  • Space Complexity:

Manage frontier using FIFO queue. O(bm+1)

O(bm)

slide-32
SLIDE 32

Bidirectional Search

s0 s1 s2 s3 s4 s5 g0 g1 g2 g3 g4 g5

slide-33
SLIDE 33

Bidirectional Search

Why? is way less than 2 × O(b

d 2 )

O(bd) Extra requirements:

  • Must be able to invert action rules.
  • Sometimes easy, sometimes hard.
  • Not always unique.

When do you stop?

  • Candidate solution when the frontiers intersect
  • That solution may not be optimal - first must exhaust

possible shortcuts.

slide-34
SLIDE 34

Iterative Deepening Search

DFS: great memory cost - - but suboptimal solution. BFS: optimal solution but horrible memory cost: . 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.

O(bm+1) O(bd)

slide-35
SLIDE 35

IDS

s0 s1 s2 s3 s4 s5 s6 s8 s7 s10 s9

run DFS to this depth

slide-36
SLIDE 36

IDS

How can that be a good idea? It duplicates work. Optimal for constant cost! Proof? Also!

  • Low memory requirement (equal to DFS).
  • Not many more nodes expanded than BFS.

(About twice as many for binary tree.)

slide-37
SLIDE 37

IDS

visited m + 1 times visited m times

slide-38
SLIDE 38

IDS

m

X

i=0

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

# revisits # nodes at level i

bm+1 − 1 b − 1

BFS worst case:

slide-39
SLIDE 39

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-40
SLIDE 40

Uninformed Searches So Far

Simple strategy for choosing next node:

  • Choose the shallowest one (breadth-first)
  • Choose the deepest one (depth-first)

Neither guaranteed to find the least-cost path, in the case where action costs are not uniform. What if we chose the one with lowest cost?

slide-41
SLIDE 41

Uniform-Cost

Order the nodes in the frontier by cost-so-far

  • Cost from the start state to that node.

Open the next node with the smallest cost-so-far

  • Optimal solution
  • Complete (provided no negative costs)
slide-42
SLIDE 42

Uniform-Cost

s0 s1 s2

5 11

Expand cheapest node Use whole path cost

slide-43
SLIDE 43

Uniform-Cost

s0 s1 s2

5 11

s3 s4

4 7

Expand cheapest node Use whole path cost

slide-44
SLIDE 44

Uniform-Cost

s0 s1

Expand cheapest node Use whole path cost

s2

5 11

s3 s4

4 7

s5 s6

6 5

slide-45
SLIDE 45

Uniform-Cost

s0 s1

Expand cheapest node Use whole path cost

s2

5 11

s3 s4

4 7

s5 s6

6 5

s7 s8

3 9

slide-46
SLIDE 46

Informed Search

What if we know something about the search? How should we include that knowledge? In what form should it be expressed to be useful?

slide-47
SLIDE 47

What Does Uniform Cost Suggest?

The cost-so-far tells us how much it cost to get to a node.

  • Go to cheapest nodes first.

What remains?

Total cost = cost-so-far + cost-to-go Cost-so-far: cost from start to node. Cost-to-go: cost from node to goal.

slide-48
SLIDE 48

Informed Search

Key idea: heuristic function.

  • h(s) - estimates cost-to-go
  • Cost to go from state to solution.
  • Estimates h*(s) - true cost-to-go.
  • h(s) = 0 if s is a goal.
  • Problem specific (hence informed)

h(s) h(s) h(s) h(s)

slide-49
SLIDE 49

Greed

What if we expand the node with lowest h(s)?

s0 s1 s2 s3 s4 s5 s6 s8 s7 s10 s9

h(s)? h(s)? h(s)? h(s)? h(s)? h(s)? h(s)?

slide-50
SLIDE 50

Informed Search: A*

A* algorithm:

  • g(s) - cost so far (start to s).
  • Expand s that minimizes g(s) + h(s)
  • Manage frontier as priority queue.
  • Admissible heuristic: never overestimates cost.
  • h(s) = 0 if s is a goal state, so g(s) + h(s) = c(s)
  • If h is admissible, A* finds optimal solution.
  • If h(s) is exact, runs in O(bd) time.

h(s) ≤ h∗(s)

both

slide-51
SLIDE 51

Admissible Heuristics

Optimality: Proof by contradiction

slide-52
SLIDE 52

Proof

Assume: But if sa was opened before sb then:

g(sa) + h(sa) ≤ g(sb) + h(sb)

But if h is admissible then:

g(sb) + h(sb) ≤ g(sb) + h∗(sb) = g(sopt) g(sa) ≤ g(sb) + h(sb) ≤ g(sopt)

… but then:

g(sa) > g(sopt)

contradiction

slide-53
SLIDE 53

Example Heuristic

slide-54
SLIDE 54

More on Heuristics

Ideal heuristics:

  • Fast to compute.
  • Close to real costs.

Some programs automatically generate heuristics.

slide-55
SLIDE 55