Download presentation
Presentation is loading. Please wait.
Published byMarlene Grant Modified over 9 years ago
1
Computer Science CPSC 322 Lecture 6 Iterative Deepening and Search with Costs (Ch: 3.7.3, 3.5.3)
2
Lecture Overview Recap of last class: Uninformed search Iterative Deepening Search (IDS) Search with Costs Intro to Heuristic Search (time permitting)
3
A. Check what node on a path is the goal B. Initialize the frontier C. Add/remove paths from the frontier D. Check if a state is a goal Search Strategies are different with respect to how they:
4
A. Check what node on a path is the goal B. Initialize the frontier C. Add/remove paths from the frontier D. Check if a state is a goal Search Strategies are different with respect to how they:
5
DFS Depth-First Search, DFS explores each path on the frontier until its end (or until a goal is found) before considering any other path. the frontier is a last-in-first-out stack
6
Breadth-first search (BFS) BFS explores all paths of length l on the frontier, before looking at path of length l + 1 The frontier is a first-in-first-out queue
7
Comparing DFS and BFS CompleteOptimalTimeSpace DFSNO O(b m ) BFSYES O(b m )
8
When to use BFS vs. DFS? 8 The search graph has cycles or is infinite We need the shortest path to a solution There are only solutions at great depth There are some solutions at shallow depth and others deeper No way the search graph will fit into memory DFS BFS DFS
9
How can we achieve an acceptable (linear) space complexity while maintaining completeness and optimality? Key Idea: re-compute elements of the frontier rather than saving them. CompleteOptimalTimeSpace DFSNO O(b m ) BFSYES O(b m ) Comparing DFS and BFS
10
Lecture Overview Recap of last class: Uninformed search Iterative Deepening Search (IDS) Search with Costs Intro to Heuristic Search (time permitting)
11
depth = 1 depth = 2 depth = 3... Iterative Deepening DFS (IDS) in a Nutshell Use DFS to look for solutions at depth 1, then 2, then 3, etc – For depth D, ignore any paths with longer length – Depth-bounded depth-first search If no goal re-start from scratch and get to depth 2 If no goal re-start from scratch and get to depth 3 If no goal re-start from scratch and get to depth 4
12
(Time) Complexity of IDS DepthTotal # of paths at that level #times created by BFS (or DFS) #times created by IDS Total #paths for IDS 1b1 2b2b2 1.............................. m-1b m-1 1 mbmbm 1 12 m m-1 2 1 mb (m-1) b 2 2 b m-1 bmbm That sounds wasteful! Let’s analyze the time complexity For a solution at depth m with branching factor b
13
Solution at depth m, branching factor b Total # of paths generated: b m + 2 b m-1 + 3 b m-2 +...+ mb = b m (1 b 0 + 2 b -1 + 3 b -2 +...+ m b 1-m ) (Time) Complexity of IDS converges to Overhead factor For b= 10, m = 5. BSF 111,111 and ID = 123,456 (only 11% more nodes) The larger b the better, but even with b = 2 the search ID will take only 2 times as much as BFS
14
Lecture Overview Recap of last class: Uninformed search Iterative Deepening Search (IDS) Search with Costs Intro to Heuristic Search (time permitting)
15
Search with Costs Sometimes there are costs associated with arcs. Def.: The cost of a path is the sum of the costs of its arcs Slide 15
16
Example: Traveling in Romania
17
Search with Costs Sometimes there are costs associated with arcs. In this setting we often don't just want to find any solution we usually want to find the solution that minimizes cost Def.: The cost of a path is the sum of the costs of its arcs Def.: A search algorithm is optimal if when it finds a solution, it is the best one: it has the lowest path cost Slide 17
18
Lowest-cost-first search finds the path with the lowest cost to a goal node At each stage, it selects the path with the lowest cost on the frontier. The frontier is implemented as a priority queue ordered by path cost. Lowest-Cost-First Search (LCFS) Let’s see how this works in AIspace: in the Search Applet toolbar select the “Vancouver Neighborhood Graph” problem set “Search Options -> Search Algorithms” to “Lowest-Cost-First ”. select “Show Edge Costs” under “View” Create a new arc from UBC to SP with cost 20 and run LCFS Slide 18
19
Example of one step for LCFS: Let’s use (p i, c i ) to indicate a path p i and its cost the frontier is [(p 2, 5), p 3, 7 , p 1, 11 , ] p 2 is the lowest-cost node in the frontier: Paths obtained by adding neighbor nodes to the end node of p 2 are: { p 9, 10 , p 10, 15 } What happens? p 2 is selected, and tested for being a goal: false Neighbor paths of p 2 are inserted into the frontier, which is then sorted by cost Thus, the frontier is now [ p 3, 7 , p 9, 10 , p 1, 11 , p 10, 15 ]. p 3, 7 is selected next.
20
When arc costs are equal LCFS is equivalent to.. A.DFS B.BFS C.IDS D.None of the Above
21
When arc costs are equal LCFS is equivalent to.. A.DFS B.BFS C.IDS D.None of the Above
22
Analysis of Lowest-Cost Search (1) Is LCFS complete? not in general: for instance, a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs are strictly positive Is LCFS optimal? see how this works in AIspace: e.g, add arc with cost -20 to the simple search graph from N4 to S
23
Analysis of Lowest-Cost Search (1) Is LCFS complete? not in general: for instance, a cycle with zero or negative arc costs could be followed forever. yes, as long as arc costs c are strictly positive Is LCFS optimal? Not in general. 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 see how this works in AIspace: e.g, add arc with cost -20 to the simple search graph from N4 to S
24
Analysis of LCFS What is the time complexity, if the maximum path length is m and the maximum branching factor is b ? What is the space complexity?
25
Analysis of Lowest-Cost Search Time complexity, if the maximum path length is m and the maximum branching factor is b The time complexity is O(b m ) In worst case, must examine every node in the tree because it generates all paths from the start that cost less than the cost of the solution Space complexity Space complexity is O(b m ): E.g. uniform cost: just like BFS, in worst case frontier has to store all nodes m-1 steps from the start node
26
Summary of Uninformed Search CompleteOptimalTimeSpace DFSNNO(b m )O(mb) BFSYY (shortest) O(b m ) IDS LCFS Slide 26
27
Summary of Uninformed Search CompleteOptimalTimeSpace DFSNNO(b m )O(mb) BFSYY (shortest) O(b m ) IDSYY (shortest) O(b m )O(mb) LCFS Slide 27
28
Summary of Uninformed Search CompleteOptimalTimeSpace DFSNNO(b m )O(mb) BFSYY (shortest) O(b m ) IDSYY (shortest) O(b m )O(mb) LCFSY Costs > 0 Y (Least Cost) Costs >=0 O(b m ) Slide 28
29
Select the most appropriate search algorithms for specific problems. Depth-First Search vs. Bredth-First Search vs. Iterative Deepening vs. Least-Cost-First Search Define/read/write/trace/debug different search algorithms Learning Goals for Search (cont’) (up to today)
30
Continue Heuristic Search: Ch 6 TODO Assign 1 will be available early next week Due Monday Feb 2 30
31
Summary of Uninformed Search (cont.) Why are all the search strategies seen so far are called uninformed? Because they do not consider any information about the states and the goals to decide which path to expand first on the frontier They are blind to the goal In other words, they are general and do not take into account the specific nature of the problem.
32
Lecture Overview Recap of last class: Uninformed search Iterative Deepening Search (IDS) Search with Costs Intro to Heuristic Search (time permitting)
33
Blind search algorithms do not take into account the goal until they are at a goal node. Often there is extra knowledge that can be used to guide the search: -an estimate of the distance/cost from node n to a goal node. This estimate is called a search heuristic. Heuristic Search Slide 33
34
More formally Def.: A search heuristic h(n) is an estimate of the cost of the optimal (cheapest) path from node n to a goal node. Estimate: h(n1) Estimate: h(n2) Estimate: h(n3) n3 n2 n1 Slide 34
35
Example: finding routes 35 What could we use as h(n)?
36
Example: finding routes 36 What could we use as h(n)? E.g., the straight-line (Euclidian) distance between source and goal node
37
Example 2 Search problem: robot has to find a route from start to goal location on a grid with obstacles Actions: move up, down, left, right from tile to tile Cost : number of moves Possible h(n)? 1 2 3 4 5 6 G 43214321 S
38
Example 2 Search problem: robot has to find a route from start to goal location on a grid with obstacles Actions: move up, down, left, right from tile to tile Cost : number of moves Possible h(n)? Manhattan distance (L 1 distance) between two points: sum of the (absolute) difference of their coordinates 1 2 3 4 5 6 G 43214321
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.