Search 1
Search 1
Problem-Solving Agents
Task: To solve a particular problem by searching state space.
function simple-problem-solving-agent (percept) returns an action
inputs: percept, a percept
static: seq, an action sequence, initially empty
state, some description of current world state
goal, a goal, initially empty
problem, a problem formulation
state Å update-state (state, percept)
if seq is empty then do
goal Å formulate-goal (state)
problem Å formulate-problem (state, goal)
seq Å search (problem)
action Å first (seq)
seq Å rest (seq) Assume the environment is:
return action Static, Observable, Discrete &
Deterministic.
Artificial Intelligence Searching
1. initial state: starting point from which the agent sets out
2. actions (operators, successor functions):
• describe the set of possible actions
3. goal test: determines if a given state is the goal state.
4. path cost:
• determines the expenses of the agent for executing the actions in a path
• sum of the costs of the individual actions in a path
Solution quality is measured by the path cost function, and an
optimal solution has the lowest path cost
among all solutions.
Artificial Intelligence Searching
S 5 5
• states
– Locations (e.g: A, B, …) 4 G
• initial state D E F 3
2 4
– starting point (e.g: S)
• successor function (operators) To find the route from city S to city G
– move from one location to another
• goal test
– arrive at a certain location (e.g: G)
• path cost
– Total distance, money, time, travel
comfort etc. (here distance in km)
Artificial Intelligence Searching
1. Start from initial state, test, is it goal? If not expand the current state.
(i.e. from S get A, D).
2. Move to anyone of new states to proceed further (i.e move to A or D).
3. Continue choosing, testing, and expending until either a solution is
found or no more state to be expanded.
For this example there are 8 states & infinite number of paths to
check.
Artificial Intelligence Searching
Search Methods
There are two broad classes of search methods:
- uninformed (or blind) search methods;
In the case of the uninformed search methods the order in which potential
solution paths are considered is arbitrary, using no domain-specific
information to judge where the solution is likely to lie.
• Breadth-first Search
• Uniform-cost search
• Depth-first search
• Depth-limited search.
• Interative deepening depth-first search.
• Bidirectional search
- informed (heuristic) search methods.
Use domain specific heuristic to find solution.
• Discussed later.
Artificial Intelligence Searching
D A E
B
B F
C E E B
D F B F C E A C G
Artificial Intelligence Searching
BFS: Discussion
• Complete? Yes, if b is finite (i.e goal is in some finite depth)
• Optimal? Yes, if steps are identical not optimal in general.
• Time complexity? 1 + b + b2 + b3 + . . . + bd = O(bd), i.e.,
exponential in d
• Space complexity? O(bd) (keeps every node in memory)
Lets assume a b= 10 at depth 10, number of nodes = 1011 time required for
processing (with processor can process 10,000 nodes per sec) = 129 days
and memory requirement = 101 TB (1 node = 1KB)
Uniform-Cost Search
Modified version of BFS to make optimal.
Expand the node n with lowest path cost.
4 4
A B C
C(i,j) = cost of an arc from node i to node j 3
C(x,z) = C(x,y) + C(y,z) S
5 5
Find the minimum cost path from S to G: 4 G
D E F 3
S 2 4
3 4
A3 4 D
4 5 5 2
B7 8 D A9 6 E
4 5 5 4
C 11 12 E 11 B F 10
3
G 13
Artificial Intelligence Searching
Does not care about the number of steps, only care about total cost.
• Complete? Yes, if step cost ≥ ε (small positive number).
• Time? Maximum as of BFS
• Space? Maximum as of BFS.
• Optimal? Yes
Artificial Intelligence Searching
A 4 4
A B C
3
B S
5 5
4 G
D E F 3
C E 2 4
G
Artificial Intelligence Searching
DFS: Discussion
Depth 1: S S
A A D
Depth 2: S S S S
A A A D A D
B B D B D A B D A
Depth 3: S S S S
A A A A D
…
B B B D B D A
C C E C E E C E E B
Artificial Intelligence Searching
Bidirectional Search
• Search simultaneously forwards from the start
point, and backwards from the goal, and stop
when the two searches meet in the middle.
• Problems: generate predecessors; many goal
states; efficient check for node already visited
by other half of the search; and, what kind of
search.
Artificial Intelligence Searching