Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lecture 5 Uniform Cost Search

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 14

Uniform Cost Search Method

A
Z
75
T
118
S
140

T
118
S
140
O
146

S
140
O
146
L
229

O
146
L
229
R
230
F
239
O
291

L
229
R
230
F
239
O
291

R
230
F
239
O
291
M
299
Remedies space limitation of breadth first
by always generating a child of the
deepest unexpanded node.
Depth-First Search
http://www.rci.rutgers.edu/~cfs/472_html/AI_SEARCH/SearchAnimations.html
Implementation
Maintain a list of unexpanded nodes
treated as a LIFO stack (as opposed to
FIFO for breadth first
Usually implemented recrsively- with the
recursion stack taking the place of an
explicit node stack
Time complexity is O (bd)-Practically DF is time limited and BF
is space limited
Disadvantage: does not terminate if tree infinite
or cycles in graph
Solution: cutoff depth (d)
d small?
d large?
Use a stack data structure.
1. Push root node of tree on the stack.
2. Pop the top node off the stack. Call this
node N.
3. Push children of node N onto the stack in
right-to-left order (so they are popped in
left-to-right order).
4. Repeat steps 2 and 3 until stack is empty
or goal is reached.
Simple Algorithm
Depth First Iterative Deepening
The problem with depth-limited search is
determining an appropriate depth for the search.
We have a search method called depth first
iterative deepening search (IDS) that tries all
possible depth limits; 0, 1, 2 , until a solution is
found.
At first it seems wasteful as it is expanding
nodes multiple times. But the overhead is small
in comparison to the growth of an exponential
search tree
For huge search spaces- the depth of the
solution unknown, IDS is preferred.

Depth First Iterative Deepening
Combines best features of DF and BF
Performs a depth first to depth 1 then starts over
executing a complete depth first to depth 2 and
continues to run depth first searches to successive
greater depths until a solution is found.
Optimal in terms of time and space among all brute force algorithms on a tree.
Iterative deepening search L =3
A
C D E F B
G H I J K L M N O P
Q R S T U V W X Y Z
Initial state
Goal state
A
L
A A
We begin with our initial state: the node
labeled A. This node is added to the
queue. Press space to continue
Size of Queue: 0
Nodes expanded: 0 Current Action: Expanding Current level: n/a
Queue: Empty Queue: A Size of Queue: 1
Current level: 0 Nodes expanded: 1
Queue: Empty Size of Queue: 0
Press space to begin the search
As this is the 0
th
iteration of the search, we cannot search past any level greater than
zero. This iteration now ends, and we begin the 1
st
iteration.
ITERATIVE DEEPENING SEARCH PATTERN (0
th
ITERATION)
Node A is then expanded and removed
from the queue. Press space.
A
C D E F B
A
B C D
We again begin with our initial state: the
node labeled A. Note that the 1
st
iteration
carries on from the 0
th
, and therefore the
nodes expanded value is already set to 1.
Press space to continue
Node A is expanded, then removed from
the queue, and the revealed nodes are
added to the front . Press space.
The search now moves to level one of
the node set. Press space to continue
Node B is expanded and removed from the
queue. Press space.
Size of Queue: 0
Nodes expanded: 1 Current Action: Current level: n/a
Queue: Empty Queue: A Size of Queue: 1
Nodes expanded: 2
Queue: B, C, D, E, F
Press space to begin the search
Size of Queue: 5
Current level: 0 Current Action: Expanding
Queue: C, D, E, F Size of Queue: 4
Nodes expanded: 3 Current level: 1 Current Action: Backtracking Current level: 0 Current level: 1
Queue: D, E, F Size of Queue: 3
Nodes expanded: 4 Current Action: Expanding Current Action: Backtracking Current level: 0 Current level: 1
Queue: E, F Size of Queue: 2
Nodes expanded: 5 Current Action: Expanding Current Action: Backtracking Current level: 0 Current level: 1 Current Action: Expanding
Queue: F
E
Current Action: Backtracking Current level: 0 Current Action: Expanding Current level: 1
Queue: Empty
F
Current level: 0 Current level: 1
Press space to continue the search Press space to continue the search Press space to continue the search
ITERATIVE DEEPENING SEARCH PATTERN (1
st
ITERATION)
Size of Queue: 1 Size of Queue: 0
As this is the 1
st
iteration of the search, we cannot search past any level greater than
level one. This iteration now ends, and we begin a 2
nd
iteration.
Nodes expanded: 6 Nodes expanded: 7
We now back track to expand node C, and
the process continues. Press space.
A
C D E F B
G H I J K L
A
B
G
We again begin with our initial state:
the node labeled A. Note that the 2
nd

iteration carries on from the 1
st
, and
therefore the nodes expanded value is
already set to 7 (1+6). Press space to
continue the search
Again, we expand node A to reveal the
level one nodes. Press space.
Node A is removed from the queue and
each revealed node is added to the front of
the queue. Press space.
The search then moves to level one of
the node set. Press space to continue
Node B is expanded and the revealed
nodes added to the front of the queue.
Press space to continue.
Size of Queue: 0
Nodes expanded: 7 Current Action: Current level: n/a
Queue: Empty Queue: A Size of Queue: 1
Current level: 0 Nodes expanded: 8
Queue: B, C, D, E, F
Current level: 1
Queue: G, H, C, D, E, F
Nodes expanded: 9 Current level: 2
ITERATIVE DEEPENING SEARCH PATTERN (2
nd
ITERATION)
Size of Queue: 5
Current Action: Expanding
We now move to level two of the node
set. Press space to continue.
After expanding node G we backtrack
to expand node H. The process then
continues until goal state. Press space
Queue: H, C, D, E, F
Nodes expanded: 10 Current Action: Backtracking Current Action: Expanding
Queue: C, D, E, F Size of Queue: 6
Nodes expanded: 11
H
Press space to continue the search
Size of Queue: 5 Size of Queue: 4
Current Action: Backtracking Current Action: Expanding
Queue: I, J, D, E, F Size of Queue: 5
Nodes expanded: 12
Press space to continue the search
C
Current level: 1 Current level: 2 Current level: 1 Current level: 0 Current level: 1 Current level: 2
Queue: J, D, E, F Size of Queue: 4
Nodes expanded: 13
I
Press space to continue the search
Current Action: Backtracking Current level: 1 Current level: 2
Queue: D, E, F
Current Action: Expanding
Size of Queue: 3
Nodes expanded: 14
J
Press space to continue the search
Current Action: Backtracking Current level: 1 Current level: 0 Current level: 1 Current Action: Expanding
Queue: K, L, E, F Size of Queue: 4
Nodes expanded: 15
D
Press space to continue the search
Current level: 2
Queue: L, E, F Size of Queue: 3
Nodes expanded: 16
K
Press space to continue the search
Current Action: Expanding Current level: 1 Current level: 2
L L L L L
Current Action: Backtracking
Queue: Empty Size of Queue: 0
Node L is located on the second level and the search returns a solution
on its second iteration. Press space to end.
SEARCH FINISHED
Algorithm
Do DFS to depth 1
Treat all children of the start node as
leafs
If no solution found, do DFS to depth 2
Repeat by increasing depth until a
solution found

*Start node is at depth 0

You might also like