Aug 28, 2006 ------------ - Recap goal-based agents: they - formulate goal (Goal Formulation) - formulate state, actions/operators (Problem Formulation) - try to achieve goal (Search) - Search - ubiquitous in AI - need a good understanding of it before moving onto other topics - Example search problems - 8-queens problem - 8-puzzle problem - traveling salesperson problem (TSP) - Formalizing a search problem GIVEN: - what is the start state? - what are the available operators? - what is the goal test? - i.e., how do you know you have succeeded? - "are we there yet?" FIND: a path/state that satisfies the goal test OPTIONAL and that is optimal - Revisiting the problems - goal is a state - 8-queens problem - goal is a path - 8-puzzle problem - goal is an optimal path - TSP - Two basic uninformed search methods - breadth first search (BFS) - uniform cost search (UCS) - Pseudocode for generic BFS algorithm fringe := make-queue(initial-node) loop if empty?(fringe) then return FAIL else X := remove-front(fringe) if isa-goal?(state(X)) then return X else fringe := insert(fringe,expand(X)) end loop - Breadth first search - expand nodes of one level completely before moving to the next - time complexity - nodes expanded: O(b^d) - nodes generated: O(b^(d+1)) - space complexity - nodes expanded: O(b^d) - nodes generated: O(b^(d+1)) - complete?: yes - i.e., guaranteed to find a solution - finds optimal solution?: yes - because nodes at lower depths are expanded before ones at higher depths - Note: memory requirement is killing! - In the above - b: branching factor - d: depth at which solution is found - BFS assumptions - equates cost to depth - what if different edges in the search tree have different costs? - Solution: uniform cost search (UCS) - expand nodes based on cost - has a tendency to flip-flop its way - path costs must be non-decreasing down the tree, for UCS to make sense - easy to get by making the min. cost to be a small positive number - has same worst-case time and space complexity as BFS - Data structure support for search algorithms - BFS: use queue - UCS: use priority queue - Next idea - DFS: uses a stack! - More search algorithms: Depth First Search (DFS) - uses a stack in place of a queue - primary advantage is its space complexity - problems: does not provide optimal solution - more problems: can go into an infinite loop - DFS features - time complexity: O(b^m) - space complexity: O(bm) - where m is the max depth of search tree - DBS: Depth Bounded Search - uses a limit "l" to prevent infinite loops - complete only if l is chosen large enough so that l >= d (but then need not be optimal) - if l < d, not complete - time complexity: O(b^l) - space complexity: O(bl) - Thus far - BFS and UCS are good for "guarantees" - DFS and DBS good for space complexity - DFID: Depth First Iterative Deepening - best of both worlds - DFID Details - performs a series of DBSs with increasing l - guaranteed to find solution and, - since at each time it is doing only a DFS, has the nice space complexity we want - time complexity: O(b^d) - space complexity: O(bd) - complete and optimal - Still.. - Q: won't DFID be wasting too much time expanding nodes over and over again? - A: not really, asymptotically the bulk of the work is really in the "last iteration" - All search algorithms studied thus far can be categorized as - "uninformed search" - Informed search algorithms - e.g., "psychic search" - more next class!