Problem Solving and Search Andrea Danyluk September 11, 2013
Feb 23, 2016
Problem Solving and Search
Andrea DanylukSeptember 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 solutionFor BFSTime: O(bd) If we check for goal as we generate a
node! Not if we check as we get ready to expand!Space: O(bd)
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(bm)
• Space Complexity?– O(mb)
Depth-Limited DFS?
Let l be the depth limit• Complete?– No
• Optimal?– No
• Time Complexity?– O(bl)
• Space Complexity?– O(ml)
Iterative Deepening?
• Complete?– Yes (if b is finite)
• Optimal?– Yes (if costs of all actions are the same)
• Time Complexity?– O(bd)
• Space Complexity?– O(bd)
Costs on Actions
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
ab
h
g
c
f
e
d
i
2
3
11
11
2
3
3.5
4
5
33.75
3
Fringe is a Priority Queue
Priority = cost so far
Similar to anotheralgorithm you know?
Evaluating Uniform Cost Search
• Complete?– Yes (if b is finite and step cost ≥ e for positive e )
• Optimal?– Yes
• Time Complexity?– O(b 1+C*/e) Can’t check for goal until coming out
of PQ!• Space Complexity?– O(b1+C*/e)
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 hSLD
ab
h
g
c
f
e
d
i
2
3
11
11
2
3
3.5
4
5
33.75
3
a 6
b 2.5
c 6
d 3
e 1.5
f 3
g 0
h 3.5
i 6.5
black 4.5
red 3.5
yellow 2.5
This time gis the goal.
Problems with Greedy Search?
Can be quite good with a high-quality heuristic, but
• Not optimal
• Time and space complexity: O(bm)