C AI r 3 e t p a

  • Slides: 114
Download presentation
C AI r 3 e t p a h Solving problems by searching

C AI r 3 e t p a h Solving problems by searching

Outline • • • Problem-solving agents Problem types Problem formulation Example problems Basic search

Outline • • • Problem-solving agents Problem types Problem formulation Example problems Basic search algorithms

Problem-solving agents Fundamentals of classical symbolic AI can be divided into knowledge representation and

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.

Example: Romania • On holiday in Romania; currently in Arad. • Flight leaves tomorrow

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

Example: Romania The path depends on the search algorithm

Example: Romania The path depends on the search algorithm

Problem types • Deterministic, fully observable single-state problem – Agent knows exactly which state

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

Well-defined problems and solutions A problem can be defined formally by four components: 1.

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: { <Go(Sibiu), In(Sibiu)), (Go(Timisoara), In( Timisoara)), (Go(Zerind), In(Zerind)>}

Example: The 8 -puzzle 1. 2. 3. 4. 5. States: locations of tiles Initial

Example: The 8 -puzzle 1. 2. 3. 4. 5. States: locations of tiles Initial state: any initial state Actions: move blank left, right, up, down Goal test: check if whether the state matches goal Path cost: 1 per move

Example: The 8 -puzzle

Example: The 8 -puzzle

Measuring problem-solving performance The output of a problem-solving algorithm is either failure or a

Measuring problem-solving performance 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?

Tree search algorithms • Having formulated some problems, we now need to solve them.

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.

Tree search algorithms: graph into tree

Tree search algorithms: graph into tree

Tree search algorithms: graph into tree

Tree search algorithms: graph into tree

Tree search example

Tree search example

Tree search example

Tree search example

Tree search example

Tree search example

Uninformed search strategies (also called blind search) Uninformed search strategies use only the information

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

Breadth-first search is a simple strategy in which the root node is expanded first,

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.

Breadth-first search is a simple strategy in which the root node is expanded first,

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.

Breadth-first search is a simple strategy in which the root node is expanded first,

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.

Breadth-first search is a simple strategy in which the root node is expanded first,

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.

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Order in which the nodes are expanded in Breadth-first search

Properties of breadth-first search • • Complete? Yes (if b is finite) Time? 1+b+b

