1. Problem Solving What is a problem? Lecture 2: Problem Formulation A goal and a means for achieving the goal The goal specifies the state of affairs we want to bring about The means specifies the operations we can perform in an attempt to bring about the goal The difficulty is deciding what order to carry out the operations Solution will be a sequence of operations leading from initial state to goal state (plan) 2. Problem Formulation Problem Formulation: The sequence of required actions to move from current state to a goal state Once the goal is determined, formulate the problem to be solved First determine set of possible states S of the problem Then the problem has a: set of states S initial state - the starting point, s0 - a member of S set of operations - the actions that can be performed, {o1,..., on} goal - what you are aiming at - subset of S Operations cause changes in state. Performing an operation in a given state reaches some specified next state. Operations are functions s1 s2 A solution is a sequence of actions such that when applied to initial state s0, we reach the goal state Example 1: 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 1
Single-state problem formulation A problem is defined by four items: 1. initial state e.g., "at Arad" 2. actions or successor function S(x) = set of action state pairs e.g., S(Arad) = {<Arad Zerind, Zerind>, <Arad Timisoara, Timisoara>, } 3. goal test, can be explicit, e.g., x = "at Bucharest" implicit, e.g., Checkmate(x) 4. path cost (additive) e.g., sum of distances, number of actions executed, etc. c(x,a,y) is the step cost, assumed to be 0 Example 2: Toy Problems: The 8 Puzzle States: 3 3 grid filled with numbers 1 8 and a blank Initial state: as shown on the left Goal state: as shown on the right Operations: o1: move any tile to left of empty square to right States? Locations of tiles Actions? Move blank left, right, up, down Goal test? Given Path cost? 1 per move Example 3: Toy Problems: The n Queens Problem This is a problem from chess Place 8 queens on chess board so that no queen can be taken by another (A queen attacks any piece in the same row, column or diagonal) Initial state: empty chess boar Goal state: n queens on chess board so that none can take any other Operations: place queen in empty square Place queens anywhere For the 8-queens problem 648 possibilities Place queens only where they are not attacked already Around 2,000 possible sequences to check 2
Example 4: robotic assembly States? real-valued coordinates of robot joint angles parts of the object to be assembled Actions? continuous motions of robot joints Goal test? complete assembly Path cost? time to execute More Examples of Real World Problems Game playing Route finding - routing in computer networks, rail travel, air travel Touring and travelling - find a route between Aberdeen and Glasgow; travelling salesperson problem Assembly sequencing VLSI layout Robot navigation.... 3. Search Space An imaginary tree showing all possible states reachable from the initial state 724 5_6 831 A tree showing nodes explored by a search algorithm Root is the initial state: successor nodes found by applying operators (expanding nodes) Stops when goal is reached 3.1 Search Strategy Performance Completeness: does it always find a solution if one exists? Time complexity: number of nodes generated/expanded Space complexity: maximum number of nodes in memory Optimality: does it always find a least-cost solution? Time and space complexity: are measured in terms of b: maximum branching factor of the search tree d: depth of the least-cost solution m: maximum depth of the state space (may be infinite) 3.2 Selecting a state space Real world is absurdly complex state space must be abstracted for problem solving (Abstract) state = set of real states (Abstract) action = complex combination of real actions 3
e.g., "Arad Zerind" represents a complex set of possible routes, detours, rest stops, etc. For guaranteed realizability, any real state "in Arad must get to some real state "in Zerind" (Abstract) solution = set of real paths that are solutions in the real world Each abstract action should be "easier" than the original problem 3.3 Solution Cost For most problems, some solutions are better than others: 8 puzzle: number of moves to get to solution chess: number of moves to checkmate route planning: length of distance (or time) to travel Mechanism for determining cost of solution is the path cost function This is the length (cost) of the path through the state-space from the initial state to the goal state 4. Numerical Problem solving: example of optimization EXAMPLE 1: A farmer has 2400 ft of fencing and wants to fence off a rectangular field that borders a straight river. He needs no fence along the river. What are the dimensions of the field that has the largest area? Solution: Note that the area of the field depends on its dimensions: To solve the problem, we first draw a picture that illustrates the general case: The next step is to create a corresponding mathematical model: Maximize: A = xy Constraint: 2x + y = 2400 We now solve the second equation for y and substitute the result into the first equation to express A as a function of one variable: 2x + y = 2400 y = 2400 2x A = xy = x(2400 2x) = 2400x 2x 2 To find the absolute maximum value of A = 2400x 2x 2, The derivative of A(x) is A (x) = (2400x 2x 2 ) = 2400x 2(x 2 ) = 2400 1 2 2x = 2400 4x So to find the critical numbers we solve the equation, 2400 4x = 0 2400 = 4x x = 2400 4= 600 To find the maximum value of A(x) we evaluate it at the end points and critical number: A(0) = 0, A(600) = 2400 600 2 600 2 = 720, 000, A(1200) = 0 4
Homework: EXAMPLE 2: We need to enclose a field with a rectangular fence. We have 500 ft of fencing material and a building is on one side of the field and so won t need any fencing. Determine the dimensions of the field that will enclose the largest area. Solution: We first draw a picture that illustrates the general case: EXAMPLE 3: We want to construct a box whose base length is 3 times the base width. The material used to build the top and bottom cost $10/ft2 and the material used to build the sides cost $6/ft2. If the box must have a volume of 50 ft3 determine the dimensions that will minimize the cost to build the box. EXAMPLE 4: We want to construct a box with a square base and we only have 10 m2 of material to use in construction of the box. Assuming that all the material is used in the construction process determine the maximum volume that the box can have. 5