Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science CPSC 322 Lecture 9 (Ch 3.7.1 - 3.7.4, 3.7.6) Slide 1.

Similar presentations


Presentation on theme: "Computer Science CPSC 322 Lecture 9 (Ch 3.7.1 - 3.7.4, 3.7.6) Slide 1."— Presentation transcript:

1 Computer Science CPSC 322 Lecture 9 (Ch 3.7.1 - 3.7.4, 3.7.6) Slide 1

2 Announcements Midterm: Friday Feb. 27 - See update schedule on website Slide 2

3 Slide 3 Lecture Overview Recap of Lecture 8 Cycle checking, multiple path pruning Branch-and-Bound Other A* refinements

4 Apply basic properties of search algorithms: - completeness, optimality, time and space complexity CompleteOptimalTimeSpace DFSN (Y if no cycles) NO(b m )O(mb) BFSYYO(b m ) IDSYYO(b m )O(mb) LCFS (when arc costs available) Y Costs > 0 Y Costs >=0 O(b m ) Best First (when h available) NNO(b m ) A* (when arc costs > 0 and h admissible) YYO(b m ) Recap 4

5 Proved A* optimality under admissibility conditions Discussed A* as optimally efficient No other optimal algorithm is guaranteed to expand fewer nodes than A* Slide 5

6 Slide 6 Lecture Overview Recap of Lecture 8 Cycle checking, multiple path pruning Branch-and-Bound Other A* refinements

7 Clarification: state space graph vs search tree kc b z h a d f State space graph represents the states in a search problem, and how they are connected by the available operators Search Tree: Shows how the search space is traversed by a given search algorithm: explicitly “unfolds” the paths that are expanded. k c b z h a d f If there are no cycles or multiple paths, the two look the same 7

8 Clarification: state space graph vs search tree kc b z h a d f State space graph k cb z k ad c If there are cycles or multiple paths, the two look very different Search Tree: (first three levels) h b k cbf 8

9 Size of state space vs. search tree If there are cycles or multiple paths, the two look very different A B C D A B C B CCC DD E.g. state space with d states and 2 actions from each state to next With d + 1 states, search tree has depth d 2 d possible paths through the search space => exponentially larger search tree! With cycles or multiple parents, the search tree can be exponential in the state space 9

10 Cycle Checking and Multiple Path Pruning Cycle checking: good when we want to avoid infinite loops, but also want to find more than one solution, if they exist Multiple path pruning: good when we only care about finding one solution Subsumes cycle checking 10

11 What is the computational cost of cycle checking? Cycle Checking You can prune a path that ends in a node already on the path. This pruning cannot remove an optimal solution => cycle check Good when we want to avoid infinite loops, but also want to find more than one solution, if they exist 11

12 Cycle Checking See how DFS and BFS behave on Cyclic Graph Example in Aispace, when Search Options-> Pruning -> Loop detection is selected Set N1 to be a normal node so that there is only one start node. Check, for each algorithm, what happens during the first expansion from node 3 to node 2 12

13 Depth First Search Since DFS looks at one path at a time, when a node is encountered for the second time (e.g. Node 2 while expanding N0, N2, N5, N3) it is guaranteed to be part of a cycle. 13

14 Breadth First Search Since BFS keeps multiple subpaths going, when a node is encountered for the second time, it could be as part of expanding a different path (e.g. Node 2 while expanding N0-.N3). Not necessarily a cycle. 14

15 Breadth First Search The cycle for BFS happens when N2 is encountered for the second time while expanding the path N0-.N2- N5-N3. 15

16 Computational Cost of Cycle Checking? D. None of the above B. Linear time in the path length: before adding a new node to the currently selected path, check that the node is not already part of the path A. As low as Constant time: (e.g., set a bit to 1 when a node is selected for expansion, and never expand a node with a bit set to 1) C. It depends on the algorithm 16

17 Computational Cost of Cycle Checking? D. None of the above B. Linear time in the path length: before adding a new node to the currently selected path, check that the node is not already part of the path A. As low as constant time: (e.g., set a bit to 1 when a node is selected for expansion, and never expand a node with a bit set to 1) C. It depends on the algorithm 17

18 What is the computational cost of cycle checking? Cycle Checking You can prune a path that ends in a node already on the path. This pruning cannot remove an optimal solution => cycle check Using depth-first methods, with the graph explicitly stored, this can be done in constant time -Only one path being explored at a time Other methods: cost is linear in path length -check each node in the path 18

19 If we only want one path to the solution Can prune path to a node n that has already been reached via a previous path -Subsumes cycle check Multiple Path Pruning n 19

20 Can see how it works by –Running BFS on the Cyclic Graph Example in CISPACE –See how it handles the multiple paths from N0 to N2 –You can erase start node N1 to simplify things Multiple Path Pruning n 20

