Presentation is loading. Please wait.

Presentation is loading. Please wait.

Informed Search (no corresponding text chapter). Recall: Wanted " An algorithm and associated data structure(s) that can: 1) Solve an arbitrary 8-puzzle.

Similar presentations


Presentation on theme: "Informed Search (no corresponding text chapter). Recall: Wanted " An algorithm and associated data structure(s) that can: 1) Solve an arbitrary 8-puzzle."— Presentation transcript:

1 Informed Search (no corresponding text chapter)

2 Recall: Wanted " An algorithm and associated data structure(s) that can: 1) Solve an arbitrary 8-puzzle problem (or problem like it), 2) Do it in a reasonable amount of time and space-- efficiency, 3) Be guaranteed to first find the solution with the minimum number of actions--optimality.

3 Available Algorithms " Breadth-first state space search (BFS) ➢ Pro: optimal ➢ Con: memory inefficient " Depth-first state space search (DFS) ➢ Pro: memory efficient ➢ Con: non-optimal " Solution: A* search, a kind of "informed'' search

4 Informed and Uninformed Search " If a search algorithm makes an attempt to evaluate an item's children by comparing their "goodness'' with respect to the goal, it is informed. " If a search algorithm is not informed, it is uninformed or blind. " BFS and DFS are uninformed " Informed search requires the concept of an evaluation function

5 Evaluation Functions " An evaluation function takes a search space item as an argument and returns a numerical value as its "goodness'' " One type evaluates the strength of a state (as in chess playing programs)--the higher the better " Another type estimates the number of actions required to get to the goal. " Such an evaluation function is also called a "heuristic'' " The smaller an item's heuristic, the better

6 Heuristic for the 8-puzzle " If n is an item in the 8-puzzle state space, consider: ➢ h(n) = m, where m is the number of tiles out of place " h estimates, but does not overestimate, the number of actions required to get to the goal g " Note that h(g) = 0

7 8-puzzle Heuristic Function: Number of Misplaced Tiles 283 164 75 283 14 765 23 184 765 23 184 765 123 84 765 123 84 765 up left down right 283 164 75 283 164 75 left right 283 64 175 up 283 16 754 4 535 5 3 6 2 1 0 283 14 765 left 3 283 14 765 4 right

