CS414-Artificial Intelligence Lecture 6: Informed Search Algorithms Waheed Noor Computer Science and Information Technology, University of Balochistan, Quetta, Pakistan Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 1 / 30
Outline 1 Informed Search 2 Best First Search A* Search Example More on Heuristic Reading 3 Hill-Climbing Search Readings Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 2 / 30
Outline 1 Informed Search 2 Best First Search A* Search Example More on Heuristic Reading 3 Hill-Climbing Search Readings Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 3 / 30
Informed Search What we have seen so far are all those search algorithms that operate with out any domain knowledge, and try to solve the problem in brute-force fashion. Such methods are insufficient for most problems specially when the problem is large and complex. Now we will look into another type of search techniques called informed search. Definition Informed Search Incorporates a heuristic in the search that determines the quality of any state in the search space. In a graph search, this results in a strategy for node expansion. The heuristic may consider the problem knowledge to guide the search strategy. Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 4 / 30
Outline 1 Informed Search 2 Best First Search A* Search Example More on Heuristic Reading 3 Hill-Climbing Search Readings Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 5 / 30
Best First Search I Best-FS tries to minimize some estimated measure (evaluation function) of the cost of the solution. Generally, in Best-FS, state space is evaluated on the basis of an evaluation function f (n) that incorporates an estimate of the measure of the cost of the path from the current state to the closest goal. Then the Best-FS may follow two strategies: 1 Greedy Search: Expands the node closest to the goal, i.e., f (n) = h(n). 2 A Search: Expands the node on the least cost solution path, i.e., f (n) = g(n) + h(n). Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 6 / 30
Best First Search II where h(n) is heuristic function and g(n) is estimated path-cost from start node to current node n. The h(n) can be an educated guess or estimate of the cheapest path from the state at node n to the goal. In Romania example, this may be a straight line between state at node n to goal. The g(n) is the cost from the start node to node n. The algorithm is often implemented by maintaining two list, an open one and a closed one. Open list is a priority queue consist nodes yet to be visited sorted by their evaluation function. Closed list contains nodes that have already been evaluated. Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 7 / 30
Best First Search III Best-FS specializes to BFS when f (n) = h(n) and to UCS when f (n) = g(n). Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 8 / 30
An Example Consider again the Romania example Oradea 71 Neamt 87 Zerind 75 151 Iasi Arad 140 92 Sibiu 99 Fagaras 118 80 Vaslui Timisoara Rimnicu Vilcea 111 142 211 Lugoj 97 Pitesti 70 98 146 Hirsova Mehadia 101 85 Urziceni 75 138 86 Bucharest 120 Dobreta 90 Craiova Eforie Giurgiu Straight line distance to Bucharest Arad 366 Bucharest 0 Craiova 160 Dobreta 242 Eforie 161 Fagaras 178 Giurgiu 77 Hirsova 151 Iasi 226 Lugoj 244 Mehadia 241 Neamt 234 Oradea 380 Pitesti 98 Rimnicu Vilcea 193 Sibiu 253 Timisoara 329 Urziceni 80 Vaslui 199 Zerind 374 Figure : Romania map with SLD Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 9 / 30
Greedy Fashion (a) The initial state (b) After expanding Arad Arad 366 Arad Sibiu Timisoara Zerind 253 329 374 (c) After expanding Sibiu Arad Sibiu Timisoara Zerind 329 374 Arad Fagaras Oradea Rimnicu Vilcea 366 176 380 193 (d) After expanding Fagaras Arad Sibiu Timisoara Zerind 329 374 Arad Fagaras Oradea Rimnicu Vilcea 366 380 193 Sibiu Bucharest 253 0 Figure : In the greedy fashion Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 10 / 30
Outline 1 Informed Search 2 Best First Search A* Search Example More on Heuristic Reading 3 Hill-Climbing Search Readings Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 11 / 30
Waheed Noor (CS&IT, UoB, Quetta) Figure : CS414-Artificial The A* implementation Intelligence August 2015 12 / 30 A* Search Example (a) The initial state (b) After expanding Arad Arad 366=0+366 Arad Sibiu 393=140+253 Timisoara Zerind 447=118+329 449=75+374 (c) After expanding Sibiu 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 (d) After expanding Rimnicu Vilcea 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 (e) After expanding Fagaras Arad Sibiu Timisoara Zerind 447=118+329 449=75+374 Arad 646=280+366 Fagaras Oradea 671=291+380 Rimnicu Vilcea Sibiu Bucharest Craiova Pitesti Sibiu 591=338+253 450=450+0 526=366+160 417=317+100 553=300+253 (f) After expanding Pitesti Arad Sibiu Timisoara Zerind 447=118+329 449=75+374 Arad 646=280+366 Fagaras Oradea 671=291+380 Rimnicu Vilcea Sibiu Bucharest Craiova Pitesti Sibiu 526=366+160 553=300+253 591=338+253 450=450+0 Bucharest Craiova Rimnicu Vilcea 418=418+0 615=455+160 607=414+193
Class Activity Apply A & Greedy Best-FS on following problem Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 13 / 30
A* Search A* Search Rating Complete: Yes Time Complexity: O(b d ) Space Complexity: O(b d ) Optimal: Yes. A* search algorithm have two flavors, the graph based and tree based. Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 14 / 30
Conditions for Optimality Admissibility and Consistency Admissibility: That the heuristic is admissible i.e., that h(n) will never overestimate the cost to reach the goal. For A*, h(n) is admissible, since straight line is the shortest path between any two points. Consistent: Consistency (also called monotonicity) describes that the cost along the path is increasing or decreasing. For A* graph version, the h(n) needs to be the increasing function of n along the path to goal, i.e., h(n) < c(n, a, n ) + h(n ). The A* tree search is optimal when h(n) is admissible. The A* graph search is optimal when h(n) is consistent. Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 15 / 30
Outline 1 Informed Search 2 Best First Search A* Search Example More on Heuristic Reading 3 Hill-Climbing Search Readings Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 16 / 30
Heuristic for 8-Puzzle 7 2 4 51 2 3 5 6 4 5 6 8 3 1 7 8 Start State Goal State What possible heuristic h(n) you can propose? Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 17 / 30
Two Possible Heuristic for 8-Puzzle h 1 One possibility can be to count the number of misplaced tiles in the current state n than the goal state. For initial state given above h 1 (n) = 6. Maximum possible h 1 (n) = 8, since there are eight tiles. Is h 1 admissible? h 2 Second possibility can be the sum of the distance of tiles in the current state n from their goal. As the tiles in this problem can not move diagonal, they can either move horizontal or vertical therefore, this distance will be the count of horizontal and vertical distance/steps. This is also called Manhattan distance. The Manhattan distance from 1 to 8 for above problem start state is: Is h 2 admissible? h 2 (n) = 4 + 0 + 3 + 3 + 1 + 0 + 2 + 1 Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 18 / 30
Outline 1 Informed Search 2 Best First Search A* Search Example More on Heuristic Reading 3 Hill-Climbing Search Readings Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 19 / 30
Reading Read about Recursive best-first search (RBFS) and try on the Romania map example to develop your understanding. Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 20 / 30
Outline 1 Informed Search 2 Best First Search A* Search Example More on Heuristic Reading 3 Hill-Climbing Search Readings Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 21 / 30
Hill-Climbing Search An iterative algorithm that tries to find maximum (or minimum) value of an objective/evaluation function. In each iteration it moves towards the direction of increasing value. Unlike Best-First, it does not maintain a search tree and uses current state node and its immediate neighbors. Each time it follows a single node and hence its OPEN list contain only one node. It is also sometime called a greedy local search. Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 22 / 30
Hill-Climbing Search objective function global maximum shoulder local maximum "flat" local maximum current state state space Problems: Since hill-climbing search considers immediate neighbor state that is its local, therefore it may end-up with a local optimal solution, i.e., local maximum(or minimum) rather than global optimum solution. Solution: Random restart sometime solve the problem of local optimum. Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 23 / 30
Ridges and Plateau Ridges: Result in the a series of local optima and it is very difficult for greedy algorithm to overcome. Plateau: A plateau is the flat area of the state space with respect to the objective function. It can be a flat local optimum, for which no uphill exist or a shoulder where progress is possible. The hill-climbing may get lost in plateau, one possible solution can be to allow progress sideways, if plateau is shoulder. If plateau is flat local optima then it may result in an infinite loop, so we can then limit the number of sideway moves. Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 24 / 30
An Example h = 5 h = 2 h = 0 Figure : 4-Queen starting from state with heuristic cost estimate of h(n) = 4 In this problem our heuristic can be the number of conflicts we can observe in the current state. Obviously then our goal is h(n) = 0. The hill-climbing algorithm will often (say 80% of the time for this problem) fails to find the solution. But when the algorithm solve the problem, it is very efficient even in very large state space. Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 25 / 30
Discussion The hill-climbing algorithm explained today is incomplete, since it will often lost in local optima. Multiple restarts (with random initial state in each restart) may solve the problem. If p is the probability of success of hill-climbing algorithm then we need at-least 1/p restarts. It is also not guaranteed to give optimal solution globally. However, local optimal is guaranteed. The time and space complexity both are linear, i.e., O(d) and O(b) respectively. Since the algorithm consider only one state node at a time. Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 26 / 30
Outline 1 Informed Search 2 Best First Search A* Search Example More on Heuristic Reading 3 Hill-Climbing Search Readings Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 27 / 30
Readings You are supposed to read an alternative approach called Simulated Annealing, and discuss in a report the characteristics and comparison of hill climbing and simulated annealing algorithm. Your answer should contain at least 100 words. Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 28 / 30
References I Stuart Russell and Peter Norvig. Artificial Intelligence: A Modern Approach. Pearson Education, Inc, USA, second edition, 2003. George F. Luger. Artificial Intelligence: Structures and Strategies for Complex Problem Solving. Addison-Wesley Publishing Company, USA, 6th edition, 2008. Waheed Noor (CS&IT, UoB, Quetta) CS414-Artificial Intelligence August 2015 29 / 30