Outline Solving Problems by Searching S/ University of Waterloo Sept 7, 009 Problem solving agents and search Examples Properties of search algorithms Uninformed search readth first Depth first Iterative Deepening Introduction Problem-solving agents Search was one of the first topics studied in I Newell and Simon (9) General Problem Solver entral component to many I systems utomated reasoning, theorem proving, robot navigation, VLSI layout, scheduling, game playing,
Start Example: Traveling in Romania 7 7 Dobreta Formulate Goal Get to ucharest 0 70 7 Lugoj Mehadia 0 0 99 raiova Fagaras Rimnicu Vilcea 97 Pitesti Neamt 0 ucharest Giurgiu Formulate Problem Find a solution Initial state: In() Sequence of cities:, ctions: Drive between cities, Fagaras, ucharest Goal Test: In(ucharest)? Path cost: Distance between cities 7 90 7 Iasi Urziceni End 9 9 Vaslui Hirsova Eforie Examples of Search Problems 7 Start State 7 Goal State States: Locations of tiles and blank Initial State: ny state Initial State: No queens on the board Succ Func: Generates legal states that result from trying actions (blank up, Succ Func: dd a queen to an empty down, left, right) space Goal test: Does state match desired configuration Path cost: Number of steps States: rrangement of 0 to queens on the board Goal test: queens on board, none attacked Path cost: none More Examples ommon haracteristics ll of those examples are Fully observable Deterministic Sequential Static Discrete Single agent an be tackled by simple search techniques 9 0 annot tackle these yet hance Infinite number of states Hidden states ll of the above Games against an adversary Searching We can formulate a search problem Now need to find the solution We can visualize a state space search in terms of trees or graphs Nodes correspond to states Edges correspond to taking actions We will be studying search trees These trees are constructed on the fly by our algorithms
Data Structures for Search asic data structure: Search Node State Parent node and operator applied to parent to reach current node ost of the path so far Depth of the node PRENT NODE Expanding Nodes Expanding a node pplying all legal operators to the state contained in the node and generating nodes for all corresponding successor states (a) The initial state (b) fter expanding Fagaras Rimnicu Vilcea Lugoj TION = right Node DEPTH = PTH OST = STTE Fagaras Rimnicu Vilcea Lugoj (c) fter expanding 7 Fagaras Rimnicu Vilcea Lugoj Generic Search lgorithm. Initialize search algorithm with initial state of the problem. Repeat. If no candidate nodes can be expanded, return failure. hoose leaf node for expansion, according to search strategy. If node contains a goal state, return solution. Otherwise, expand the node, by applying legal operators to the state within the node. dd resulting nodes to the tree Implementation Details We need to only keep track of nodes that need to be expanded (fringe) Done by using a (prioritized) queue. Initialize queue by inserting the node corresponding to the initial state of the problem. Repeat. If queue is empty, return failure. Dequeue a node. If the node contains a goal state, return solution. Otherwise, expand node by applying legal operators to the state within. Insert resulting nodes into queue Search algorithms differ in their queuing function! readth-first search ll nodes on a given level are expanded before any nodes on the next level are expanded. Implemented with a FIFO queue,,d,e D,E,F,G Evaluating search algorithms ompleteness: Is the algorithm guaranteed to find a solution if a solution exists? Optimality: Does the algorithm find the optimal solution (Lowest path cost of all solutions) Time complexity Space complexity Variables b ranching factor d Depth of shallowest goal node m Maximum length of any path in the state space 7
Judging FS omplete:, if b is finite Optimal:, if all costs are the same Time: +b+b +b + +b d = O(b d ) Space: O(b d ) ll uninformed search methods will have exponential time complexity 9 Uniform ost Search variation of breadth-first search Instead of expanding shallowest node it expands the node with lowest path cost Implemented using a priority queue Optimal omplete if ε > 0 Time: O(b ceiling(*/ε ) ) Space: O(b ceiling(*/ε ) ) * is cost of optimal solution ε is minimum action cost 0
Judging DFS omplete: No, might get stuck going down a long path Optimal: No, might return a solution which is deeper (i.e. more costly) than another solution Time: O(b m ), m might be larger than d Space: O(bm) Do not use DFS if you suspect a large tree depth 7 Depth-limited search We can avoid the problem of unbounded trees by using a depth limit, l ll nodes at depth l are treated as though they have no successors If possible, choose l based on knowledge of the problem Time: O(b l ) Memory: O(bl) omplete?: No Optimal?: No Iterative-deepening General strategy that repeatedly does depthlimited search, but increases the limit each time Iterative-deepening IDS is not as wasteful as one might think. Note, most nodes in a tree are at the bottom level. It does not matter if nodes at a higher level are generated multiple times. readth first search : + b + b + + b d- + b d E.g. b=0, d=: +0+00+,000+0,000+00,000 =, Iterative deepening search : (d+)* + (d)*b + (d-)*b + + b d- + b d E.g. +0+00+000+0,000+00,000 =, omplete, Optimal, O(b d ) time, O(bd) space 9 0
Summary Problem formulation usually requires abstracting away real-world details to define a state space that can feasibly be explored Variety of uninformed search strategies ssume no knowledge about the problem (general but expensive) Mainly differ in the order in which they consider the states Summary Iterative deepening uses only linear space and not much more time than other uninformed search algorithms Use IDS when there is a large state space and the maximum depth of the solution is unknown riteria omplete Time Space Optimal FS O(b d ) O(b d ) Uniform DFS DLS No No O(b ceiling(*/ε) ) O(b m ) O(b l ) O(b ceiling(*/ε) ) O(bm) O(bl) No No IDS O(b d ) O(bd) Things to think about: What about searching graphs? Repeated states? Next lass Informed search techniques Russell & Norvig: Sections.-.