P. 1
Problems and Search

|Views: 0|Likes:

See more
See less

08/19/2013

pdf

text

original

# Problems and Search

• To build a system to solve a particular problem we need:
To define the problem precisely: Specify initial solution(s), and finally what acceptable solutions will be. Analyze the problem: Finding out important features which can have important impact on the technique of solving the problem Isolate and represent the task knowledge necessary to solve the problem. Choose the best problem solving technique(s) and apply it to solve the particular problem.
2

An initial state is the description of the starting configuration of the agent. An action or an operator takes the agent from one state to another state which is called a successor state. A plan is a sequence of actions. The cost of a plan is referred to as the path cost. It is a positive number. Search is the process of considering various possible sequences of operators applied to the initial state, and finding out a sequence which culminates in a goal state.
3

• •

 A sequence of states is called a path. • A search problem is represented using a directed graph.  The states are represented as nodes.• So A search problem consists of the following:  S: the full set of states  S0 : the initial state  A:S→S is a set of operators  G is the set of final states. (G S). 4 .  This sequence of actions is called a solution plan.  The allowed actions are represented as arcs.

Using the set of rules to move from one state to another. Steps for solution : Starting at the initial state. • State space is a set of legal positions. Attempting to end up in a goal state. 5 . • Initial position is the game opening position.State Space Search: Playing Chess • Each position can be described by an 8-by-8 array. • Goal position is any position in which the opponent does not have a legal move and his or her king is under attack. • Legal moves can be described by a set of rules.

3 • Start state: (0. • Goal state: (2. a 4-litre one and a 3-litre one. 2. 1. 0). 1. Neither has any measuring markers on it.State Space Search: Water Jug Problem “You are given two jugs. 6 . 2. • Attempting to end up in a goal state. or 4 y = 0. How can you get exactly 2 litres of water into 4-litre jug. y) x = 0. 3.” • State: (x. There is a pump that can be used to fill the jugs with water. n) for any n.

