Problem Solving and Search Andrea Danyluk September 11, 2013
Announcements Progamming Assignment 0: Python Tutorial – Due now – Thanks for your patience with account set-up, turnin, etc. Assignment 1: Search – Now posted on web site – Due Fri, Sep 20 – Team project! (35 students) – First few parts straightforward. Don’t be fooled. It gets harder.
Today’s Lecture More on Uninformed search – Breadth-first – Depth-first – Uniform-cost search New Informed (Heuristic) search – Greedy best-first
Formalizing State Space Search A node in a search tree typically contains: – A state description – A reference to the parent node – The name of the operator that generated it from its parent – The cost of the path from the initial state to itself – Might also include its depth in the tree The node that is the root of the search tree typically represents the initial state
Formalizing State Space Search Child nodes are generated by applying legal operators to a node – The process of expanding a node means to generate all of its successor nodes and to add them to the frontier. A goal test is a function applied to a state to determine whether its associated node is a goal node
Formalizing State Space Search A solution is either – A sequence of operators that is associated with a path from start state to goal or – A state that satisfies the goal test The cost of a solution is the sum of the arc costs on the solution path – If all arcs have the same (unit) cost, then the solution cost is just the length of the solution (i.e., the length of the path)
Evaluating Search Strategies Completeness – Is the strategy guaranteed to find a solution when there is one? Optimality – Does the strategy find the highest-quality solution when there are several solutions? Time Complexity – How long does it take (in the worst case) to find a solution? Space Complexity – How much memory is required (in the worst case)?
Evaluating BFS Complete? – Yes (if the number of possible actions is finite) Optimal? – Not in general. When is it optimal? When costs of all actions are the same Time Complexity? – How do we measure it? Space Complexity?
Time and Space Complexity Let b = branching factor (i.e., max number of successors) m = maximum depth of the search tree d = depth of shallowest solution For BFS Time: O(b d ) If we check for goal as we generate a node! Not if we check as we get ready to expand! Space: O(b d )
Evaluating DFS Complete? – Not in general – Yes if state space is finite and we modify tree search to account for loops Optimal? – No Time Complexity? – O(b m ) Space Complexity? – O(mb)
Depth-Limited DFS? Let l be the depth limit Complete? – No Optimal? – No Time Complexity? – O(b l ) Space Complexity? – O(m l )
Iterative Deepening? Complete? – Yes (if b is finite) Optimal? – Yes (if costs of all actions are the same) Time Complexity? – O(b d ) Space Complexity? – O(bd)
Costs on Actions
Cost of moving a truck = 2x the cost of moving a car that isn’t a sports car. Cost of moving a sports car is 4x the cost of moving any other vehicle.
Uniform Cost Search a a b b h h g g c c f f e e d d i i Fringe is a Priority Queue Priority = cost so far Similar to another algorithm you know?
Evaluating Uniform Cost Search Complete? – Yes (if b is finite and step cost ≥ for positive ) Optimal? – Yes Time Complexity? – O(b 1+C*/ ) Can’t check for goal until coming out of PQ! Space Complexity? – O(b 1+C*/ )
Generalized Search Function S EARCH (problem, frontier) returns a solution, or failure expanded ← an empty set frontier ← Insert(Make-Node(Initial-State[problem]), frontier) loop do if frontier is empty then return failure node ← Remove(frontier) if Goal-Test(problem, State[node]) then return node if State[node] is not in explored then add State[node] to explored frontier ← InsertAll(Expand(node, problem), frontier) end But be careful about slight (and yet significant) differences!
So we’re done, right? Our search spaces are big.
Informed (Heuristic) Search Strategies Use problem-specific knowledge to find solutions more efficiently
Best-first Search Choose a node from the frontier based on its “desirability” – Frontier is a priority queue Requires a search heuristic – Any estimate of how close a state is to a goal – Examples: Euclidean distance Manhattan distance For the “rush hour” problem?
Greedy Best-first Search h(n) = estimate of cost from n to the closest goal Expand the node with lowest h value - i.e., the node that appears to be closest to the goal
Greedy Search with h SLD a a b b h h g g c c f f e e d d i i a6 b2.5 c6 d3 e1.5 f3 g0 h3.5 i6.5 black4.5 red3.5 yellow2.5 This time g is the goal.
Problems with Greedy Search? Can be quite good with a high-quality heuristic, but Not optimal Time and space complexity: O(b m )