8 Recall General Search Algorithm Suppose we added children to the waiting collection on the basis of their heuristic values. Q: What kind of collection should be used? search(root) returns Node or null { waiting.add(root) while (waiting is not empty) { node = waiting.remove() state = node.getState() if (problem.success(state)) return node else { children = expand(node) for each child in children waiting.add(child) } return null }

9 Priority Queues A (regular) queue has first-in, first-out (FIFO) behavior, where items must enter at the rear and leave from the front. In a priority queue items must leave from the front, but they enter on the basis of a priority (key) value. The queue is kept sorted by this value. Examples of priority queues: - CPU process queues - Print queues - Event-driven simulation (traffic flows) - VLSI design (channel routing, pin layout) - Artificial intelligence search algorithms

10 Implementations of Priority Queues Priority Queue Linked ListArrayBinary Heap Implemented as:

11 Array Implementation of Priority Queues Suppose items with keys 1, 3, 4, 7, 8, 9, 10, 14, 16 are to be stored in a priority queue. Array: 134789101416 A 1 NMax Suppose an item with key 2 is added: 134789101416 A 1 Max 2 Thus inserting takes O(N) time: linear

12 Linked List Implementation of Priority Queues 134789101416 L Suppose an item with key 15 is to be added: 134789101416 L 15 Only O(1) (constant) pointer changes required, but it takes O(N) pointer traversals to find the location for insertion.

13 Binary Heap Implementation of Priority Queues A binary heap is a "nearly full" binary tree: 1 34 79810 141615 A binary heap has the property that, for every node other than a leaf, its key value is less than or equal to that of its children (called the Heap Property). Adds and removes: O(log 2 N) time (see java.util.PriorityQueue)

14 Example State Space With Heuristics 1 3452 6789111012 1413 192120 161715 232422 262725 18 28 Goal State 4 3 2 1 0 2 2 2 4 5 3 3

15 "Best-First'' State Space Search ● If the general search algorithm is used on a priority queue where the key value is a heuristic, it is called a "best-first'' search ● "Best-first'' search, despite its name, is not optimal

16 Trace of Best-First Search PQ: ( 1 ) 4532 2 3 4 5 4 PQ: ( ) 10911 5 PQ: ( 32 ) 2 3 3 3 4 5 17 9115 PQ: ( 32 ) 2 3 3 3 4 5 18 9115 PQ: ( 32 ) 1 3 3 3 4 5 28 9115 PQ: ( 32 ) 0 3 3 3 4 5 These links are pointers back to parent created at expansion time

17 Notes On Best-First Search ● Solution path found in the example: – 1  4  10  17  18  28 ● Shortest possible solution: – 1   12  18  28 ● Therefore best-first search is not optimal ● The problem: the heuristic function rates state 4 better than state 5 ● Moral: heuristic functions are not perfect

18 Recall 8-puzzle Heuristic 283 164 75 283 14 765 23 184 765 up 283 164 75 283 164 75 left right 283 64 175 up 283 16 754 left 4 535 5 3 6 283 14 765 3 283 14 765 4 right This state leads to the shortest solution This state may not lead to the shortest solution

19 Forcing an Optimal Solution In Previous Example ● The problem is that 18 is created as a result of expanding 17 instead of 12 ● 12 is preferred to 17 because it is shallower in the state space ● We can force 12 to precede 17 in the PQ by adding a state's depth to its heuristic value before adding it. ● When we order the PQ by key = heuristic + depth, then the search is called A*.

20 Taking Heuristics and Depth Into Account 1 3452 6789111012 1413 192120 161715 232422 262725 18 28 Goal State 4+0 3+1 2+2 1+3 0+4 2+1 2+2 2+3 4+1 5+1 3+2 1+4

21 A* Search 1 4532 10 53 911 2 5 17 39112 12 1739112 18 1739112 28 1739112 4 3 4 5 6 4 4 5 5 5 6 4 5 5 5 5 6 PQ: ( )

22 Notes on A* Search ● Q: What is the solution path? – descended from ● A: 1 → 5 → 12 → 18 → 28 (optimal) ● If A* is used, and the heuristic never overestimates the number of moves required, a shortest solution is guaranteed (theorem). ● The number-of-misplaced-tiles heuristic never overestimates 28 18 12 5 5 1

23 BFS As A Special Case of A* ● Suppose the heuristic function is h(n) = 0 ● Then the priority queue key will be: ➢ h(n) + depth(n) = 0 + depth(n) = depth(n) ● If the children of an item at depth k are added to a priority queue they will go to the end (since they are at depth k+1) ● Therefore all items at depth k will be examined before items at depth k+1= the definition of BFS

24 Some Heuristics Are Better Than Others ● Although the number-of-misplaced-tiles heuristic never overestimates, we could do better without overestimating 283 164 75 283 14 765 23 184 765 up 4 3 3 283 14 765 left 3 283 14 765 4 right This state is better because the 8 is closer to its destination. A more informed heuristic is the sum of the "Manhattan distances'' that the tiles are out of place. 123 84 765 0

25 8-puzzle Heuristic Function: Sum of Manhattan Distances 283 164 75 283 14 765 23 184 765 23 184 765 123 84 765 123 84 765 up left down right 283 164 75 283 164 75 left right 283 64 175 up 283 16 754 5 646 7 3 7 2 1 0 283 14 765 left 5 283 14 765 5 right

26 Comparing Heuristic Functions ● A heuristic h 1 is more informed than another heuristic h 2 if: – For all items n in the search space, h 1 (n)  h 2 (n)  The more informed the heuristic, the fewer items will be expanded  If a heuristic is more informed without overestimating, then it is more efficient as well as optimal  The sum-of-Manhattan-distances heuristic does not overestimate

27 Implementing Heuristics ● Need to add depth and heuristic to Node class as instance variables ● Abstract computeHeuristic(State) method can be added to Problem class; overridden in subclasses ● Depth and heuristic can be computed at expand time (depth of child = 1 + depth of parent) ● Use key = depth + heuristic to insert into priority queue


Download ppt "Informed Search (no corresponding text chapter). Recall: Wanted " An algorithm and associated data structure(s) that can: 1) Solve an arbitrary 8-puzzle."

Similar presentations


Ads by Google