Heuristic Search CPSC 322 Lecture 6 September 17, 2007 Textbook - - PowerPoint PPT Presentation

heuristic search
SMART_READER_LITE
LIVE PREVIEW

Heuristic Search CPSC 322 Lecture 6 September 17, 2007 Textbook - - PowerPoint PPT Presentation

Recap Breadth-First Search Search with Costs Heuristic Search CPSC 322 Lecture 6 September 17, 2007 Textbook 3.5 Heuristic Search CPSC 322 Lecture 6, Slide 1 Recap Breadth-First Search Search with Costs Lecture Overview 1 Recap 2


slide-1
SLIDE 1

Recap Breadth-First Search Search with Costs

Heuristic Search

CPSC 322 Lecture 6 September 17, 2007 Textbook §3.5

Heuristic Search CPSC 322 Lecture 6, Slide 1

slide-2
SLIDE 2

Recap Breadth-First Search Search with Costs

Lecture Overview

1 Recap 2 Breadth-First Search 3 Search with Costs

Heuristic Search CPSC 322 Lecture 6, Slide 2

slide-3
SLIDE 3

Recap Breadth-First Search Search with Costs

Graph Search Algorithm

Input: a graph, a set of start nodes, Boolean procedure goal(n) that tests if n is a goal node. frontier := {s : s is a start node}; while frontier is not empty: select and remove path n0, . . . , nk from frontier; if goal(nk) return n0, . . . , nk; for every neighbor n of nk add n0, . . . , nk, n to frontier; end while After the algorithm returns, it can be asked for more answers and the procedure continues. Which value is selected from the frontier defines the search strategy. The neighbor relationship defines the graph. The goal function defines what is a solution.

Heuristic Search CPSC 322 Lecture 6, Slide 3

slide-4
SLIDE 4

Recap Breadth-First Search Search with Costs

Depth-first Search

Depth-first search treats the frontier as a stack

It always selects one of the last elements added to the frontier.

Complete when the graph has no cycles and is finite Time complexity is O(bm) Space complexity is O(bm)

Heuristic Search CPSC 322 Lecture 6, Slide 4

slide-5
SLIDE 5

Recap Breadth-First Search Search with Costs

Using Depth-First Search

When is DFS appropriate?

Heuristic Search CPSC 322 Lecture 6, Slide 5

slide-6
SLIDE 6

Recap Breadth-First Search Search with Costs

Using Depth-First Search

When is DFS appropriate?

space is restricted solutions tend to occur at the same depth in the tree you know how to order nodes in the list of neighbours so that solutions will be found relatively quickly

Heuristic Search CPSC 322 Lecture 6, Slide 5

slide-7
SLIDE 7

Recap Breadth-First Search Search with Costs

Using Depth-First Search

When is DFS appropriate?

space is restricted solutions tend to occur at the same depth in the tree you know how to order nodes in the list of neighbours so that solutions will be found relatively quickly

When is DFS inappropriate?

Heuristic Search CPSC 322 Lecture 6, Slide 5

slide-8
SLIDE 8

Recap Breadth-First Search Search with Costs

Using Depth-First Search

When is DFS appropriate?

space is restricted solutions tend to occur at the same depth in the tree you know how to order nodes in the list of neighbours so that solutions will be found relatively quickly

When is DFS inappropriate?

some paths have infinite length the graph contains cycles some solutions are very deep, while others are very shallow

Heuristic Search CPSC 322 Lecture 6, Slide 5

slide-9
SLIDE 9

Recap Breadth-First Search Search with Costs

Lecture Overview

1 Recap 2 Breadth-First Search 3 Search with Costs

Heuristic Search CPSC 322 Lecture 6, Slide 6

slide-10
SLIDE 10

Recap Breadth-First Search Search with Costs

Breadth-first Search

Breadth-first search treats the frontier as a queue

it always selects one of the earliest elements added to the frontier.

Example:

the frontier is [p1, p2, . . . , pr] neighbours of p1 are {n1, . . . , nk}

What happens?

p1 is selected, and tested for being a goal. Neighbours of p1 follow pr at the end of the frontier. Thus, the frontier is now [p2, . . . , pr, (p1, n1), . . . , (p1, nk)]. p2 is selected next.

Heuristic Search CPSC 322 Lecture 6, Slide 7

slide-11
SLIDE 11

Recap Breadth-First Search Search with Costs

Illustrative Graph — Breadth-first Search

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Heuristic Search CPSC 322 Lecture 6, Slide 8

slide-12
SLIDE 12

Recap Breadth-First Search Search with Costs

Analysis of Breadth-First Search

Is BFS complete?

Heuristic Search CPSC 322 Lecture 6, Slide 9

slide-13
SLIDE 13

Recap Breadth-First Search Search with Costs

Analysis of Breadth-First Search

Is BFS complete?

Yes (but it wouldn’t be if the branching factor for any node was infinite) In fact, BFS is guaranteed to find the path that involves the fewest arcs (why?)

Heuristic Search CPSC 322 Lecture 6, Slide 9

