Download presentation
Presentation is loading. Please wait.
Published byGary Rodgers Modified over 9 years ago
1
Solving problems by searching A I C h a p t e r 3
2
Outline Problem-solving agents Problem types Problem formulation Example problems Basic search algorithms
3
Problem-solving agents Fundamentals of classical symbolic AI can be divided into knowledge representation and search. Search deals with finding nodes having certain properties in a graph. Representing a problem in a way that is accessible to this sort of search is called knowledge representation.
4
Example: Romania On holiday in Romania; currently in Arad. Flight leaves tomorrow from Bucharest Formulate goal: – be in Bucharest Formulate problem: – states: various cities – actions: drive between cities Find solution: – sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
5
Example: Romania The path depends on the search algorithm
6
Problem types Deterministic, fully observable single-state problem – Agent knows exactly which state it will be in; solution is a sequence Non-observable sensorless problem (conformant problem) – Agents may have no idea where it is; solution is a sequence Nondeterministic and/or partially observable contingency problem – percepts provide new information about current state – often interleave search, execution Unknown state space exploration problem
7
Well-defined problems and solutions A problem can be defined formally by four components: 1.The initial state that the agent starts in. For example, the initial state for our agent in Romania might be described as In(Arad). 2.A description of the possible actions available to the agent. The most common formulation uses a successor function. Given a particular state x, SUCCESSOR-FN(x) returns a set of (action, successor) ordered pairs, where each action is one of the legal actions in state x and each successor is a state that can be reached from x by applying the action. For example, from the state In(Arad), the successor function for the Romania problem would return: { }
8
Example: The 8-puzzle 1.States: locations of tiles 2.Initial state: any initial state 3.Actions: move blank left, right, up, down 4.Goal test: check if whether the state matches goal 5.Path cost: 1 per move
9
Example: The 8-puzzle
10
The output of a problem-solving algorithm is either failure or a solution. (Some algorithms might get stuck in an infinite loop and never return an output.) We will evaluate an algorithm's performance in four ways: Completeness: Is the algorithm guaranteed to find a solution when there is one? Optimality: Does the strategy find the optimal solution Time complexity : How long does it take to find a solution? Space complexity: How much memory is needed to perform the search? Measuring problem-solving performance
11
Tree search algorithms Having formulated some problems, we now need to solve them. This is done by a search through the state space. Using an explicit search tree that is generated by the initial state and the successor function that together define the state space The root of the search tree is a search node corresponding to the initial State In(Arad) By expanding the current state; that is, applying the successor function to the current state, thereby generating a new set of states. In this case, we get three new states In(Sibiu), In(Timisoara), and In(Zerind). We also need to represent the collection of nodes that have been generated but not yet expanded-this collection is called the fringe. Each element of the fringe is a leaf node.
12
Tree search algorithms: graph into tree
14
Tree search example
17
Uninformed search strategies ( also called blind search) 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
18
Breadth-first search is a simple strategy in which the root node is expanded first, then all the successors of the root node are expanded next, then their successors, and so on. In general, all the nodes are expanded at a given depth in the search tree before any nodes at the next level are expanded.
19
Breadth-first search is a simple strategy in which the root node is expanded first, then all the successors of the root node are expanded next, then their successors, and so on. In general, all the nodes are expanded at a given depth in the search tree before any nodes at the next level are expanded.
20
Breadth-first search is a simple strategy in which the root node is expanded first, then all the successors of the root node are expanded next, then their successors, and so on. In general, all the nodes are expanded at a given depth in the search tree before any nodes at the next level are expanded.
21
Breadth-first search is a simple strategy in which the root node is expanded first, then all the successors of the root node are expanded next, then their successors, and so on. In general, all the nodes are expanded at a given depth in the search tree before any nodes at the next level are expanded.
22
Order in which the nodes are expanded in Breadth-first search
23
Order in which the nodes are expanded in Breadth-first search
24
Order in which the nodes are expanded in Breadth-first search
25
Order in which the nodes are expanded in Breadth-first search
26
Order in which the nodes are expanded in Breadth-first search
27
Order in which the nodes are expanded in Breadth-first search
28
Order in which the nodes are expanded in Breadth-first search
29
Order in which the nodes are expanded in Breadth-first search
30
Order in which the nodes are expanded in Breadth-first search
31
Order in which the nodes are expanded in Breadth-first search
32
Order in which the nodes are expanded in Breadth-first search
33
Order in which the nodes are expanded in Breadth-first search
34
Order in which the nodes are expanded in Breadth-first search
35
Order in which the nodes are expanded in Breadth-first search
36
Order in which the nodes are expanded in Breadth-first search
37
Properties of breadth-first search Complete? Yes (if b is finite) Time? 1+b+b 2 +b 3 +… +b d + b(b d-1 ) = O(b d ) Space? O(b d+1 ) (keeps every node in memory) Optimal? Yes (if cost = 1 per step) Space is the bigger problem (more than time) d is the depth of the solution b is the branching factor at each non-leaf node
38
Uniform Cost Search(UCS) uniform-cost search (UCS) is a tree search algorithm used for traversing or searching a tree or graph. The search begins at the root node. The search continues by visiting the next node which has the least total cost from the root. Nodes are visited in this manner until a goal state is reached. Uniform Cost Search is the best algorithm for a search problem, which does not involve the use of heuristics. It can solve any general graph for optimal cost. Uniform Cost Search as it sounds searches in branches which are more or less the same in cost. Uniform Cost Search again demands the use of a priority queue.
39
S A B C D G 1 3 3 3 1 1 2 12 Initialization: { [ S, 0 ] } Iteration1: { [ S->A, 1 ], [ S->G, 12 ] } Iteration2: { [ S->A->C, 2 ], [ S->A->B, 4 ], [ S->G, 12] } Iteration3: { [ S->A->C->D, 3 ], [ S->A->B, 4 ], [ S->A->C->G, 4 ], [ S->G, 12 ] } Iteration4: { [ S->A->B, 4 ], [ S->A->C->G, 4 ], [ S->A->C->D->G, 6 ], [ S->G, 12 ] } Iteration5: { [ S->A->C->G, 4 ], [ S->A->C->D->G, 6 ], [ S->A->B->D, 7 ], [ S->G, 12 ] } Iteration6 gives the final output as S->A->C->G. Example: Uniform Cost Search(UCS)
50
Completeness: Yes Time complexity: : O(b d ) exponential Space complexity: O(b d ) exponential Optimality: Yes Properties Uniform Cost Search(UCS) d is the depth of the solution b is the branching factor at each non-leaf node
51
Depth-first search always expands the deepest node in the current fringe of the search tree. The search proceeds immediately to the deepest level of the search tree, where the nodes have no successors. As those nodes are expanded, they are dropped from the fringe, so then the search "backs up" to the next shallowest node that still has unexplored successors.
52
Depth-first search Find M
53
Depth-first search
63
M found
64
Order in which the nodes are expanded in Depth-first search
65
Order in which the nodes are expanded in Depth-first search
66
Order in which the nodes are expanded in Depth-first search
67
Order in which the nodes are expanded in Depth-first search
68
Order in which the nodes are expanded in Depth-first search
69
Order in which the nodes are expanded in Depth-first search
70
Order in which the nodes are expanded in Depth-first search
71
4 Order in which the nodes are expanded in Depth-first search
72
4 Order in which the nodes are expanded in Depth-first search
73
45 Order in which the nodes are expanded in Depth-first search
74
45 3 Order in which the nodes are expanded in Depth-first search
75
45 3 Order in which the nodes are expanded in Depth-first search
76
6 45 3 Order in which the nodes are expanded in Depth-first search
77
6 45 3 2 Order in which the nodes are expanded in Depth-first search
78
6 45 3 2 Order in which the nodes are expanded in Depth-first search
79
6 45 3 27 Order in which the nodes are expanded in Depth-first search
80
6 45 3 27 Order in which the nodes are expanded in Depth-first search
81
6 45 3 27 Order in which the nodes are expanded in Depth-first search
82
6 45 3 27 Order in which the nodes are expanded in Depth-first search
83
6 45 3 27 1 0 Order in which the nodes are expanded in Depth-first search
84
6 45 3 27 1 0 Order in which the nodes are expanded in Depth-first search
85
6 45 3 27 1 0 1 1 Order in which the nodes are expanded in Depth-first search
86
6 45 3 27 1 0 1 1 9 Order in which the nodes are expanded in Depth-first search
87
6 45 3 27 1 0 1 1 9 Order in which the nodes are expanded in Depth-first search
88
6 45 3 27 1 0 1 1 9 1 2 Order in which the nodes are expanded in Depth-first search
89
6 45 3 27 1 0 1 1 9 1 2 8 Order in which the nodes are expanded in Depth-first search
90
Order in which the nodes are expanded in Depth-first search
91
Properties of depth-first search Complete? No: fails in infinite-depth spaces, spaces with loops – Modify to avoid repeated states along path complete in finite spaces Time? O(b m ): 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 (because; it first explores one path to its end, thereby possibly finding a solution that is more expensive than some solution in another path.) b = branching factor m = max depth of search tree
92
Comparison between the two types The red node needs 3 actions The green node needs 10 actions The red node needs 7 actions The green node needs 5 actions depth-first search Breadth-first search
93
The problem of unbounded trees can be alleviated by supplying depth-first search with a predetermined depth limit L. That is, nodes at depth L are treated as if they have no successors to solve the infinite-path problem Depth-limited search
94
It works exactly like depth-first search, but avoids its drawbacks regarding completeness by imposing a maximum limit on the depth of the search. Even if the search could still expand a vertex beyond that depth, it will not do so and thereby it will not follow infinitely deep paths or get stuck in cycles. Therefore depth-limited search will find a solution if it is within the depth limit, which guarantees at least completeness on all graphs.
95
Order in which the nodes are expanded in Depth-limited search Set level = 2Level = 0 Level = 1 Level = 2
96
1 2 Set level = 2Level = 0 Level = 1 Level = 2 Order in which the nodes are expanded in Depth-limited search
97
1 2 3 Set level = 2Level = 0 Level = 1 Level = 2 Order in which the nodes are expanded in Depth-limited search
98
1 2 34 Set level = 2Level = 0 Level = 1 Level = 2 Order in which the nodes are expanded in Depth-limited search
99
1 2 33 Set level = 2Level = 0 Level = 1 Level = 2 Order in which the nodes are expanded in Depth-limited search
100
1 25 33 Set level = 2Level = 0 Level = 1 Level = 2 Order in which the nodes are expanded in Depth-limited search
101
1 256 33 Set level = 2Level = 0 Level = 1 Level = 2 Order in which the nodes are expanded in Depth-limited search
102
1 256 337 Set level = 2Level = 0 Level = 1 Level = 2 Order in which the nodes are expanded in Depth-limited search
103
1 256 3378 Set level = 2Level = 0 Level = 1 Level = 2 Order in which the nodes are expanded in Depth-limited search
104
1 256 3378 Set level = 2Level = 0 Level = 1 Level = 2 Order in which the nodes are expanded in Depth-limited search
105
1 256 3378 Set level = 2Level = 0 Level = 1 Level = 2 Order in which the nodes are expanded in Depth-limited search
106
1 256 3478 Set level = 2Level = 0 Level = 1 Level = 2 Order in which the nodes are expanded in Depth-limited search
107
Properties of Depth-limited search Complete? No (because; it does not find any solution that lies beyond the given search depth. But if the maximum search depth is chosen to be greater than the depth of a solution the algorithm becomes complete). Time? O(b m ) : 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 (because; it first explores one path to its end, thereby possibly finding a solution that is more expensive than some solution in another path.) b = branching factor m = max depth of search tree
108
Iterative deepening depth-first search is a state space search strategy in which a depth-limited search is run repeatedly, increasing the depth limit with each iteration until it reaches, the depth of the shallowest goal state. It is equivalent to breadth-first search it visits the nodes in the search tree in the same order as depth-first search, but the cumulative order in which nodes are first visited is effectively breadth-first. Iterative deepening depth-first search
109
Iterative deepening search L =0 Iterative deepening search L =1 Iterative deepening depth-first search
110
Iterative deepening search L =2 Iterative deepening depth-first search
111
Iterative deepening search L =3
112
Properties of iterative deepening search Complete? Yes Time? (d+1)b 0 + d b 1 + (d-1)b 2 + … + b d = O(b d ) Space? O(bd) Optimal? Yes, if step cost = 1 d is the depth of the solution b is the branching factor at each non-leaf node
113
Summary of algorithms
114
END
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.