340 likes | 347 Views
This lecture discusses uninformed search strategies in Artificial Intelligence, including Breadth-first search, Uniform-cost search, Depth-first search, and more.
E N D
Artificial Intelligence Lecture 4 – Uninformed Search Dr. Muhammad Adnan Hashmi
Uninformed Search Strategies Uninformed search strategies use only the information available in the problem definition Breadth-first search Uniform-cost search Depth-first search Depth-limited search Iterative deepening search 23 October 2019 2
Breadth-first search Expand shallowest unexpanded node Implementation: fringe is a FIFO queue, i.e., new successors go at end 23 October 2019 3
Breadth-first search • Expand shallowest unexpanded node • Implementation: • fringe is a FIFO queue, i.e., new successors go at end 23 October 2019 4
Breadth-first search • Expand shallowest unexpanded node • Implementation: • fringe is a FIFO queue, i.e., new successors go at end 23 October 2019 5
Breadth-first search • Expand shallowest unexpanded node • Implementation: • fringe is a FIFO queue, i.e., new successors go at end 23 October 2019 6
Breadth-first search 23 October 2019 7
Properties of Breadth-first search Complete?Yes (if b is finite) Time?1+b+b2+b3+… +bd + b(bd-1) = O(bd+1) Space?O(bd+1) (keeps every node in memory) Optimal? Yes (if cost = 1 per step) Space is the bigger problem (more than time). 23 October 2019 8
Preventing Loopy Paths • We can have search graphs (instead of trees) • Hence paths can go backwards, ABCB • Can get paths with loops ABCDB • We can also have multiple paths to a node • From them, we are interested in the min-cost path • The Loop problem is that we “rediscover” nodes that the search has already discovered • Need to consider methods to suppress nodes that have already been visited. 23 October 2019 9
Uniform-Cost Search 23 October 2019 11
Consider the following problem… A 10 1 5 5 S B G 5 15 C We wish to find the shortest route from node S to node G; that is, node S is the initial state and node G is the goal state. In terms of path cost, we can clearly see that the route SBG is the cheapest route. However, if we let breadth-first search loose on the problem it will find the non-optimal path SAG, assuming that A is the first node to be expanded at level 1.
Node A is removed from the queue and the revealed node (node G) is added to the queue. The queue is again sorted on path cost. Note, we have now found a goal state but do not recognise it as it is not at the front of the queue. Node B is the cheaper node. Press space. Once node B has been expanded it is removed from the queue and the revealed node (node G) is added. The queue is again sorted on path cost. Note, node G now appears in the queue twice, once as G10 and once as G11. As G10 is at the front of the queue, we now proceed to goal state. Press space. We now expand the node at the front of the queue, node A. Press space to continue. Node S is removed from the queue and the revealed nodes are added to the queue. The queue is then sorted on path cost. Nodes with cheaper path cost have priority.In this case the queue will be Node A (1), node B (5), followed by node C (15). Press space. We start with our initial state and expand it… A A 10 1 5 5 S S B B G G G G G G The goal state is achieved and the path S-B-G is returned. In relation to path cost, UCS has found the optimal route. 15 C Size of Queue: 0 Size of Queue: 0 Size of Queue: 3 Size of Queue: 1 Queue: B, G11, C Queue: G10, G11, C15 Queue: Empty Queue: Empty Queue: S Queue: A, B, C Nodes expanded: 3 Nodes expanded: 2 Nodes expanded: 0 Nodes expanded: 1 Current action: Backtracking Current action: Expanding Current action: Waiting…. FINISHED SEARCH Current action: Expanding Current level: 2 Current level: 0 Current level: 1 Current level: 1 Current level: n/a Current level: 0 UNIFORM COST SEARCH PATTERN
Uniform-Cost Search 23 October 2019 14
Uniform-Cost Search Expand least-cost unexpanded node Implementation: fringe = queue ordered by path cost Equivalent to breadth-first if step costs all equal Complete?Yes, if step cost ≥ ε Time?O(bceiling(C*/ ε)) where C* is the cost of the optimal solution Space?O(bceiling(C*/ ε)) Optimal?Yes – given the condition of completeness – you always expand the node with lowest cost O(bceiling(C*/ ε)) can be greater than Ob/d 23 October 2019 15
Depth-first search • Expand deepest unexpanded node • Implementation: • fringe is a LIFO queue, i.e., put successors in the front 23 October 2019 16
Depth-first search • Expand deepest unexpanded node • Implementation: • fringe is a LIFO queue, i.e., put successors in the front 23 October 2019 17
Depth-first search • Expand deepest unexpanded node • Implementation: • fringe is a LIFO queue, i.e., put successors in the front 23 October 2019 18
Depth-first search • Expand deepest unexpanded node • Implementation: • fringe is a LIFO queue, i.e., put successors in the front 23 October 2019 19
Depth-first search • Expand deepest unexpanded node • Implementation: • fringe is a LIFO queue, i.e., put successors in the front 23 October 2019 20
Depth-first search • Expand deepest unexpanded node • Implementation: • fringe is a LIFO queue, i.e., put successors in the front 23 October 2019 21
Depth-first search • Expand deepest unexpanded node • Implementation: • fringe is a LIFO queue, i.e., put successors in the front 23 October 2019 22
Properties of Depth-first search Complete?No: fails in infinite-depth spaces, spaces with loops Complete in finite spaces Time?O(bm): terrible if m is much larger than d But if solutions are dense, may be much faster than breadth-first Space?O(bm), i.e., linear space! Optimal? No 23 October 2019 23
Depth-limited search Depth-first search with depth limit l, i.e., nodes at depth l have no successors Recursive implementation: 23 October 2019 25
Depth-Limited Search Complete? NO. Why? (l < d OR l > d) Time?O(bl) Space? O(bl) Depth-first is a special case of depth-limited with l being infinite. 23 October 2019 26
Iterative deepening search 23 October 2019 27
Iterative deepening search l =0 23 October 2019 28
Iterative deepening search l =1 23 October 2019 29
Iterative deepening search l =2 23 October 2019 30
Iterative deepening search l =3 23 October 2019 31
Iterative Deepening search Number of nodes generated in a depth-limited search to depth d with branching factor b: NDLS = b0 + b1 + b2 + … + bd-2 + bd-1 + bd Number of nodes generated in an iterative deepening search to depth d with branching factor b: NIDS = (d+1)b0 + d b1 + (d-1)b2 + … + 3bd-2 +2bd-1 + 1bd For b = 10, d = 5, NDLS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111 NIDS = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 = 123,456 Overhead = (123,456 - 111,111)/111,111 = 11% 23 October 2019 32
Properties of iterative deepening search Complete? Yes Time?(d+1)b0 + d b1 + (d-1)b2 + … + bd = O(bd) Space?O(bd) Optimal? Yes, if step cost = 1 23 October 2019 33
Summary of Algorithms 23 October 2019 34
Questions 23 October 2019 35