AIMA Chapter 3: Solving problems by searching Ana Huaman January 13, 2011 1. Define in your own words the following terms: state, state space, search tree, search node, goal, action, transition model and branching factor • State: It represents a particular configuration of the world • State space: ”It consists of the set of all possible states that can be reached from the initial state by any sequence of actions” • Search tree: It is the possible sequences of actions beginning at the initial state of the problem. It is composed by branches (actions) and nodes (instances of the state space). The root node of the search tree is the initial state. • Search node: It is a bookeeping data structure that is used to represent the search tree. • Goal: It is a state which our agent wants to achieve. It can be formulated as one state (or a subset of states) of the state space. It also can be expressed as an ”abstract property”; in both cases a goal test must be performed. • Action: Given a particular state s, an action is a process that can be executed in order to change s into a new state s0 in the state space. • Transition Model: It is the description of what each action does • Branching factor: The maximum number of successors of a node. It is used to express the complexity of a problem. 2. Explain why problem formulation must follow goal formulation First, problem formulation is the process of deciding what actions and states to consider, given a goal, so we need to define it before. Second, once we have defined our goal properly, we can abstract the states and actions needed to achieve your objective. By abstraction I mean the simplification of the problem, this is the removal of detail not relevant to our goal. 3. Which of the following are true and which are false? Give a brief explanation of each answer: • Depth-first search always expands at least as many nodes as A* search with an admissible heuristic False. Depth-first search (DFS) is neither optimal nor complete, so it may come with a sub-optimal solution at an earlier stage than A* 1 (expanding less nodes). For instance, in 1, considering that G is the goal state we observe that DFS would just expand 1 node, with a cost of 100; however, A* would expand 3 nodes to find an optimal path to C (with a lower cost of 70 but apparently a ”longer” path). A* evaluates the goal when it expands the node, rather than when it is generated, which is why it does not get stuck in a sub-optimal path. Figure 1: Example 1 • h(n)=0 is an admissible heuristic for the 8-puzzle True. For a heuristic function h(n) to be admissible, it must satisfy: (a) The function does not have to overestimate the real path cost (b) h(goal) = 0[2] If we consider the path costs to be non-negative (as it is usually done), then h(n) = 0 satisfy both requirements. Note, however, that using this heuristic is the same as using Uniform-cost search, an uninformed search strategy, so we are not using any advantage of an informed search. Any other admissible heuristic that dominates h = 0 will generate fewer nodes and consequently will use less time and space during the search. • A* cannot be used in robotics because percepts, states and actions are continuous False. It is a fact that the world is continuous, but it is also true that usually we use discretization at some extent to solve problems that otherwise would be infeasible or harder to manage. For example, for applications in robot navigation in known environments, it is common to represent the world as a 2D grid. If the granularity factor is small enough (depending of the problem), then this problem can be solved by using any search algorithm that operates in a ”discrete” manner. As a reference, in the DARPA Challenge 2007, A* was one of the options used for planning routes to achieve all checkpoints in the real-world road.1 1 At least, the Virginia Tech’s team (Victor Tango) used it successfully (they placed third in the finals) 2 • Breadth-first search is complete even if zero step-costs are allowed True (if the other conditions for completeness are met). In breadthfirst search (BFS), we care about the number of steps the path has rather than the path cost. So, for this search to be complete, the conditions are: – The goal must be at a finite depth – The branching factor must be finite The condition of having an infinite loop of zero step-cost paths would affect completeness in the case of uniform-cost search, because in that case the evaluation function is the path cost (in BFS, it is assumed that each path has the same cost). • Assume that a rook can move on a chessboard any number of squares in a straight line, vertically or horizontally, but cannot jump over pieces. Manhattan distance is an admissible heuristic for the problem of moving the rook from square A to square B in the smallest number of moves False. The condition for a heuristic function is that it never overestimates the solution cost. We can easily see in the example shown in Fig. 2 that for diagonal displacements, the Manhattan distance overestimate the real path cost (in the figure, the real cost from start (node S) to goal (node G) is 4, while according to Manhattan distance, it would be 8. (a) Costreal =4 (b) CostM anhattan =8 Figure 2: Example of a non-admissible heuristic for the rook problem So, what can be an admissible heuristic? First, we will relax the problem to a simpler version. The original is: A rook can move from square A to square B if: (a) There are not occupied squares between A and B (horizontal, vertical or diagonal) (b) Square B is on the same column or row of A (straight movement) or it is on the same diagonal. If we relax the first condition (so the rook can jump over pieces), we would have 2 cases: One when B is on the same diagonal of A and when it is not. Both cases are shown in Fig.3. In Fig.3(a), it is easy to see that the path cost is equal to the dvertical (= dhorizontal ) between the start and goal nodes. In the second case Fig. 3(b), after 3 a simple observation we can see that the shortest path is equal to M AX(dvertical , dhorizontal ). So, we can formulate the heuristic as: h(S) = M AX(abs(XS − XG ), abs(YS − YG )) which is true for both cases (in the first case, as both horizontal and vertical distances are equal, the maximum is also the same). As this is a solution for a relaxed version of the original problem, it is an admissible heuristic for the original problem. (a) Diagonal relaxed case (b) Non-diagonal relaxed case Figure 3: Relaxed problem 4. Consider the problem of finding the shortest path between two points on a plane that has convex polygonal obstacles as shown in Fig.4 This is an idealization of the problem that a robot has to solve to navigate in a crowded environment Figure 4: A scene with polygonal obstacles. S and G are the start and goal states • Suppose the state space consists of all positions (x, y) in the plane. How many spaces are there? How many paths are there to the goal? We define our world like this: Given the world W = <2 (the real plane) and a finite group of convex polygonal obstacles O, our goal is to move an agent (represented as a point) from an initial position (xs , ys ) to a final position (xg , yg ), such as the path is the shortest 4 possible and that it is goes through the free space, defined as F = W − O. Our state space would be all the positions (x, y) ∈ <2 that are in the free space F (given that the number of obstacles is finite, it is safe to say that the free space exists) . In the world <2 , even if we have just a small neighborhood of radius > 0, the number of pairs (x, y) inside it is infinite. About the paths towards the goal, if the goal is reachable (in the figure shown, it is), there are infinite paths, given that there are infinite states. However, there is just one optimal path that is formed by a group of vertices of the obstacles and two straight lines connecting the initial and final positions to some vertices of the obstacles. • Explain briefly why the shortest path from one polygon vertex to any other in the scene must consist of straight-line segments joining some of the vertices of the polygons. Define a good state space now. How large is this state space? First we define the Euclidean shortest path: The shortest path from one polygon vertex p to any other q is expressed by: ρ =< p, p1 , p2 , ..., pk , q > where each vertex in the path is a vertex of one of the polygonal obstacles. We can prove by contradiction that the statement above is true[1]. First, let us assume that at least one of the vertices in the shortest path (pi ) is not a vertex of the obstacles. Also, consider that each of the vertices are not redundant (so 3 consecutives vertices are not colinear, or the same, they form a triangle). For this, we evaluate the 3 possible cases, shown in Fig. 5: Figure 5: Three possible cases to prove the ESP statement (figure from [1]) – Case 1: Both edges pi−1 pi and pi pi+1 are not on the tangent of an obstacle or on the tangent of a vertex. If this is the case, as we can see in Fig. 5, there is always a small neighborhood U around pi such that for a point pii ∈ U . From observing the figure, we can easily see that de (pi−1 , p0i ) + de (p0i , pi+1 ) < 5 de (pi−1 , pi ) + de (pi , pi+1 ). From this we see that if we replace pi by p0i we can obtain a shorter path, which contradicts the initial assumption of ρ being the shortest path. – Case 2: Both edges pi−1 pi and pi pi+1 are on an obstacle edge or on a tangent of a vertex. For this case, we can prove a contradiction similar as in case 1. Lets consider 02 vertices p0i−1 and p0i+1 that are the closest such that p0i−1 pi and pi p0i+1 are on the original tangents. In a similar way to the case above, we can always find a point p0i such that the new distance p0i−1 p0i p0i+1 is shorter than the original p0i−1 pi p0i+1 , that means another contradiction. – Case 3: Just one edge is on an obstacle tangent and the other is not This is a combination of the other two cases mentioned and is demonstrated in a similar way. Definition of the state space for the problem Given the proof above, we observe that to reach our goal (to go from a polygon vertex to another) in a shortest path, we have to analyze just the vertices of the obstacles, so we can safely ignore the other points (x, y) in the free space. Abstracting the problem then, we can define the state space of the problem as: State space = ∀(x, y) → (x, y) is a vertex of O (where O represents the set of polygonal obstacles in the real plane analyzed.) How large is this state space? : It would be the total number of vertices of all the obstacles in the plane. Sizess = i=n X #V ertOi i=0 • Define the necessary functions to implement the search problem, including an ACTIONS function that takes a vertex as input and returns a set of vectors, each of which maps the current vertex to one of the vertices that can be reached in a straight line (Do not forget the neighbors on the same polygon) Use the straight-line distance for the heuristic function • Apply one or more of the algorithms in this chapter to solve a range of problems in the domain, and comment on their performance. 5. Prove each of the following statements: • Breadth-first search is a special case of uniform-cost search True, since in breadth-first search we consider that the cost is the same between nodes. • Breadth-first search, depth-first search, and uniform-cost search are special cases of best-first search Best-first search selects the node to expand based on an evaluation function f (n). The node with the lowest value of f is chosen to be expanded first in each iteration. For each of the three uninformed search strategies mentioned we have: (a) Breadth-first search: f(n)=number of actions (or branches) between start and current nodes 6 (b) Depth-first search: Uh, not sure here...I think that the function thinks that the farthest of the start, the nearest to the goal :) (c) Uniform-cost search: f(n)=sum of cost of subpaths between start and current goal • Uniform-cost search is a special case of A* search For A* we have that the evaluation function is given by: f (n) = g(n)+h(n). Instead, for uniform-cost search we consider f (n) = g(n), that is h(n) = 0. References [1] Statistical Science and Interdisciplinary Research, chapter 1. World Scientific Review, 2008. [2] Artificial Intelligence: A Modern Approach. Prentice Hall, 2009. 7