(x. y (0. y) 7 . y) (x. y) if x 4 2. 3. 3) d. y) (4. y) (x. x 4. y) (x. (0. y 3. 0) y) (4 x)) y). y) d) if y if x if y if x if y if x if x if x if x 3 0 0 0 0 y y y y 4. y (x (x (0. (x. y) (x. (2. x (2. y) (3 y. 0) (4. y) (x. 8. 7. 9. y) (x. 6. 2) 12. 5. y 3. y) (x. y) (x. 3) (x (x. (x. 0) (0. y) (x. y) 11.Valid Operations Allowed: 1. x 0 0 0 0 10. 4.

8 .State Space Search: 8 queens problem “ The problem is to place 8 queens on a chessboard so that no two queens are in the same row. column or diagonal”.

and so on.N queens problem formulation 1 • • • • • States: Any arrangement of 0 to 8 queens on the board Initial state: 0 queens on the board Successor function: Add a queen in any square Goal test: 8 queens on the board. Each of the states at the next level have 63 successors. The initial state has 64 successors. 9 . none are attacked.

none are attacked • 10 .N queens problem formulation 2 • • • States: Any arrangement of 8 queens on the board Initial state: All queens are at column 1 Successor function: Change the position of any one queen Goal test: 8 queens on the board.

N queens problem formulation 3 • • • • States: Any arrangement of k queens in the first k rows such that none are attacked Initial state: 0 queens on the board Successor function: Add a queen to the (k+1)th row so that none are attacked. none are attacked 11 . Goal test : 8 queens on the board.

the agent needs to know:  The initial state. • To generate the state space implicitly.Explicit vs Implicit state space • The state space may be explicitly represented by a graph.  The operators and a description of the effects of the operators. 12 . • But more typically the state space can be implicitly represented and generated when required.

answer. but not necessarily the best. it may use more steps than necessary. It is systematic: Otherwise. 3. 13 .Search Strategies Requirements of a good search strategy: 1. It causes motion: Otherwise. It is efficient: Find a good. it will never lead to a solution. 2.

The successors of the current expanded node are put in fringe. We also maintain a list of nodes called the fringe. 14 .The basic search algorithm • • • States generated are nodes.

Issues in Search Strategy: • The search tree may be unbounded. What should we return a path or a node?  The answer to this depends on the problem.  Due to loops in the search space. 15 • • • • • . then which node should we select? The search graph may be weighted or unweighted. If we select a node for expansion. Is there any heuristic available about intermediate states.  Due to state space being infinite. Some problem may demand to find a minimal cost path or to find path as soon as possible.

b. . Space complexity: Space used by the algorithm measured in terms of the maximum size of 16 fringe.Evaluating Search strategies: • Generally these are evaluated by the following criterias. 1. Time complexity: Time taken (number of nodes expanded) (worst or average case) to find a solution. What is the search cost associated with the time and memory required to find a solution? a. Completeness: Is the strategy guaranteed to find a solution if one exists? 2. Optimality: Does the solution have low cost or the minimal cost? 3.

Informed search (heuristic search) More efficient than uninformed search. Uninformed search (blind search) Having no information about the number of steps from the current state to the goal.Different Search Strategies 1. 17 . 2.

• • The corresponding search tree is: Start from initial state and list all possible paths. 18 .Search Tree • Consider the explicit state space graph shown in the figure.

Search Tree – Terminology • • • • • Root Node: Leaf Node: Ancestor/Descendant: Branching factor: Path: Data structure of a Node: • A node contains the following:  A state description  A pointer to the parent of the node  Depth of the node  The operator that generated this node  Cost of this path (sum of operator costs from the start state) • The nodes that the algorithm has generated are kept in 19 the a data structure called OPEN or fringe. . Initially only start node is in OPEN.

• So state space makes explicit a sufficient portion of implicit 20 state space graph to find a goal node.e. it becomes impractical to represent state space. The search problem will return as a solution a path to a goal node or the goal node itself. “dead-ends”)  Each of these nodes a partial solution path. in fringe) or  having no successors (i. • • .• • The search process constructs a search tree.e. In case of large state space.  Like path finding in solving 15-puzzle..  Like the N-queens problem for which the path to the solution is not important.. where  root is the initial state and  leaf nodes are nodes  not yet expanded (i. Search tree may be infinite because of loops even if state space is small.

a1. s0. . a2. – P={a0. – Leading to traversal of several states {S0. . A:SS`.G} A plan is a sequence of actions. an}.S2.S1. Initial state S0 S.SN+1 G } 21 • • . . A. . .Search problem representation: • • • S: set of states. An action moves from one state to another state S` Search Problem: {S. .

22 . It expands the shallowest node first.Breadth First Search: • • Note that in breadth first search the newly generated nodes are put at the back of fringe.

d is the depth of the shallowest goal node.  A complete search tree of depth d where each nonleaf node has b children.. Then the time and space complexity of the algorithm is O(bd).  Optimal (i.  It has exponential time and space complexity. admissible) if all operators have the same cost.Properties of Breadth-First Search • Assume that every non-leaf node has b children. breadth first search finds a solution with the shortest path length but path cost may not be cheap. FIFO  Complete.e. Otherwise... and m maximum the depth of total space. has a total of 1 + b + b2 + .1)/(b-1) nodes OR order of O(bd) 23 . + bd = (b(d+1) .

Properties of this search algorithm are:  Complete  Optimal/Admissible  Exponential time and space complexity. then sort nodes by increasing value of g. The algorithm expands nodes in the order of their cost from the source. The newly generated nodes are put in FRINGE / OPEN according to their path costs. O(bd) 24 . This ensures that when a node is selected for expansion it is the node with cheapest cost . If g(n) = cost of the path from the start node to the current node n.Uniform Cost Search • • • • • • Put by Dijkstra [1959].

Uniform-cost search Sample 0 25 .

Uniform-cost search Sample 75 X 140 118 26 .

Uniform-cost search Sample 146 X X 140 118 27 .

Uniform-cost search Sample 146 X X 140 X 229 28 .

Depth First Search: • Expand the deepest node first 29 .

If the search tree has infinite depth. It can be seen that the time taken by the algorithm is related to the maximum depth of the search tree. Thus Depth First Search is not complete.  It can also happen if the search space contains cycles. the algorithm may not terminate. the depth of the search tree.  This can happen if the search space is infinite. Space taken is linear. O(bm).Properties of Depth First Search: • • • LIFO Exponential time O(bd). If m is the maximum depth of a node in the search space.  The latter case can be handled by checking for cycles in the algorithm. 30 • • • .

Depth Limited Search • • The incompleteness of DFS can be taken care if depth is made limited. Here. Nodes are only expanded if they have depth less than the bound. 31 .

treat start node as having no successors). etc. do DFS to depth 1. First do DFS to depth 0 (i. it might happen that goal may not fall within it..e. if no solution found. then. 32 . So.Depth-First Iterative Deepening (DFID) • • If we fix the depth initially.

• If branching factor is b and solution is at depth d.e. • Requires linear memory. then nodes at depth d are generated once and nodes at depth d-1 are generated twice etc. 33 . • Has advantage of BFS i. limited space and finds longer paths more quickly.e. complete • Has advantage of DFS i. Hence bd+2b(d-1)+…+db=bd/(1-1/b)2=O(bd) • Linear space complexity is O(bd). • Generally used in large state space with solution depth unknown.

 Such that. there is another operator that maps from state B to state A. path planning etc.Bi-directional search • Consider that the search problem is such that the arcs are bidirectional. 34 . if there is an operator that maps from state A to state B.  If there is a single state that satisfies the goal property.  Many search problems have reversible arcs.  But if the arcs are reversible. we can instead of starting from the start state and searching for the goal. 15-puzzle. the search problems are identical. we may start from a goal state and try reaching the start state.  However the water jug problem is a problem that does not have this property. such as 8-puzzle.

35 .

S A B C 11 D 14 E D E A B B D E F Forward Backwards F B F C 17 E A 15 C 15 G 13 G 19 C G 19 17 F G 25 36 .

d d/2 d/2 Time ~ bd/2 + bd/2 < bd 37 .

can sometime lead to find solution faster.Problems: • • If more than one goal. there should be an efficient way to check whether a node belongs to another tree.  Predecessors of node n are all the nodes that have n as successor. For Bi-directional search to work better. Algorithm: Bidirectional search involves alternate searching from the start state toward the goal and from the goal state toward the start. 38 • • • . The algorithm stops when the frontiers intersect. Select an algorithm for each half. How do we search backwards from goal?  One should be able to generate predecessor states.

Summary of algorithms 39 .

scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->