Tree search example Arad Sibiu Timisoara Zerind Arad Fagaras Oradea Arad Lugoj Arad Oradea Rimnicu Vilcea AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 27
Tree search example Arad Sibiu Timisoara Zerind Arad Fagaras Oradea Arad Lugoj Arad Oradea Rimnicu Vilcea Note: loopy path (repeated state) in the leftmost To avoid exploring redundant paths by using a data structure explored set – remembering every expanded node — newly generated nodes in the explored set can be discarded Graph ⇒ Tree AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 28
Implementation: states vs. nodes A state is a (representation of) a physical configuration A node is a data structure constituting part of a search tree P ARENT Node A CTION = Right 5 4 5 4 P ATH- C OST = 6 6 1 8 6 1 8 S TATE 7 3 2 7 3 2 Notation (.) for data structures – n . State : state (in the state space) corresponds to the node – n . Parent : node (in the search tree that generated this node) – n . Action : action applied to the parent to generate the node – n . Path-Cost : cost, g ( x ) , of path from initial state to n AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 29
Search strategies A strategy is defined by picking the order of node expansion Strategies are evaluated along the following dimensions: completeness—does it always find a solution if one exists? time complexity—number of nodes generated/expanded space complexity—maximum number of nodes in memory optimality—does it always find a least-cost solution? Time and space complexity are measured in terms of b —maximum branching factor of the search tree d —depth of the least-cost solution m —maximum depth of the state space (may be ∞ ) AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 30
Uninformed search strategies Uninformed (blind) strategies use only the information available in the problem definition • Breadth-first search • Uniform-cost search • Depth-first search • Depth-limited search • Iterative deepening search AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 31
Breadth-first search function Breadth-First-Search ( problem ) returns a sltn., or failures node ← a node with State= problem . Initial-State,Path-Cost =0 if problem . Goal-Test ( node .State) then reture Solution ( node ) frontier ← a FIFO queue with node as the only element explored ← an empty set loop do if Empty ?( frontier) then reture failure node ← Pop ( frontier ) add node .State to explored for each action in problem . Action ( node .State) do child ← Child-Node ( problem , node , action ) if child . State is not in explored or frontier then if problem . Goal-Test ( child . State ) then reture Sltn. ( child ) frontier ← Insert ( child , frontier ) Notation (.) for abbreviations of the statements AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 32
Breadth-first search Expand shallowest unexpanded node Implementation frontier = FIFO (First-In-First-Out) queue, i.e., new successors go at end A B C D E F G AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 33
Breadth-first search Expand shallowest unexpanded node Implementation A B C D E F G AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 34
Breadth-first search Expand shallowest unexpanded node Implementation A B C D E F G AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 35
Breadth-first search Expand shallowest unexpanded node Implementation A B C D E F G AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 36
Properties of breadth-first search Complete?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 37
Properties of breadth-first search Complete?? Yes (if b is finite) Time?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 38
Properties of breadth-first search Complete?? Yes (if b is finite) Time?? 1 + b + b 2 + b 3 + . . . + b d + b ( b d − 1) = O ( b d +1 ) i.e., exp. in d Space?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 39
Properties of breadth-first search Complete?? Yes (if b is finite) Time?? 1 + b + b 2 + b 3 + . . . + b d + b ( b d − 1) = O ( b d +1 ) i.e., exp. in d Space?? O ( b d +1 ) (keeps every node in memory) Optimal?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 40
Properties of breadth-first search Complete?? Yes (if b is finite) Time?? 1 + b + b 2 + b 3 + . . . + b d + b ( b d − 1) = O ( b d +1 ) i.e., exp. in d Space?? O ( b d +1 ) (keeps every node in memory) Optimal?? Yes (if cost = 1 per step); not optimal in general (the shallowest goal node is not necessarily optimal) AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 41
Properties of breadth-first search Complete?? Yes (if b is finite) Time?? 1 + b + b 2 + b 3 + . . . + b d + b ( b d − 1) = O ( b d +1 ) i.e., exp. in d Space?? O ( b d +1 ) (keeps every node in memory) Optimal?? Yes (if cost = 1 per step); not optimal in general O ( b d ) : d = 16 ← b = 1 , 1 million nodes/second, 1000 bytes/node Time — 350 years Space — 10 exabytes – Space is the big problem; can easily generate nodes at 100MB/sec, so 24hrs = 8640GB AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 42
Uniform-cost search Expand least-cost unexpanded node Implementation frontier = queue ordered by path cost, lowest first Equivalent to breadth-first if step costs all equal Complete?? Yes, if step cost ≥ ǫ Time?? # of nodes with g ≤ cost of optimal solution, O ( b ⌈ C ∗ /ǫ ⌉ ) where C ∗ is the cost of the optimal solution Space?? # of nodes with g ≤ cost of optimal solution, O ( b ⌈ C ∗ /ǫ ⌉ ) Optimal?? Yes—nodes expanded in increasing order of g ( n ) AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 43
Uniform-cost search O ( b ⌈ C ∗ /ǫ ⌉ ) : – can be much greater than O ( b d ) (explore large trees involving large perhaps useful steps) – all step costs are equal, O ( b ⌈ C ∗ /ǫ ⌉ ) is just O ( b d +1 ) UCS is similar to BFS – except that BFS stops as soon as it generates a goal whereas UCS examines all the nodes at the goal’s depth to see if one has a lower cost strictly more work by expanding nodes at depth d unnecessarily AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 44
Depth-first search Expand deepest unexpanded node Implementation frontier = LIFO (Last-In-First-Out) queue, i.e., put successors at front A B C D E F G H I J K L M N O AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 45
Depth-first search Expand deepest unexpanded node Implementation A B C D E F G H I J K L M N O AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 46
Depth-first search Expand deepest unexpanded node Implementation A B C D E F G H I J K L M N O AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 47
Depth-first search Expand deepest unexpanded node Implementation A B C D E F G H I J K L M N O AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 48
Depth-first search Expand deepest unexpanded node Implementation A B C D E F G H I J K L M N O AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 49
Depth-first search Expand deepest unexpanded node Implementation A B C D E F G H I J K L M N O AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 50
Depth-first search Expand deepest unexpanded node Implementation A B C D E F G H I J K L M N O AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 51
Depth-first search Expand deepest unexpanded node Implementation A B C D E F G H I J K L M N O AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 52
Depth-first search Expand deepest unexpanded node Implementation A B C D E F G H I J K L M N O AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 53
Depth-first search Expand deepest unexpanded node Implementation A B C D E F G H I J K L M N O AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 54
Depth-first search Expand deepest unexpanded node Implementation A B C D E F G H I J K L M N O AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 55
Depth-first search Expand deepest unexpanded node Implementation A B C D E F G H I J K L M N O AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 56
Properties of depth-first search Complete?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 57
Properties of depth-first search Complete?? No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path ⇒ complete in finite spaces Time?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 58
Properties of depth-first search Complete?? No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path ⇒ complete in finite spaces Time?? O ( b m ) : terrible if m is much larger than d but if solutions are dense, may be much faster than breadth-first Space?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 59
Properties of depth-first search Complete?? No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path ⇒ complete in finite spaces Time?? O ( b m ) : terrible if m is much larger than d but if solutions are dense, may be much faster than breadth-first Space?? O ( bm ) , i.e., linear space Optimal?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 60
Properties of depth-first search Complete?? No: fails in infinite-depth spaces, spaces with loops Modify to avoid repeated states along path ⇒ complete in finite spaces Time?? O ( b m ) : terrible if m is much larger than d but if solutions are dense, may be much faster than breadth- first Space?? O ( bm ) , i.e., linear space Optimal?? No AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 61
Depth-limited search = depth-first search with depth limit l ; cutoff no solution within l Recursive implementation function Depth-Limited-Search ( problem , limit ) returns slnt/fail/cutoff return Recursive-DLS ( Make-Node ( problem . Initial-State ), problem , limit ) function Recursive-DLS ( node , problem , limit ) returns slnt/fail/cutoff if problem . Goal-Test ( node . State ) then return Solution ( node ) else if limit =0 then return cutoff else cutoff-occurred? ← false for each action in problem . Action ( node . State ) do child ← Child-Node ( problem , node , action ) result ← Recursive-DLS ( child , problem , limit -1) if result = cutoff then cutoff-occurred? ← true else if result � = failure then return result if cutoff-occurred? then return cutoff else return failure AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 62
Iterative deepening search function Iterative-Deepening-Search ( problem ) returns slnt,or fail for depth =0 to ∞ do result ← Depth-Limited-Search ( problem, depth ) if result � = cutoff then return result end AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 63
Iterative deepening search l = 0 Limit = 0 A A AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 64
Iterative deepening search l = 1 Limit = 1 A A A A B C B C B C B C AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 65
Iterative deepening search l = 2 Limit = 2 A A A A B C B C B C B C D E F G D E F G D E F G D E F G A A A A B C B C B C B C D E F G D E F G D E F G D E F G AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 66
Iterative deepening search l = 3 Limit = 3 A A A A B C B C B C B C D E F G D E F G D E F G D E F G H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O A A A A B C B C B C B C D E F G D E F G D E F G D E F G H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O A A A A B C B C B C B C D E F G D E F G D E F G D E F G H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 67
Properties of iterative deepening search Complete?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 68
Properties of iterative deepening search Complete?? Yes Time?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 69
Properties of iterative deepening search Complete?? Yes Time?? ( d + 1) b 0 + db 1 + ( d − 1) b 2 + . . . + b d = O ( b d ) Space?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 70
Properties of iterative deepening search Complete?? Yes Time?? ( d + 1) b 0 + db 1 + ( d − 1) b 2 + . . . + b d = O ( b d ) Space?? O ( bd ) Optimal?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 71
Properties of iterative deepening search Complete?? Yes Time?? ( d + 1) b 0 + db 1 + ( d − 1) b 2 + . . . + b d = O ( b d ) Space?? O ( bd ) Optimal?? Yes, if step cost = 1 Can be modified to explore uniform-cost tree Numerical comparison for b = 10 and d = 5 , solution at far right leaf: N ( IDS ) = 50 + 400 + 3 , 000 + 20 , 000 + 100 , 000 = 123 , 450 N ( BFS ) = 10 + 100 + 1 , 000 + 10 , 000 + 100 , 000 + 999 , 990 = 1 , 111 , 100 IDS does better because other nodes at depth d are not expanded BFS can be modified to apply goal test when a node is generated AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 72
Bidirection search Idea: run two simultanaeous searches – hoping that two searches meet in the middle – one forward from the initial state – another backward from the goal 2 b d/ 2 is much less than b d Implementation : check to see whether the frontiers of the two searches intersect; – if they do, a solution has been found The first solution found may not be optimal; some additional search is required to make there is not another short-cut across the gap Both-ends-against-the-middle (BEATM) endeavors to combine the best features of top-down and bottom-up designs into one process AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 73
Summary of algorithms Criterion Breadth- Uniform- Depth- Depth- Iterative First Cost First Limited Deepening Yes ∗ Yes ∗ Complete? No Yes, if l ≥ d Yes b ⌈ C ∗ /ǫ ⌉ b d +1 b m b l b d Time b ⌈ C ∗ /ǫ ⌉ b d +1 Space bm bl bd Yes ∗ Yes ∗ Optimal? Yes No No AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 74
Graph search: repeated states Failure to detect repeated states can turn a linear problem into an exponential one A A B B B C C C C C D d + 1 states space ⇒ 2 d paths All the tree-search versions of algorithms can be extended to the graph-search versions by checking the repeated states AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 75
Graph search function Graph-Search ( problem ) returns a solution, or failure initialize the frontier using the initial state of problem initialize the explored set to empty loop do if the frontier is empty then return failure choose a leaf node and remove it from the frontier if the node contains a goal state then return the corresponding solution add the node to the explored set expand the chosen node and add the resulting nodes to the frontier only if not in the frontier or explored set Note: using explored set to avoid exploring redundant paths AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 76
Heuristic Search Informed ( heuristic ) strategies use problem-specific knowledge to find solution more efficiently Best-first search: use an evaluation function for each node – Eval-Fn : estimate of “desirability” ⇒ Expand most desirable unexpanded node Implementation QueueingFn = insert successors in decreasing order of desirability Special cases – greedy (best-first) search – A ∗ search AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 77
Best-first search function Best-First-Search ( problem, Eval-Fn ) returns a solution sequence inputs : problem , a problem Eval-Fn , an evaluation function Queueing-Fn ← a function that orders nodes by Eval-Fn return General-Search ( problem, Queueing-Fn ) AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 78
Romania with step costs in km Straight−line distance Oradea to Bucharest 71 Neamt Arad 366 Bucharest 0 87 Zerind 151 Craiova 160 75 Dobreta Iasi 242 Arad Eforie 161 140 92 Fagaras 178 Sibiu Fagaras 99 Giurgiu 77 118 Hirsova 151 Vaslui 80 Iasi 226 Rimnicu Vilcea Lugoj 244 Timisoara Mehadia 241 142 211 111 Neamt 234 Pitesti 97 Lugoj Oradea 380 70 98 Pitesti 98 Hirsova 85 146 101 Rimnicu Vilcea 193 Mehadia Urziceni Sibiu 86 253 75 138 Bucharest Timisoara 329 120 Dobreta Urziceni 80 90 Vaslui Craiova 199 Eforie Giurgiu Zerind 374 AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 79
Greedy search Evaluation function h ( n ) ( h euristic) = estimate of cost from n to the closest goal E.g., h SLD ( n ) = straight-line distance from n to Bucharest Greedy search expands the node that appears to be closest to goal AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 80
Greedy search example Arad 366 AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 81
Greedy search example Arad Sibiu Timisoara Zerind 253 329 374 AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 82
Greedy search example Arad Sibiu Timisoara Zerind 329 374 Arad Fagaras Oradea Rimnicu Vilcea 366 176 380 193 AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 83
Greedy search example Arad Sibiu Timisoara Zerind 329 374 Arad Fagaras Oradea Rimnicu Vilcea 366 380 193 Sibiu Bucharest 253 0 AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 84
Properties of greedy search Complete?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 85
Properties of greedy search Complete?? No – can get stuck in loops, e.g., with Oradea as goal, Iasi → Neamt → Iasi → Neamt → ( h SLD ( n ) ) Complete in finite space with repeated-state checking Time?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 86
Properties of greedy search Complete?? No–can get stuck in loops, e.g., Iasi → Neamt → Iasi → Neamt → Complete in finite space with repeated-state checking Time?? O ( b m ) , but a good heuristic can give dramatic improvement Space?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 87
Properties of greedy search Complete?? No–can get stuck in loops, e.g., Iasi → Neamt → Iasi → Neamt → Complete in finite space with repeated-state checking Time?? O ( b m ) , but a good heuristic can give dramatic improvement Space?? O ( b m ) —keeps all nodes in memory Optimal?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 88
Properties of greedy search Complete?? No–can get stuck in loops, e.g., Iasi → Neamt → Iasi → Neamt → Complete in finite space with repeated-state checking Time?? O ( b m ) , but a good heuristic can give dramatic improvement Space?? O ( b m ) —keeps all nodes in memory Optimal?? No AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 89
A ∗ search Idea: avoid expanding paths that are already expensive Evaluation function f ( n ) = g ( n ) + h ( n ) g ( n ) = cost so far to reach n h ( n ) = estimated cost to goal from n f ( n ) = estimated total cost of path through n to goal Algorithm: identical to Uniform-Cost-Search except for using g + h instead of g A ∗ search uses an admissible heuristic i.e., h ( n ) ≤ h ∗ ( n ) where h ∗ ( n ) is the true cost from n (Also require h ( n ) ≥ 0 , so h ( G ) = 0 for any goal G ) E.g., h SLD ( n ) never overestimates the actual road distance Theorem: A ∗ search is optimal AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 90
A ∗ search example Arad 366=0+366 AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 91
A ∗ search example Arad Sibiu Timisoara Zerind 393=140+253 447=118+329 449=75+374 AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 92
A ∗ search example Arad Sibiu Timisoara Zerind 447=118+329 449=75+374 Arad Fagaras Oradea Rimnicu Vilcea 646=280+366 415=239+176 671=291+380 413=220+193 AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 93
A ∗ search example Arad Sibiu Timisoara Zerind 447=118+329 449=75+374 Arad Fagaras Oradea Rimnicu Vilcea 646=280+366 415=239+176 671=291+380 Craiova Pitesti Sibiu 526=366+160 417=317+100 553=300+253 AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 94
A ∗ search example Arad Sibiu Timisoara Zerind 447=118+329 449=75+374 Arad Fagaras Oradea Rimnicu Vilcea 646=280+366 671=291+380 Sibiu Bucharest Craiova Pitesti Sibiu 526=366+160 417=317+100 591=338+253 450=450+0 553=300+253 AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 95
A ∗ search example Arad Sibiu Timisoara Zerind 447=118+329 449=75+374 Fagaras Rimnicu Vilcea Arad Oradea 646=280+366 671=291+380 Sibiu Bucharest Craiova Pitesti Sibiu 526=366+160 591=338+253 450=450+0 553=300+253 Bucharest Craiova Rimnicu Vilcea 418=418+0 615=455+160 607=414+193 AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 96
Optimality of A ∗ Suppose some suboptimal goal G 2 has been generated and is in the queue. Let n be an unexpanded node on a shortest path to an optimal goal G Start n G G 2 f ( G 2 ) = g ( G 2 ) since h ( G 2 ) = 0 > g ( G ) since G 2 is suboptimal ≥ f ( n ) since h is admissible Since f ( G 2 ) > f ( n ) , A ∗ will never select G 2 for expansion AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 97
Optimality of A ∗ Lemma: A ∗ expands nodes in order of increasing f value ∗ Gradually adds “ f -contours” of nodes (cf. breadth-first adds layers) Contour i has all nodes with f = f i , where f i < f i +1 O N Z I A 380 S F V 400 T R P L H M U B 420 D E C G AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 98
Heuristic consistency A heuristic is consistent if h ( n ) ≤ c ( n, a, n ′ ) + h ( n ′ ) n c(n,a,n’) If h is consistent, we have h(n) n’ f ( n ′ ) = g ( n ′ ) + h ( n ′ ) = g ( n ) + c ( n, a, n ′ ) + h ( n ′ ) h(n’) ≥ g ( n ) + h ( n ) G = f ( n ) I.e., f ( n ) is nondecreasing along any path (proof of the lemma) Note – the consistency is stronger than the admissibility – the graph-search version of A ∗ is optimal if h ( n ) is consistent – the inconsistent heuristics can be effective by enhancemence AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 99
Properties of A ∗ Complete?? AI Slides (5e) c � Lin Zuoquan@PKU 2003-2019 3 100
Recommend
More recommend