You are on page 1of 25

# Artiﬁcial Intelligence (Heuristic Search

)
Email: kr.chowdhary@ieee.org
Department of Computer Science and Engineering MBM Engineering College, Jodhpur

May 14, 2011

kr chowdhary

heuristic search

1/ 25

Heuristic deﬁnition

Heuristic, adj. 1. Serving to promote discovery or learning; – used especially of theories or paradigms which stimulate new ideas for discovering facts in experimental sciences. 2. Pertaining to or based on trial-and-error and experimental methods of learning and evaluation. 3. (Computers) Based on the use of an eﬃcient trial-and error method to search a space of possible solutions to a problem, or to ﬁnd an acceptable approximate solution, when an exact algorithmic method is unavailable or too time-consuming. Heuristic, n. A theory or approach which serves to promote discovery or learning by encouraging experimentation.

kr chowdhary

heuristic search

2/ 25

Heuristic techniques can be eﬀective if applied correctly on the right kinds of tasks.Heuristic Search Techniques Direct techniques (blind search) are not always possible (they require too much time or memory). Typically require domain speciﬁc information. Figure: Initial and ﬁnal states of 8-puzzle game kr chowdhary heuristic search 3/ 25 .

What heurisitic(s) can we use to decide which 8-puzzle move is “best”(worth considering ﬁrst). kr chowdhary heuristic search 4/ 25 . Figure: Heuristic search.a heuristic.Heuristic search techniques make use of domain speciﬁc information . .Blind search techniques used an arbitrary ordering (no priority) of operations. .Heuristic Search Techniques 8 Puzzle Heuristics: .

. For now . Later . which when applied on a state as argument.we will worry about the actual values returned by the heuristic function.8-puzzle Heuristic Heuristic techniques use a heuristic function. . . Number of tiles in the correct position. kr chowdhary heuristic search 5/ 25 .Easy to compute (fast and takes little memory).The higher the number the better. return a value indicting how close this state is to the goal.Probably the simplest possible heuristic.we just want to establish some ordering to the possible moves (the values of our heuristic does not matter as long as it ranks the moves).

.Is this heuristic more than a heuristic (is it always correct?).Given any two states. does it always order them properly with respect to the minimum number of moves away from a solution? kr chowdhary heuristic search 6/ 25 . .The “best”move is the one with the lowest number returned by the heuristic.8-puzzle Heuristic: another approach Number of tiles in the incorrect position. .This can also be considered a lower bound on the number of moves from a solution! .

Sum up this count over all the tiles.8-puzzle Heuristic: another approach Count how far away (how many tile movements) each tile is from it’s correct position. Figure: Heuristic search. This is another estimate on the number of moves away from a solution. kr chowdhary heuristic search 7/ 25 .

kr chowdhary heuristic search 8/ 25 .do while goal not accomplished .the quality (accuracy) of the heuristic is important in real-life application of the technique! Generate-and-test: Very simple strategy .just keep guessing. In all cases .test solution to see if it is a goal Heuristics may be used to determine the speciﬁc rules for solution generation. .Heuristic search techniques There are a variety of search techniques that rely on the estimate provided by a function.generate a possible solution .

Want to know the shortest route that visits all the cities once. n=80 will take millions of years to solve exhaustively! Figure: TSP kr chowdhary heuristic search 9/ 25 .Traveling Salesman Problem (TSP) Traveler needs to visit n cities.Heuristic search techniques Example . Know the distance between each pair of cities.

TSP Figure: TSP kr chowdhary heuristic search 10/ 25 .

. kr chowdhary heuristic search 11/ 25 .generation of next state depends on feedback from the test procedure. . Simple Hill Climbing: .Use heuristic to move only to states that are better than the current state.TSP Hill Climbing: Variation on generate-and-test: .Test now includes a heuristic function that provides a guess as to how good each possible state is.The process ends when all operators have been applied and none of the resulting states are better than the current state.Always move to better state when possible. .There are a number of ways to use the information returned by the test procedure. .

The order of application of operators can make a big diﬀerence.Hill climbing Potential Problems with Simple Hill Climbing: . kr chowdhary heuristic search 12/ 25 .TSP . . . Figure: Hill Climbing Simple Hill Climbing Example: .Cannot see past a single move in the state space. .Will terminate when at local optimum.Heuristic function is the length of a tour.Operators exchange the position of adjacent cities within the current tour. .deﬁne state space as the set of all possible tours.

