Searching: Where it all begins... CPSC 433 Christian Jacob Dept. of Computer Science Dept. of Biochemistry & Molecular Biology University of Calgary
Problem Solving by Searching 1. Introductory Concepts and Examples 2. Basic Search Techniques 3. Heuristic Search 4. Problem Decomposition and AND/OR Graphs 5. Searching in Games
Problem Solving by Searching 1. Introductory Concepts and Examples 2. Basic Search Techniques 3. Heuristic Search 4. Problem Decomposition and AND/OR Graphs 5. Searching in Games
Problem Solving by Searching 1. Introductory Concepts and Examples a. Problem space b. State space graphs
Problem Spaces A problem space is a complete set of possible states, generated by exploring a! possible steps, which may or may not lead from a given start state to a goal state.
Blocks Rearrangement Problem [Bratko, 2001]
State Space Graph
Components of a State Space Graph Start: description with which to label the start node Operators: functions that transform from one state to another, within the constraints of the search problem Goal condition: state description(s) that correspond(s) to goal state(s)
State Space Graph Start: Goal:
State Space Graph Start: Goal:
State Space Graph Start: Goal:
State Space Graph Start: Goal:
Eight Puzzle Problem Start Goal Start 1: 4 steps Start 2: 5 steps Start 3: 18 steps
Eight Puzzle Problem Start Goal
Rubik s Cube
Chess [Newborn 1997]
What it boils down to: Searching in Graphs
Problem Solving by Searching 1. Introductory Concepts and Examples 2. Basic Search Techniques 3. Heuristic Search 4. Problem Decomposition and AND/OR Graphs 5. Searching in Games
Basic Search Techniques a. Depth-first or backtracking search b. Iterative deepening search c. Breadth-first search
Depth-First Search
Depth First Search: Eight Puzzle Terminal depth = 5
Depth-First Search in Cyclic Graphs Add cycle detection!
Depth-First Search Evaluation Good: Since we don t expand all nodes at a level, space complexity is modest. For branching factor b and depth m, we require b" number of nodes to be stored in memory. However, the worst case is still O(b^m). That is when we are forced to search through the whole tree.
Depth-First Search Evaluation Bad: If you have deep search trees (or infinite!), DFS may end up running off to infinity and not be able to recover. DFS is neither optimal nor complete. - Complete: If there is a solution, it will find it. - Optimal: The best solution is found.
Depth-Limited Search DLS is a modified DFS to avoid its pitfalls: Impose a limit, l, on the maximum depth level. Little changes from DFS, but not optimal. DLS is complete if the limit l we impose is greater than or equal to the depth of our solution space. Time: O(b^l), Space: bl.
Basic Search Techniques a. Depth-first or backtracking search b. Iterative deepening search c. Breadth-first search
Iterative Deepening Search: A Variant of DLS 1 2 3 4 Depth bound
Basic Search Techniques a. Depth-first or backtracking search b. Iterative deepening search c. Breadth-first search
Breadth-First Search
Eight Puzzle: BFS
BFS: Complexity BFS expands from the root, where it expands a fixed number of nodes, say b. On level d = 2 we expand b^2 nodes. On level d = 3 we expand b^3 nodes. Therefore: O(b^d) time complexity All leaf nodes need to be stored in memory. Hence, space complexity = time complexity.
Problem Solving by Searching 1. Introductory Concepts and Examples 2. Basic Search Techniques 3. Heuristic Search 4. Problem Decomposition and AND/OR Graphs 5. Searching in Games
Heuristic Search a. Greedy Search b. Best-First Heuristic Search A*
Greedy Search on a Graph Start 75 A 118 C B 111 140 D E 80 G 99 97 F H 211 101 I Goal State h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 h(n) = straight-line distance heuristic
Greedy Search 75 B State h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 A E C B h=253 329 374 A 118 C 140 E 80 G 99 F 211 111 D 97 H 101 I
Greedy Search B State h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 Total distance = 253 + 178 = 431 h=253 A E C B A F G 75 h = 366 h = 178 h = 193 A 118 C 111 140 D E 80 G 99 97 F H 211 101 I A E F h = 253 h = 178
Greedy Search 75 A 118 C B 111 140 D State E 80 h(n) A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 G 99 97 F Total distance =253 + 178 + 0 =431 H 211 101 I A h = 253 E h =366 h=178 h=193 h = 253 E F h = 0 A E F I I A C G h = 253 h = 178 h = 0 B
Greedy Search: Optimal? State h(n) B A 366 B 374 C 329 D 244 E 253 F 178 G 193 H 98 I 0 Cost(A E F I )= 431 Cost(A E G H I) = 418 75 A 118 C 140 E 80 G 99 F 211 111 D 97 H 101 I
Greedy Search: Complete? Straight-line distance A B h(n) 6 5 A Greedy search is incomplete. C D 7 0 B Starting node Worst-case time complexity: O(b^m) Target node D C
Heuristic Search a. Greedy Search b. Best-First Heuristic Search A*
A* Best-First Heuristic Search f(n) = g(n) + h(n) g(n): cost so far up to node & h: heuristic estimator from node n to the goal '
A* Example start g h
A* Example start Activate-deactivate Process 1 Process 2
A* Example start Activate-deactivate Process 1 Process 2
A* Example start Activate-deactivate Process 1 Process 2
A* Example start Activate-deactivate Process 1 Process 2
A* Example start Activate-deactivate Process 1 Process 2
A* Example start Activate-deactivate Process 1 Process 2
A* Example start Activate-deactivate Process 1 Process 2
A* Example start Activate-deactivate Process 1 Process 2
Problem Solving by Searching 1. Introductory Concepts and Examples 2. Basic Search Techniques 3. Heuristic Search 4. Problem Decomposition and AND/OR Graphs 5. Searching in Games
AND/OR Graphs OR AND AND
AND/OR Solution Tree(s) Solution Tree T: OR AND The original problem P is the root node of T. If P is an OR node then exactly one of its successors (in the AND/OR graph), together with its own solution tree, is in T. If P is an AND node, then all of its successors (in the AND/OR graph), together with their solution trees, are in T.
Solution Tree: Example Solution Tree 1
Solution Tree: Example Solution Tree 2
Route Problem
Route Problem
Route Problem
Route Problem............
Problem Solving by Searching 1. Introductory Concepts and Examples 2. Basic Search Techniques 3. Heuristic Search 4. Problem Decomposition and AND/OR Graphs 5. Searching in Games
Chess Us to move Opponent to move Us to move
Two-Person Game AND/OR Graph OR AND
Searching in Games a. Minimax Strategy b. Pruning c. Chance
Minimax Strategy Our possible configurations 3 12 8 2 4 6 14 5 2... Opponent s possible configurations Evaluations of configurations
Minimax Strategy 3 2 2 Our possible configurations 3 12 8 2 4 6 14 5 2 Opponent s possible configurations
Minimax Strategy 3 3 2 2 Our possible configurations 3 12 8 2 4 6 14 5 2 Opponent s possible configurations
Chess Search Tree Structure
Searching in Games a. Minimax Strategy b. Pruning c. Chance
Speedup through Pruning 3... 3 2 2 3 12 8 2 4 6 14 5 2
Speedup through Pruning 3... 3 2 2 3 12 8 2 4 6 14 5 2
Speedup through Pruning 3... A2 is worth at most 2 to MAX 3 2 2 3 12 8 2 4 6 14 5 2
Speedup through Pruning 3 2 2 3... A2 is worth at most 2 to MAX 3 12 8 2 4 6 14 5 2
Alpha-Beta Pruning A sophisticated pruning algorithm Introduced and explained in this week s lab!
Searching in Games a. Minimax Strategy b. Pruning c. Chance
Give Chance a Chance
Weighted Minimax Max Chance 3.56.6.4 Weights Min Chance Max 3.0 4.4 3.6 3.0 5.8 4.4 = 6 * 0.6 + 2 * 0.4.6.4.6.4.6.4.6.4 4 3 3 3 5 7 6 2 2 4 3 2 3 1 2 3 5 2 1 7 5 61 2
References Bratko, I. (2001). PROLOG Programming for Artificial Inte!igence. New York, Addison-Wesley. Kurzweil, R. (1990). The Age of Inte!igent Machines. Cambridge, MA, MIT Press. Newborn, M. (1997). Kasparov versus Deep Blue. Berlin, Springer-Verlag. Nilsson, N. (1998). Artificial Inte!igence A New Synthesis. San Francisco, CA, Morgan Kaufmann. Russel, S., and Norvig, P. (1995). Artificial Inte!igence A Modern Approach. Upper Saddle River, NJ, Prentice Hall.