700 likes | 826 Views
Problem Solving and Search in AI Part II. Search Strategies. Uninformed (blind, exhaustive) strategies use only the information available in the problem definition Breadth-first search Depth-first search Uniform-cost search
E N D
Search Strategies • Uninformed (blind, exhaustive) strategies use only the information available in the problem definition • Breadth-first search • Depth-first search • Uniform-cost search • Heuristic strategies use “rules of thumb” based on the knowledge of domain to pick between alternatives at each step Graph Searching Applet: http://www.cs.ubc.ca/labs/lci/CIspace/Version4/search/index.html
Basic Search Procedure • 1. Start with the start node (root of the search tree) and place in on the queue • 2. Remove the front node in the queue and • If the node is a goal node, then we are done; stop. • Otherwise expand the node generate its children using the successor function (other states that can be reached with one move) • 3. Place the children on the queue according to the search strategy • 4. Go back to step 2.
Search Strategies • Search strategies differ based on the order in which new successor nodes are added to the queue • Breadth-first add nodes to the end of the queue • Depth-first add nodes to the front • Uniform cost sort the nodes on the queue based on the cost of reaching the node from start node
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: A
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: B I E
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: I E C D
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: E C D M K
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: C D M K F H
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: D M K F H N
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: M K F H N
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: K F H N O G
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: F H N O G
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: H N O G Q
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: N O G Q R T
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: O G Q R T P S
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: G Q R T P S
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S DONE!!! Solution: A I M G Queue: Q R T P S
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: A
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: B I E
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: C D I E
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: N D I E
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: P S D I E
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: S D I E
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: D I E
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: I E
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: M K E
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: O G K E
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S Queue: G K E
Breadth-First Search A B I E C D M K F H N O G Q R T goal P S DONE!!! Solution: A I M G Queue: K E
Search Exercise Traffic Graph: Start Node: A Goal Node: M
Exercise: Breadth-First A G B D L C E K H B E F I D O I I J M • Order of node expansion: A, B, D, G, C, E, K, L, B, E, F, I, O, D, H, I, I, J, M Solution Found: A D E I M (optimal)
Exercise: Breadth-First(with duplicate detection) A G B D L C E K F I O H J M • Order of node expansion: A, B, D, G, C, E, K, L, F, I, O, H, J, M
Exercise : Depth-First A G B D C E B E F I M • Order of node expansion: A, B, D, C, B, E, I, M Solution Found: A D C E I M (not optimal)
Example: The 8-Puzzle • States? integer location of tiles • Operators? move blank left, right, up, down • Goal Test? = goal state (given) • Path Cost? One per move
Example: 8-Puzzle – Depth First Search We will assume that we can do repeated state checking (i.e., we will not generate nodes that have been previously expanded)
. . . Example: 8-Puzzle – Depth First Search
A 1 10 S B G 5 5 C 15 5 C 15 G G 10 11 Uniform-Cost Search • Each move has some cost • The cost of the path to each node N is g(N) = sum of the move costs • The goal is to generate a solution path of minimal cost • The queue is sorted in increasing cost order • So, lower cost nodes go to the front S 0 1 A B 5
Uniform-Cost Search • Always expand the least-cost unexpanded node • Queue = insert in order of increasing path cost Arad 75 118 140 Zerind Sibiu Timisoara <== Zerind, Timisoara, Sibiu <==
Uniform-Cost Search Arad 75 118 140 Zerind Sibiu Timisoara 71+75 75+75 Arad Oradea <== Timisoara, Sibiu, Oradea, Arad <==
Uniform-Cost Search Arad 75 118 140 Zerind Sibiu Timisoara 75+75 118+118 71+75 111+118 Arad Arad Oradea Lugoi <== Sibiu, Oradea, Arad, Lugoi, Arad <==