Properties of breadth-first search • • Complete? Yes (if b is finite) Time? 1+b+b 2+b 3+… +bd + b(bd-1) = O(bd) Space? O(bd+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

Uniform Cost Search(UCS) uniform-cost search (UCS) is a tree search algorithm used for traversing

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.

Example: Uniform Cost Search(UCS) 3 3 B 1 A D 1 1 S C

Example: Uniform Cost Search(UCS) 3 3 B 1 A D 1 1 S C 3 2 G 12 Initialization: { [ S , 0 ] } Iteration 1: { [ S->A , 1 ] , [ S->G , 12 ] } Iteration 2: { [ S->A->C , 2 ] , [ S->A->B , 4 ] , [ S->G , 12] } Iteration 3: { [ S->A->C->D , 3 ] , [ S->A->B , 4 ] , [ S->A->C->G , 4 ] , [ S->G , 12 ] } Iteration 4: { [ S->A->B , 4 ] , [ S->A->C->G , 4 ] , [ S->A->C->D->G , 6 ] , [ S->G , 12 ] } Iteration 5: { [ S->A->C->G , 4 ] , [ S->A->C->D->G , 6 ] , [ S->A->B->D , 7 ] , [ S->G , 12 ] } Iteration 6 gives the final output as S->A->C->G.

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Example: Uniform Cost Search(UCS)

Properties Uniform Cost Search(UCS) • • Completeness: Yes Time complexity: : O(bd) exponential Space

Properties Uniform Cost Search(UCS) • • Completeness: Yes Time complexity: : O(bd) exponential Space complexity: O(bd) exponential Optimality: Yes • d is the depth of the solution • b is the branching factor at each non-leaf node

Depth-first search always expands the deepest node in the current fringe of the search

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.

Depth-first search Find M

Depth-first search Find M

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search

Depth-first search M found

Depth-first search M found

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search 4

Order in which the nodes are expanded in Depth-first search 4

Order in which the nodes are expanded in Depth-first search 4

Order in which the nodes are expanded in Depth-first search 4

Order in which the nodes are expanded in Depth-first search 4 5

Order in which the nodes are expanded in Depth-first search 4 5

Order in which the nodes are expanded in Depth-first search 3 4 5

Order in which the nodes are expanded in Depth-first search 3 4 5

Order in which the nodes are expanded in Depth-first search 3 4 5

Order in which the nodes are expanded in Depth-first search 3 4 5

Order in which the nodes are expanded in Depth-first search 3 4 5 6

Order in which the nodes are expanded in Depth-first search 3 4 5 6

Order in which the nodes are expanded in Depth-first search 2 3 4 5

Order in which the nodes are expanded in Depth-first search 2 3 4 5 6

Order in which the nodes are expanded in Depth-first search 2 3 4 5

Order in which the nodes are expanded in Depth-first search 2 3 4 5 6

Order in which the nodes are expanded in Depth-first search 2 3 4 5

Order in which the nodes are expanded in Depth-first search 2 3 4 5 6 7

Order in which the nodes are expanded in Depth-first search 2 3 4 5

Order in which the nodes are expanded in Depth-first search 2 3 4 5 6 7

Order in which the nodes are expanded in Depth-first search 2 3 4 5

Order in which the nodes are expanded in Depth-first search 2 3 4 5 6 7

Order in which the nodes are expanded in Depth-first search 2 3 4 5

Order in which the nodes are expanded in Depth-first search 2 3 4 5 6 7

Order in which the nodes are expanded in Depth-first search 2 3 4 5

Order in which the nodes are expanded in Depth-first search 2 3 4 5 7 6 10

Order in which the nodes are expanded in Depth-first search 2 3 4 5

Order in which the nodes are expanded in Depth-first search 2 3 4 5 7 6 10

Order in which the nodes are expanded in Depth-first search 2 3 4 5

Order in which the nodes are expanded in Depth-first search 2 3 4 5 7 6 10 11

Order in which the nodes are expanded in Depth-first search 2 3 4 5

Order in which the nodes are expanded in Depth-first search 2 3 4 5 6 7 9 10 11

Order in which the nodes are expanded in Depth-first search 2 3 4 5

Order in which the nodes are expanded in Depth-first search 2 3 4 5 6 7 9 10 11

Order in which the nodes are expanded in Depth-first search 2 3 4 5

Order in which the nodes are expanded in Depth-first search 2 3 4 5 6 7 9 12 10 11

Order in which the nodes are expanded in Depth-first search 2 3 4 5

Order in which the nodes are expanded in Depth-first search 2 3 4 5 6 7 8 9 12 10 11

Order in which the nodes are expanded in Depth-first search

Order in which the nodes are expanded in Depth-first search

Properties of depth-first search • Complete? No: fails in infinite-depth spaces, spaces with loops

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(bm): terrible if m is much larger than d – but if solutions are dense, may be much faster than breadthfirst • 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

Comparison between the two types Breadth-first search depth-first search The red node needs 3

Comparison between the two types Breadth-first search depth-first search 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-limited search The problem of unbounded trees can be alleviated by supplying depth-first search

Depth-limited search 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 q. It works exactly like depth-first search, but avoids its drawbacks regarding

Depth-limited search q. It works exactly like depth-first search, but avoids its drawbacks regarding completeness by imposing a maximum limit on the depth of the search. q. 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. q. Therefore depth-limited search will find a solution if it is within the depth limit, which guarantees at least completeness on all graphs.

Order in which the nodes are expanded in Depth-limited search Set level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2 Level = 0 Level = 1 Level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2 1 2 Level = 0 Level = 1 Level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2 1 2 3 Level = 0 Level = 1 Level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2 1 2 3 4 Level = 0 Level = 1 Level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2 1 2 3 3 Level = 0 Level = 1 Level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2 1 2 3 3 5 Level = 0 Level = 1 Level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2 Level = 0 1 2 3 3 5 6 Level = 1 Level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2 Level = 0 1 2 3 3 5 6 7 Level = 1 Level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2 Level = 0 1 2 3 3 5 Level = 1 6 7 8 Level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2 Level = 0 1 2 3 3 5 Level = 1 6 7 8 Level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2 Level = 0 1 2 3 3 5 Level = 1 6 7 8 Level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2

Order in which the nodes are expanded in Depth-limited search Set level = 2 Level = 0 1 2 3 4 5 Level = 1 6 7 8 Level = 2

Properties of Depth-limited search • Complete? No (because; it does not find any solution

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(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 (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

Iterative deepening depth-first search q Iterative deepening depth-first search is a state space search

Iterative deepening depth-first search q 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. q 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 • Iterative deepening search L =0 • Iterative deepening search

Iterative deepening depth-first search • Iterative deepening search L =0 • Iterative deepening search L =1

Iterative deepening depth-first search • Iterative deepening search L =2

Iterative deepening depth-first search • Iterative deepening search L =2

Iterative deepening depth-first search • Iterative deepening search L =3

Iterative deepening depth-first search • Iterative deepening search L =3

Properties of iterative deepening search • • Complete? Yes Time? (d+1)b 0 + d

Properties of iterative deepening search • • Complete? Yes Time? (d+1)b 0 + d b 1 + (d-1)b 2 + … + bd = O(bd) 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

Summary of algorithms

Summary of algorithms

END

END