BFS, DFS, Greedy Search
Total Page:16
File Type:pdf, Size:1020Kb
Introduction to Artificial Intelligence Problem Solving through Search (Goal-based agents) BFS, DFS, Greedy Search Janyl Jumadinova September 12-16, 2016 Example: Romania On holiday in Romania; currently in Arad. Flight leaves tomorrow from Bucharest Formulate goal: be in Bucharest Formulate problem: states: various cities actions: drive between cities Find solution: sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest 2/38 Example: Romania 3/38 Tree search algorithms Basic idea: offline, simulated exploration of state space by generating successors of already-explored states (a.k.a. expanding states) 4/38 Tree search example 5/38 Tree search example 6/38 Tree search example 7/38 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 includes parent, children, depth, path cost g(x) States do not have parents, children, depth, or path cost! 8/38 Breadth-first search Expand shallowest unexpanded node I FIFO queue, i.e., new successors go at end A B C D E F G 9/38 Breadth-first search Expand shallowest unexpanded node I FIFO queue, i.e., new successors go at end A B C D E F G 10/38 Breadth-first search Expand shallowest unexpanded node I FIFO queue, i.e., new successors go at end A B C D E F G 11/38 Breadth-first search Expand shallowest unexpanded node I FIFO queue, i.e., new successors go at end A B C D E F G 12/38 Breadth-first search Arad 13/38 Breadth-first search Arad Zerind Sibiu Timisoara 14/38 Breadth-first search Arad Zerind Sibiu Timisoara Arad Oradea 15/38 Breadth-first search Arad Zerind Sibiu Timisoara Rimnicu Arad Oradea Arad Oradea Fagaras Vilcea Arad Lugoj 16/38 Breadth-first search 17/38 Depth-first search Expand deepest unexpanded node I LIFO queue, i.e., put successors at front Arad 18/38 Depth-first search Expand deepest unexpanded node I LIFO queue, i.e., put successors at front Arad Zerind Sibiu Timisoara 19/38 Depth-first search Expand deepest unexpanded node I LIFO queue, i.e., put successors at front Arad Zerind Sibiu Timisoara Arad Oradea 20/38 Depth-first search Expand deepest unexpanded node I LIFO queue, i.e., put successors at front Arad Zerind Sibiu Timisoara Arad Oradea Zerind Sibiu Timisoara 21/38 ) Expand most desirable unexpanded node Implementation: a queue sorted in decreasing order of desirability Special cases: greedy search, A∗ search Best-first search Idea: use an evaluation function for each node { estimate of \desirability" 22/38 Implementation: a queue sorted in decreasing order of desirability Special cases: greedy search, A∗ search Best-first search Idea: use an evaluation function for each node { estimate of \desirability" ) Expand most desirable unexpanded node 22/38 Special cases: greedy search, A∗ search Best-first search Idea: use an evaluation function for each node { estimate of \desirability" ) Expand most desirable unexpanded node Implementation: a queue sorted in decreasing order of desirability 22/38 Best-first search Idea: use an evaluation function for each node { estimate of \desirability" ) Expand most desirable unexpanded node Implementation: a queue sorted in decreasing order of desirability Special cases: greedy search, A∗ search 22/38 Romania with step costs in km Straight−line distance Oradea 71 to Bucharest Neamt Arad 366 87 Bucharest 0 Zerind 75 151 Craiova 160 Iasi Dobreta 242 Arad 140 Eforie 161 92 Fagaras 178 Sibiu Fagaras 99 Giurgiu 77 118 Hirsova 80 Vaslui 151 Iasi 226 Rimnicu Vilcea Timisoara Lugoj 244 142 Mehadia 241 111 211 Neamt 234 Lugoj 97 Pitesti Oradea 380 70 98 Pitesti 98 146 85 Hirsova Mehadia 101 Urziceni Rimnicu Vilcea 193 75 138 86 Sibiu 253 Bucharest Timisoara 120 329 Dobreta 90 Urziceni 80 Craiova Eforie Vaslui 199 Giurgiu Zerind 374 A* slide 23/38 I Greedy search expands the node that appears to be closest to goal Greedy search Evaluation function h(n)(heuristic) = estimate of cost from n to the closest goal Example: h(n) = straight-line distance from n to Bucharest 24/38 Greedy search Evaluation function h(n)(heuristic) = estimate of cost from n to the closest goal Example: h(n) = straight-line distance from n to Bucharest I Greedy search expands the node that appears to be closest to goal 24/38 Greedy Search Arad 366 25/38 Greedy Search Arad Sibiu Timisoara Zerind 253 329 374 26/38 Greedy Search Arad Sibiu Timisoara Zerind 329 374 Arad Fagaras Oradea Rimnicu Vilcea 366 176 380 193 27/38 Greedy Search Arad Sibiu Timisoara Zerind 329 374 Arad Fagaras Oradea Rimnicu Vilcea 366 380 193 Sibiu Bucharest 253 0 28/38 Greedy search I Can get stuck in loops, e.g., Iasi ! Neamt ! Iasi ! Neamt ! Complete in finite space with repeated-state checking I A good heuristic can give dramatic improvement in search cost 29/38 http://aispace.org/search/ Explore Best first search (explanation from AIspace: http://www.aispace.org/deduction/help/tut3.shtml) 30/38 I Evaluation function f (n) = g(n) + h(n) I g(n) = cost so far to reach n I h(n) = estimated cost to goal from n I f (n) = estimated total cost of path through n to goal Romania with step costs A* search Idea: avoid expanding paths that are already expensive 31/38 A* search Idea: avoid expanding paths that are already expensive I Evaluation function f (n) = g(n) + h(n) I g(n) = cost so far to reach n I h(n) = estimated cost to goal from n I f (n) = estimated total cost of path through n to goal Romania with step costs 31/38 Example: Romania 32/38 A* Search Arad 366=0+366 33/38 A* Search Arad Sibiu Timisoara Zerind 393=140+253 447=118+329 449=75+374 34/38 A* Search Arad Sibiu Timisoara Zerind 447=118+329 449=75+374 Arad Fagaras Oradea Rimnicu Vilcea 646=280+366415=239+176 671=291+380 413=220+193 35/38 A* Search 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 36/38 A* Search 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 591=338+253 450=450+0 526=366+160 417=317+100 553=300+253 37/38 A* Search 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 591=338+253 450=450+0 526=366+160 553=300+253 Bucharest Craiova Rimnicu Vilcea 418=418+0 615=455+160 607=414+193 38/38.