21 Multiple-Path Pruning & Optimal Solutions Problem: what if a subsequent path p 2 to n is better (shorter or less costly) than the first path p 1 to n, and we want an optimal solution ? Can remove all paths from the frontier that use the longer path: these can’t be optimal. Can change the initial segment of the paths on the frontier to use the shorter or Can prove that this can’t happen for an algorithm? p1 p2 21

22 “ Whenever search algorithm X expands the first path p ending in node n, this is the lowest-cost path from the start node to n (if all costs ≥ 0)” This is true for D. None of the above A. Lowest Cost Search First C. Both of the above B. A* Can prove that search algorithm X always find the optimal path to any node n in the search space first? 22

23 “ Whenever search algorithm X expands the first path p ending in node n, this is the lowest-cost path from the start node to n (if all costs ≥ 0)” This is true for D. None of the above A. Lowest Cost Search First C. Both of the above B. A* Can prove that search algorithm X always find the optimal path to any node n in the search space first? 23

24 Which of the following algorithms always find the shortest path to nodes on the frontier first? Only Least Cost First Search Counter-example for A*: it expands the upper path first Special conditions on the heuristic can recover the guarantee of LCFS for A*: the monotone restriction (See P&M text, Section 3.7.2) 22 11120 Start10 0 1Goal 24

25 25

26 Slide 26 Lecture Overview Recap of Lecture 8 Cycle checking, multiple path pruning Branch-and-Bound Other A* refinements

27 Branch-and-Bound Search What does allow A* to do better than the other search algorithms we have seen? Arc cost and h(h) combined in f(n) What is the biggest problem with A*? space Possible Solution: Combine DFS with f 27

28 Branch-and-Bound Search One way to combine DFS with heuristic guidance Follows exactly the same search path as depth-first search But to ensure optimality, it does not stop at the first solution found It continues, after recording upper bound on solution cost upper bound: UB = cost of the best solution found so far Initialized to  or any overestimate of optimal solution cost When a path p is selected for expansion: Compute lower bound LB(p) = f(p) = cost(p) + h(p) - If LB(p)  UB, remove p from frontier without expanding it (pruning) - Else expand p, adding all of its neighbors to the frontier 28

29 Example Arc cost = 1 h(n) = 0 for every n UB = ∞ Solution! UB = 5 Before expanding a path p, check its f value f(p): Expand only if f(p) < UB 29 Simplifications for clarity

30 Example Arc cost = 1 h(n) = 0 for every n UB = 5 Cost = 5 Prune! 30

31 Example Arc cost = 1 h(n) = 0 for every n UB = 5 Cost = 5 Prune! Cost = 5 Prune! Solution! UB =? 31

32 Example Arc cost = 1 h(n) = 0 for every n UB = 3 Cost = 3 Prune! Cost = 3 Prune! Cost = 3 Prune! 32

33 Branch-and-Bound Analysis Complete ? Optimal: Space complexity: Time complexity: ……. 33

34 Is Branch-and-Bound optimal? D. Only if there are no cycles A. YES, with no further conditions C. Only if h(n) is admissible B. NO Branch-and-Bound Analysis 34

35 Is Branch-and-Bound optimal? D. Only if there are no cycles A. YES, with no further conditions C. Only if h(n) is admissible. Otherwise, when checking LB(p)  UB, if the answer is yes but h(p) is an overestimate of the actual cost of p, we remove a possibly optomal solution B. NO Branch-and-Bound Analysis 35

36 Branch-and-Bound Analysis Complete ? (..even when there are cycles) B. NO A. YES C. It depends 36

37 Branch-and-Bound Analysis Complete ? (..even when there are cycles) IT DEPENDS on whether we can initialize UB to a finite value, i.e. we have a reliable overestimate of the solution cost. If we don`t, we need to use ∞, and BBA can be caught in a cycle 37

38 Branch-and-Bound Analysis Complete ? Same as DFS: can’t handle cycles/infinite graphs. But complete if initialized with some finite U Optimal: YES, if h(n) is admissible Space complexity: Branch & Bound has the same space complexity as DFS this is a big improvement over A*! Time complexity O(b m ) 38

39 Learning Goals for today’s class Pruning cycles and multiple paths Define/read/write/trace/debug different search algorithms - In more detail today: Branch-and-Bound Slide 39

40 CompleteOptimalTimeSpace DFSNNO(b m )O(mb) BFSYYO(b m ) IDSYYO(b m )O(mb) LCFS (when arc costs available) Y Costs > 0 Y Costs >=0 O(b m ) Best First (when h available) NNO(b m ) A* (when arc costs > 0 and h admissible ) YY O(b m ) Optimally Efficient O(b m ) Branch-and-BoundN (Y with finite initial bound) Y If h admissible O(b m ) Search Methods so Far Slide 40

41 Next class: Fri Read 3.6 (Dynamic programming) 4.1 and 4.2 (Intro to CSP) Keep working on assignment-1 ! Do Practice Exercise 3D Slide 41


Download ppt "Computer Science CPSC 322 Lecture 9 (Ch 3.7.1 - 3.7.4, 3.7.6) Slide 1."

Similar presentations


Ads by Google