250 likes | 481 Views
SOLVING PROBLEMS BY SEARCHING. Feng Zhiyong Tianjin University Fall 2008. Problem-solving Agents. Formulating Problems. Well-defined problems and solutions. datatype PROBLEM components: INITIAL-STATE, OPERATORS, GOAL-TEST, PATH-COST-FUNCTION Measuring problem-solving performance
E N D
SOLVING PROBLEMS BYSEARCHING Feng Zhiyong Tianjin University Fall 2008
Well-defined problems and solutions • datatype PROBLEM • components: INITIAL-STATE, OPERATORS, GOAL-TEST, PATH-COST-FUNCTION • Measuring problem-solving performance • The effectiveness of a search can be measured in at least three ways. First, does it rind a solutionSEARCH COST at all? Second, is it a good solution (one with a low path cost)? Third, what is the search costTOTAL COST associated with the time and memory required to find a solution? The total cost of the search isthe sum of the path cost and the search cost.5
Example Problems • The 8-puzzIe • States: a state description specifies the location of each of the eight tiles in one of the ninesquares. For efficiency, it is useful to include the location of the blank. • Operators: blank moves left, right, up, or down. • Goal test: state matches the goal configuration shown in Figure 3.4. • Path cost: each step costs 1, so the path cost is just the length of the path.
The 8-queens problem • Goal test: 8 queens on board, none attacked. • Path cost: zero. • States: any arrangement of 0 to 8 queens on board. • Operators: add a queen to any square. • States: arrangements of 0 to 8 queens with none attacked. • Operators: place a queen in the left-most empty column such that it is not attacked by anyother queen. • States: arrangements of 8 queens, one in each column. • Operators: move any attacked queen to another square in the same column.
The vacuum world • State sets: subsets of states 1-8 shown in Figure 3.2 (or Figure 3.6). • Operators: move left, move right, suck. • Goal test: all states in state set have no dirt. • Path cost: each action costs 1.
Missionaries and cannibals • States: a state consists of an ordered sequence of three numbers representing the numberof missionaries, cannibals, and boats on the bank of the river from which they started.Thus, the start state is (3,3,1). • Operators: from each state the possible operators are to take either one missionary, onecannibal, two missionaries, two cannibals, or one of each across in the boat. Thus, there are at most five operators, although most states have fewer because it is necessary to avoid jillegal states. Note that if we had chosen to distinguish between individual people then jthere would be 27 operators instead of just 5. • Goal test: reached state (0,0,0). • Path cost: number of crossings.
Real-world problems • Route finding • Touring and travelling salesperson problems • VLSI layout • Robot navigation • Assembly sequencing
Searching for Solutions • Generating action sequences
Data structures for search trees • the state in the state space to which the node corresponds; • the node in the search tree that generated this node (this is called the parent node); • the operator that was applied to generate the node; • the number of nodes on the path from the root to this node (the depth of the node); • the path cost of the path from the initial state to the node.
Data structures for search trees • MAKE-QUEUE(Elements) creates a queue with the given elements. • EMPTY?(Queue) returns true only if there are no more elements in the queue. • REMOVE-FRONT(Queue) removes the element at the front of the queue and returns it. • QUEUlNG-FN(Elements,Queue) inserts a set of elements into the queue. Different varietiesof the queuing function produce different varieties of the search algorithm.
Search Strategies • Four criteria • Completeness: is the strategy guaranteed to find a solution when there is one? • Time complexity: how long does it take to find a solution? • Space complexity: how much memory does it need to perform the search? • Optimality: does the strategy find the highest-quality solution when there are several different solutions?7
Search Strategies • Breadth-first search • The news about breadth-first search has been good. To see why it is not always the strategy of choice, we have to consider the amount of time and memory it takes to complete a search.
Search Strategies • Breadth-first search • The memory requirements area bigger problem for breadth-first search than the execution time. • The time requirements are still a major factor
Search Strategies • Uniform cost search: modifies the breadth-first strategy by always expanding the lowest-cost node on the fringe (as measured by the path cost g(n)), rather than the lowest-depth node. • g(SUCCESSOR(n)) > g(n)
Search Strategies • Depth-first search • has very modest memory requirements.
Search Strategies • Depth-limited search
Search Strategies • Iterative deepening search: time complexity of iterative deepening is still O(bd), and the space complexity is O(bd).
Search Strategies • Bidirectional search: Time and space complexity areO(bdl2)
Avoiding Repeated States • Do not return to the state you just came from. Have the expand function (or the operator set) refuse to generate any successor that is the same state as the node's parent. • Do not create paths with cycles in them. Have the expand function (or the operator set) refuse to generate any successor of a node that is the same as any of the node's ancestors. • Do not generate any state that was ever generated before. This requires every state that is generated to be kept in memory, resulting in a space complexity of O(bd), potentially. It is better to think of this as O(s), where s is the number of states in the entire state space.