slide-14
SLIDE 14

Recap Breadth-First Search Search with Costs

Analysis of Breadth-First Search

Is BFS complete?

Yes (but it wouldn’t be if the branching factor for any node was infinite) In fact, BFS is guaranteed to find the path that involves the fewest arcs (why?)

What is the time complexity, if the maximum path length is m and the maximum branching factor is b?

Heuristic Search CPSC 322 Lecture 6, Slide 9

slide-15
SLIDE 15

Recap Breadth-First Search Search with Costs

Analysis of Breadth-First Search

Is BFS complete?

Yes (but it wouldn’t be if the branching factor for any node was infinite) In fact, BFS is guaranteed to find the path that involves the fewest arcs (why?)

What is the time complexity, if the maximum path length is m and the maximum branching factor is b?

The time complexity is O(bm): must examine every node in the tree. The order in which we examine nodes (BFS or DFS) makes no difference to the worst case: search is unconstrained by the goal.

Heuristic Search CPSC 322 Lecture 6, Slide 9

slide-16
SLIDE 16

Recap Breadth-First Search Search with Costs

Analysis of Breadth-First Search

Is BFS complete?

Yes (but it wouldn’t be if the branching factor for any node was infinite) In fact, BFS is guaranteed to find the path that involves the fewest arcs (why?)

What is the time complexity, if the maximum path length is m and the maximum branching factor is b?

The time complexity is O(bm): must examine every node in the tree. The order in which we examine nodes (BFS or DFS) makes no difference to the worst case: search is unconstrained by the goal.

What is the space complexity?

Heuristic Search CPSC 322 Lecture 6, Slide 9

slide-17
SLIDE 17

Recap Breadth-First Search Search with Costs

Analysis of Breadth-First Search

Is BFS complete?

Yes (but it wouldn’t be if the branching factor for any node was infinite) In fact, BFS is guaranteed to find the path that involves the fewest arcs (why?)

What is the time complexity, if the maximum path length is m and the maximum branching factor is b?

The time complexity is O(bm): must examine every node in the tree. The order in which we examine nodes (BFS or DFS) makes no difference to the worst case: search is unconstrained by the goal.

What is the space complexity?

Space complexity is O(bm): we must store the whole frontier in memory

Heuristic Search CPSC 322 Lecture 6, Slide 9

slide-18
SLIDE 18

Recap Breadth-First Search Search with Costs

Using Breadth-First Search

When is BFS appropriate?

Heuristic Search CPSC 322 Lecture 6, Slide 10

slide-19
SLIDE 19

Recap Breadth-First Search Search with Costs

Using Breadth-First Search

When is BFS appropriate?

space is not a problem it’s necessary to find the solution with the fewest arcs although all solutions may not be shallow, at least some are there may be infinite paths

Heuristic Search CPSC 322 Lecture 6, Slide 10

slide-20
SLIDE 20

Recap Breadth-First Search Search with Costs

Using Breadth-First Search

When is BFS appropriate?

space is not a problem it’s necessary to find the solution with the fewest arcs although all solutions may not be shallow, at least some are there may be infinite paths

When is BFS inappropriate?

Heuristic Search CPSC 322 Lecture 6, Slide 10

slide-21
SLIDE 21

Recap Breadth-First Search Search with Costs

Using Breadth-First Search

When is BFS appropriate?

space is not a problem it’s necessary to find the solution with the fewest arcs although all solutions may not be shallow, at least some are there may be infinite paths

When is BFS inappropriate?

space is limited all solutions tend to be located deep in the tree the branching factor is very large

Heuristic Search CPSC 322 Lecture 6, Slide 10

slide-22
SLIDE 22

Recap Breadth-First Search Search with Costs

Lecture Overview

1 Recap 2 Breadth-First Search 3 Search with Costs

Heuristic Search CPSC 322 Lecture 6, Slide 11

slide-23
SLIDE 23

Recap Breadth-First Search Search with Costs

Search with Costs

Sometimes there are costs associated with arcs.

Definition (cost of a path)

The cost of a path is the sum of the costs of its arcs: cost(n0, . . . , nk) =

k

  • i=1

|ni−1, ni|

Heuristic Search CPSC 322 Lecture 6, Slide 12

slide-24
SLIDE 24

Recap Breadth-First Search Search with Costs

Search with Costs

Sometimes there are costs associated with arcs.

Definition (cost of a path)

The cost of a path is the sum of the costs of its arcs: cost(n0, . . . , nk) =

k

  • i=1

|ni−1, ni| In this setting we often don’t just want to find just any solution we usually want to find the solution that minimizes cost

Definition (optimal algorithm)

A search algorithm is optimal if it is complete, and only returns cost-minimizing solutions.

Heuristic Search CPSC 322 Lecture 6, Slide 12

slide-25
SLIDE 25

Recap Breadth-First Search Search with Costs

Lowest-Cost-First Search

At each stage, lowest-cost-first search selects a path on the frontier with lowest cost.

The frontier is a priority queue ordered by path cost. We say “a path” because there may be ties

