problem solving and search andrea danyluk september 9, 2013
TRANSCRIPT
![Page 1: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/1.jpg)
Problem Solving and Search
Andrea DanylukSeptember 9, 2013
![Page 2: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/2.jpg)
Announcements
• Progamming Assignment 0: Python Tutorial– Should have received my email about it– Due Wednesday at 10am• Should not take long to complete• Talk to me if the due date/time is a real problem
– Turnin should be fixed today– Grading for this one is mainly a sanity check
– Any trouble with accounts: let me know!
![Page 3: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/3.jpg)
Today’s Lecture
• Agents• Goal-directed problem-solving and search• Uninformed search– Breadth-first– Depth-first and variants– Uniform-cost search (Wednesday)
![Page 4: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/4.jpg)
Rational Agents
• An agent perceives and acts.
• “Doing the right thing” captured by a performance measure that evaluates a given sequence of environment states.
A rational agent: selects an action that is expected to maximize the
performance measure, given evidence provided by the percept sequence and whatever built-in knowledge the agent has.
![Page 5: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/5.jpg)
• Rational ≠ omniscient– Percepts may not supply all relevant information
• Rational ≠ clairvoyant– Action outcomes may not be as expected
• Rational ≠ successful
[ Adapted from Russell]
![Page 6: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/6.jpg)
Reflex Agents
• Act on the basis of the current percept (and possibly what they remember from the past).
• May have memory or a model of the world’s state.
• Do not consider future consequences of their actions.
[Adapted from CS 188 UC Berkeley]
![Page 7: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/7.jpg)
Goal-based Agents
• Plan ahead• Ask “what if”• Decisions based on
(hypothesized) consequences of actions
• Have a model of how the world evolves in response to actions
[Adapted from CS 188 UC Berkeley]
![Page 8: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/8.jpg)
Building a goal-based agent
• Determine the percepts available to the agent• Select/devise a representation for world states• Determine the task knowledge the agent will
need• Clearly articulate the goal• Select/devise a problem-solving technique so
that the agent can decide what to do
![Page 9: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/9.jpg)
Search as a Fundamental Problem-Solving Technique
• Originated with Newell and Simon’s work on problem solving in the late 60s.
![Page 10: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/10.jpg)
Search Problems
A search problem consists of • A state space– A set of states– As set of actions– A transition model that specifies results of
applying actions to states• Successor function: Result(s, a)
• An initial state• A goal test
![Page 11: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/11.jpg)
An Example: the 8-Puzzle
1 2 3
8 7
6 5 4
1 2 3
4 5 6
7 8
Initial State Goal State
# possible distinct states = 9! = 362,880 (but only 9!/2 reachable)
![Page 12: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/12.jpg)
Real world examples
• Navigation• Vehicle parking• Parsing (natural and artificial languages)– The old dog slept on the porch– The old dog the footsteps of the young
![Page 13: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/13.jpg)
And back to the 8-Puzzle
• States:– Puzzle configurations
• Actions:– Move blank N, S, E, or W
• Start state:– As given
• Goal test:– Is current state =
specified goal state?
1 2 3
8 7
6 5 4
1 2 3
4 5 6
7 8
![Page 14: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/14.jpg)
State Space Graph1 2 3
8 76 5 4
1 2 38 76 5 4
1 38 2 76 5 4
1 2 38 5 76 4
1 2 36 8 7
5 4
S
G
![Page 15: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/15.jpg)
Finding a solution in a problem graph
• Solving the puzzle = finding a path through the graph from initial state to goal state
• Simple graph search algorithms:– Breadth-first search– Depth-first search
![Page 16: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/16.jpg)
Breadth-first Graph Search:Review
ab
h
g
c
f
e
d
iFringe is a FIFO queue
Start: aGoal: i
Explore vertices (reallyedges closest to thestart state first.
![Page 17: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/17.jpg)
Depth-first Graph Search:Review
ab
h
g
c
f
e
d
iFringe is a LIFO stack
Start: aGoal: i
Explore deepest vertex(really edge) first.
![Page 18: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/18.jpg)
State Space Search in the AI World
• Rarely given a graph to begin with• We don’t build the graph before doing the
search– Our search problems are BIG
![Page 19: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/19.jpg)
Search Trees1 2 3
8 76 5 4
2 31 8 76 5 4
1 2 38 76 5 4
1 2 36 8 7
5 4
{N, E, S, W}
2 3
1 8 7
6 5 4
1 3
8 2 7
6 5 4
1 2 3
8 5 7
6 4
1 2 3
8 7
6 5 4
1 2 3
6 8 7
5 4
2 3
1 8 7
6 5 4
2 8 3
1 7
6 5 4
Search tree for BFSWhite nodes = explored (i.e., expanded)Orange nodes = frontierMaintains an “explored” set of states to avoid redundant search
![Page 20: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/20.jpg)
Search Tree
• A “what if” tree of plans and outcomes• Start state at the root node• Children correspond to successors• Nodes contain states; correspond to plans to
those states• Aim to build as little as possible• Because we build the tree “on the fly” the
representations of states and actions matter![Adapted from CS 188 UC Berkeley]
![Page 21: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/21.jpg)
Formalizing State Space Search
• A state space is a graph (V, E), where V is the set of states and E is a set of directed edges between states. The edges may have associated weights (costs).
• Our exploration of the state space using search generates a search tree.
[Adapted from Eric Eaton]
![Page 22: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/22.jpg)
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
• The node that is the root of the search tree typically represents the initial state
![Page 23: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/23.jpg)
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
![Page 24: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/24.jpg)
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)
![Page 25: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/25.jpg)
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)?
![Page 26: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/26.jpg)
Evaluating BFS
• Complete?– Yes
• Optimal?– Not in general. When is it optimal?
• Time Complexity?– How do we measure it?
• Space Complexity?
![Page 27: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/27.jpg)
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)
![Page 28: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/28.jpg)
Evaluating DFS
• Complete?– Not in general– Can be if space is finite and we modify tree search to
account for loops and redundant paths• Optimal?– No
• Time Complexity?– O(bm)
• Space Complexity?– O(mb)
![Page 29: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/29.jpg)
Depth-Limited DFS?
Let l be the depth limit• Complete?– No
• Optimal?– No
• Time Complexity?– O(bl)
• Space Complexity?– O(ml)
![Page 30: Problem Solving and Search Andrea Danyluk September 9, 2013](https://reader030.vdocuments.net/reader030/viewer/2022032518/56649cc55503460f9498e39c/html5/thumbnails/30.jpg)
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)