Solving Problem by Searching
Solving Problem by Searching
Problem Solving
Problem:
◦ A goal and set of means for achieving the goal is called a
problem
Search:
◦ The process of exploring what the means can do is called a
search
2
Problem Solving Agents
Problem solving agent
◦ A kind of “goal based” agent
◦ Finds sequences of actions that lead to desirable states.
3
Problem-Solving Agent
sensors
?
environment
agent
actuators
• Formulate Goal
• Formulate Problem
•States
•Actions
• Find Solution
Goal Formulation
6
Search, Solution & Execution
Search: Examining different possible sequences of
actions that lead to the state of known value and
choose the best one, the process of looking such a
sequence is search
Solution: form of action sequence to reach the goal
Execution: the actions that the solution recommends
can be carried out in this phase
Vacuum World Example
9
Problem Formulation
Problem
◦ Collection of information that the agent will use to decide
what to do
Initial State
◦ The starting state of the problem, defined in a suitable manner
Operator
◦ An action or a set of actions that moves the problem from one
state to another
◦ Given a particular state x, S(x) returns the set of states
reachable from x by any single action
State Space
◦ The set of all states reachable from the initial state by any
sequence of actions
Problem Formulation
Path
◦ A path in a state space is simply any sequence of actions
leading from one state to another
Goal Test
◦ A test applied to a state which returns true if we have reached
a state that solves the problem
Path Cost
◦ A path cost function is a function that assigns a cost to the
path
Solution
◦ Path from the initial state to the state that satisfies the goal test
Problem Formulation
State Set Space
◦ The initial state set and the successor function define the state
space set of the problem OR the set of all states reachable
from the initial state set
Abstraction
◦ The process of removing the detail from the representation is
called the abstraction
12
Measuring Problem Solving Performance
The effectiveness of a search can be measured in at
least three ways:
◦ It finds a solution at all
◦ Is it a good solution? (one with low path cost)
◦ Search cost associated with time and memory required to find a
solution
The total cost of search is the sum of path cost and the
search cost
The agents must somehow decide what resources to
devote to search and what resources to devote to
execution (for example, in large complicated problems,
there is trade off to be made, the agent can search for a
very long time to get an optimal solution and vice
versa)
Example: The 8-puzzle
Initial State
Considering all input records
Goal Test
Considering a single record, and it gives “illegal input” message.
Successor Function
Run again on the first half of the records
Run again on the second half of the records
Note: your choice of move depends on whether a run gives the error or not.
Cost Function
Number of runs
Search strategies
The choice of which state to expand first is
determined by the search strategy
Think search process as building up a search tree.
The root of the search tree is a search node
corresponding to the initial state
The leaf node of the tree correspond to states that do
not have successors in the tree, either because they
have not expanded yet, or because they were
expanded, but generated the empty set.
Search Trees
STATE
PARENT
ACTION
COST
DEPTH
Implementation: states vs. nodes
22
Breadth-first search
In this strategy, the root node is expanded first, then
all the nodes generated by the root node are expanded
next, and then their successors, and so on.
In general, all the nodes at depth d in the search tree
are expanded before the nodes at depth d + 1.
If there is a solution, breadth-first search is guaranteed
to find it.
If there are several solutions, breadth-first search will
always find the shallowest goal state first.
Breadth-first search
Complete
◦ Yes if b (max branching factor) is finite
Time
◦ 1 + b + b2 + … + bd + b(bd-1) = O(bd+1)
◦ exponential in d
Space
◦ O(bd+1)
◦ Keeps every node in memory
◦ This is the big problem; an agent that generates nodes at 10
MB/sec will produce 860 MB in 24 hours
Optimal
◦ Yes (if cost is 1 per step); not optimal in general
Depth-First Search
30
Depth-First Search
Depth-First Search
Depth-First Search
Depth-First Search
Depth-First Search
Depth-First Search
Depth-First Search
Depth-First Search
Depth-First Search
Depth-First Search
Depth-First Search
Depth-First Search
Depth-First Search
Complete
◦ No: fails in infinite-depth spaces, spaces with loops
Modify to avoid repeated spaces along path
◦ Yes: in finite spaces
Time
◦ O(bm)
◦ Not great if m is much larger than d
◦ But if the solutions are dense, this may be faster than breadth-
first search
Space
◦ O(bm)…linear space
Optimal
◦ No
Depth-Limited Search
Complete
◦ Yes if l < d
Time
◦ O(bl)
Space
◦ O(bl)
Optimal
◦ No if l > d
Iterative Deepening Search
47
Iterative Deepening Search
Iterative Deepening Search
Iterative Deepening Search
Iterative Deepening Search
Iterative Deepening Search
Complete
◦ Yes
Time
◦ O(bd)
Space
◦ O(bd)
Optimal
◦ Yes if step cost = 1
◦ Can be modified to explore uniform cost tree
Iterative Deepening Search
In general, iterative deepening search is the preferred
uninformed search method when there is a large
search space and the depth of the solution is not
known