When all arc costs are equal, LCFS is equivalent to BFS.

Heuristic Search CPSC 322 Lecture 6, Slide 13

slide-26
SLIDE 26

Recap Breadth-First Search Search with Costs

Lowest-Cost-First Search

At each stage, lowest-cost-first search selects a path on the frontier with lowest cost.

The frontier is a priority queue ordered by path cost. We say “a path” because there may be ties

When all arc costs are equal, LCFS is equivalent to BFS. Example:

the frontier is [p1, 10, p2, 5, p3, 7] p2 is the lowest-cost node in the frontier neighbours of p2 are {p9, 12, p10, 15}

What happens?

Heuristic Search CPSC 322 Lecture 6, Slide 13

slide-27
SLIDE 27

Recap Breadth-First Search Search with Costs

Lowest-Cost-First Search

At each stage, lowest-cost-first search selects a path on the frontier with lowest cost.

The frontier is a priority queue ordered by path cost. We say “a path” because there may be ties

When all arc costs are equal, LCFS is equivalent to BFS. Example:

the frontier is [p1, 10, p2, 5, p3, 7] p2 is the lowest-cost node in the frontier neighbours of p2 are {p9, 12, p10, 15}

What happens?

p2 is selected, and tested for being a goal. Neighbours of p2 are inserted into the frontier (it doesn’t matter where they go) Thus, the frontier is now [p1, 10, p9, 12, p10, 15, p3, 7]. p3 is selected next. Of course, we’d really implement this as a priority queue.

Heuristic Search CPSC 322 Lecture 6, Slide 13

slide-28
SLIDE 28

Recap Breadth-First Search Search with Costs

Analysis of Lowest-Cost-First Search

Is LCFS complete?

Heuristic Search CPSC 322 Lecture 6, Slide 14

slide-29
SLIDE 29

Recap Breadth-First Search Search with Costs

Analysis of Lowest-Cost-First Search

Is LCFS complete?

not in general: a cycle with zero or negative arc costs could be followed forever.

Heuristic Search CPSC 322 Lecture 6, Slide 14

slide-30
SLIDE 30

Recap Breadth-First Search Search with Costs

Analysis of Lowest-Cost-First Search

Is LCFS complete?

not in general: a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs are strictly positive

What is the time complexity, if the maximum path length is m and the maximum branching factor is b?

Heuristic Search CPSC 322 Lecture 6, Slide 14

slide-31
SLIDE 31

Recap Breadth-First Search Search with Costs

Analysis of Lowest-Cost-First Search

Is LCFS complete?

not in general: a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs are strictly positive

What is the time complexity, if the maximum path length is m and the maximum branching factor is b?

The time complexity is O(bm): must examine every node in the tree. Knowing costs doesn’t help here.

Heuristic Search CPSC 322 Lecture 6, Slide 14

slide-32
SLIDE 32

Recap Breadth-First Search Search with Costs

Analysis of Lowest-Cost-First Search

Is LCFS complete?

not in general: a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs are strictly positive

What is the time complexity, if the maximum path length is m and the maximum branching factor is b?

The time complexity is O(bm): must examine every node in the tree. Knowing costs doesn’t help here.

What is the space complexity?

Heuristic Search CPSC 322 Lecture 6, Slide 14

slide-33
SLIDE 33

Recap Breadth-First Search Search with Costs

Analysis of Lowest-Cost-First Search

Is LCFS complete?

not in general: a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs are strictly positive

What is the time complexity, if the maximum path length is m and the maximum branching factor is b?

The time complexity is O(bm): must examine every node in the tree. Knowing costs doesn’t help here.

What is the space complexity?

Space complexity is O(bm): we must store the whole frontier in memory.

Heuristic Search CPSC 322 Lecture 6, Slide 14

slide-34
SLIDE 34

Recap Breadth-First Search Search with Costs

Analysis of Lowest-Cost-First Search

Is LCFS complete?

not in general: a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs are strictly positive

What is the time complexity, if the maximum path length is m and the maximum branching factor is b?

The time complexity is O(bm): must examine every node in the tree. Knowing costs doesn’t help here.

What is the space complexity?

Space complexity is O(bm): we must store the whole frontier in memory.

Is LCFS optimal?

Not in general. Why not?

Heuristic Search CPSC 322 Lecture 6, Slide 14

slide-35
SLIDE 35

Recap Breadth-First Search Search with Costs

Analysis of Lowest-Cost-First Search

Is LCFS complete?

not in general: a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs are strictly positive

What is the time complexity, if the maximum path length is m and the maximum branching factor is b?

The time complexity is O(bm): must examine every node in the tree. Knowing costs doesn’t help here.

What is the space complexity?

Space complexity is O(bm): we must store the whole frontier in memory.

Is LCFS optimal?

Not in general. Why not? Arc costs could be negative: a path that initially looks high-cost could end up getting a “refund”. However, LCFS is optimal if arc costs are guaranteed to be non-negative.

Heuristic Search CPSC 322 Lecture 6, Slide 14