Hill climbing Hill climbing: Figure: Hill Climbing kr chowdhary heuristic search 13/ 25 .

A variation on simple hill climbing. .Not just climbing to a better state. . move to the best possible state that is one move away. .Hill climbing Steepest-Ascent Hill Climbing . climbing up the steepest slope.Instead of moving to the ﬁrst state that is better. kr chowdhary heuristic search 14/ 25 .The order of operators does not matter.

Hill Climbing Termination . Heuristic Dependence .Ridge .Local Optimum: all neighboring states are worse or the same. .Plateau . or can use other means to arrive at a value for a state. . . kr chowdhary heuristic search 15/ 25 . .local optimum that is caused by inability to apply 2 operators at once.The heuristic can look ahead many states.The heuristic used by a hill climbing algorithm does not need to be a static function of a single state.all neighboring states are the same as the current state.Hill climbing is based on the value assigned to states by the heuristic function.

2. do not need to generate all competing paths. kr chowdhary heuristic search 16/ 25 . Best First Search: explore the most promising path seen so far. .DFS: follows a single path. While goal not reached: 1.BFS: does not get caught in loops or dead-end-paths. Similar to steepest-ascent. . Generate all potential successor states and add to a list of states. but do not throw away states that are not chosen.Best-First Search Combines the advantages of Breadth-First and Depth-First searches. Pick the best state in the list and go to it.

else { generate children of X. for each child of X do case { the child is not on open or closed: { assign the child a heuristic value. call it X. } the child is already on open: { if this child was reached by a shorter path then give the state on open the shorter path } kr chowdhary heuristic search 17/ 25 . % Initialize closed := [].Best-First Search procedure best_first_search { open := [Start]. while open != [] do { % While states remai remove the leftmost state from open. add the child to open. if X = goal then return path from Start to X.

re-order states on open by heuristic merit (best leftmost) } % else } % while return failure % open is empty } % best_first kr chowdhary heuristic search 18/ 25 . add this child to open.Best-First Search the child is already on closed: { if this child was reached by a shorter path { then remove the state from closed. } } } % cases put X on closed.

start out allowing large downhill moves (to much worse states) and gradually allow only small downhill moves.Simulated Annealing Based on physical process of annealing a metal to get the best (minimal energy) state.allow some moves downhill (to worse states) . The search initially jumps around a lot. exploring many regions of the state space. Hill climbing with a twist: . Figure: Simulated Anealing kr chowdhary heuristic search 19/ 25 . The jumping is gradually reduced and the search becomes a simple hill climb (search for local optimum).

A* Algorithm (a sure test topic) The A* algorithm uses a modiﬁed evaluation function and a Best-First search. h′ (x) is the estimated cost to get from state x to the goal state (the heuristic). kr chowdhary heuristic search 20/ 25 .The evaluation function f is an estimate of the value of a node x given by: f (x) = g (x) + h′ (x) g (x) is the cost to get from the start state to state x. Under the right conditions A* provides the cheapest cost solution in the optimal time! A* evaluation function . A* minimizes the total path cost.

but is useful for Best-First Search. Modiﬁed State Evaluation: Value of each state is a combination of: ..A* Algorithm (a sure test topic) contd. This does not make sense for DFS or BFS. The idea is to use the path to a state to determine (partially) the rank of the state when compared to other states.estimated cost of reaching a goal from the state.the cost of the path to the state . kr chowdhary heuristic search 21/ 25 .

A* Algorithm 1. . .Best First Search with the modiﬁed evaluation function.A* Algorithm The general idea is: . kr chowdhary heuristic search 22/ 25 . If x is not goal state: generate all possible children of x (and save path information with each node). While queue not empty and goal not found: get best state x from the queue.loops are avoided . .h’(x) is an estimate of the number of steps from state x to a goal state.Information about the path to the goal state is retained. Create a priority queue of search nodes (initially the start state). Apply f to each new node and add to queue. Remove duplicates from queue (using f to pick the best). Priority is determined by the function f 2.we do not expand the same state twice.

Maze kr chowdhary heuristic search 23/ 25 .A* Algorithm Figure: Example .

A* Algorithm Figure: Example .Maze kr chowdhary heuristic search 24/ 25 .

A* can use lot of memory. . A* will run put of memory. where n is total count of states.For really big search spaces. demerits: .Merits and demerits of Astar merits: .A* is guaranteed to terminate. kr chowdhary heuristic search 25/ 25 . in principle O(n).