0% found this document useful (0 votes)
4 views36 pages

Lec 2-Uninformed Searches - Part 2

Uploaded by

r.arshadr12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views36 pages

Lec 2-Uninformed Searches - Part 2

Uploaded by

r.arshadr12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

ARTIFICIAL

INTELLIGENCE

Dr. Momina Moetesum


Lecture 2
19th Sept 2024
Today
• Uninformed Search Methods
• Uniform-Cost Search
• Iterative Deepening Search
Uniform Cost (Tree) Search
2 a G
Strategy: expand a cheapest b c
node first: 1 8 2
2 e
3 d f
Frontier is a priority queue 9 2
S h 8
(priority: cumulative cost) 1
1 p q r
15

S 0

d 3 e 9 p 1

b 4 c e 5 h 17 r 11 q 16
11
Cost a 6 a h 13 r 7 p q f
contours
p q f 8 q c G

q 11 c G 10 a

a
function UNIFORM-COST-SEARCH(problem) returns a solution, or failure
initialize the explored set to be empty
initialize the frontier as a priority queue using node path_cost as the priority
add initial state of problem to frontier with path_cost = 0
2 C
loop do G
A 4
if the frontier is empty then 1
3
return failure S B D
4 1
choose a node and remove it from the frontier
if the node contains a goal state then
return the corresponding solution
add the node state to the explored set
for each resulting child from node
if the child state is not already in the frontier or explored set then
add child to the frontier
else if the child is already in the frontier with higher path_cost then
replace that frontier node with child
Uniform Cost Search (UCS)

• Extension of BFS:
• Expand node with lowest path cost
• Implementation: fringe = priority queue
ordered by path cost.
• UCS is the same as BFS when all step-costs are
equal.
• UCS does not care about the number of steps a path has, but
only about their total cost
Uniform Cost Search (UCS)

generalSearch(problem, priorityQueue)
# of nodes tested: 0, expanded: 0
S
start
expnd. Frontier list
node 5 2 4
{S}
A B C

9 4 6 2
6 G 1
D E goal F

H
Uniform Cost Search (UCS)

generalSearch(problem, priorityQueue)
S
# of nodes tested: 1, expanded: 1 start
expnd. Frontier list
node 5 2 4
{S:0}
A B C
S not goal {B:2,C:4,A:5}
9 4 6 2
6 G 1
D E goal F

H
Uniform Cost Search (UCS)

generalSearch(problem, priorityQueue)
S
# of nodes tested: 2, expanded: 2 start
expnd. Frontier list
node 5 2 4
{S}
A B C
S {B:2,C:4,A:5}
B not goal {C:4,A:5,G:2+6} 9 4 6 2
6 G 1
D E goal F

H
Uniform Cost Search (UCS)

generalSearch(problem, priorityQueue)
S
# of nodes tested: 3, expanded: 3 start
expnd. Frontier list
node 5 2 4
{S}
A B C
S {B:2,C:4,A:5}
B {C:4,A:5,G:8} 9 4 6 2
C not goal {A:5,F:4+2,G:8}
6 G 1
D E goal F

H
Uniform Cost Search (UCS)

generalSearch(problem, priorityQueue)
S
# of nodes tested: 4, expanded: 4 start
expnd. Frontier list
node 5 2 4
{S}
A B C
S {B:2,C:4,A:5}
B {C:4,A:5,G:8} 9 4 6 2
C {A:5,F:6,G:8}
6 G 1
A not goal {F:6,G:8,E:5+4, D E goal F
D:5+9}
7

H
Uniform Cost Search (UCS)

generalSearch(problem, priorityQueue) S
start
# of nodes tested: 5, expanded: 5
expnd. Frontier list 5 2 4
node
{S} A B C
S {B:2,C:4,A:5}
B {C:4,A:5,G:8} 9 4 6 2
C {A:5,F:6,G:8} 6 G 1
D E goal F
A {F:6,G:8,E:9,D:14
}
7
F not goal {G:4+2+1,G:8,E:9
,D:14} H
Uniform Cost Search (UCS)
generalSearch(problem, priorityQueue)
S
# of nodes tested: 6, expanded: 5 start
expnd. node Frontier list
5 2 4
{S}
A B C
S {B:2,C:4,A:5}
B {C:4,A:5,G:8} 9 4 6 2
C {A:5,F:6,G:8}
6 G 1
A {F:6,G:8,E:9,D:14} D E goal F

F {G:7,G:8,E:9,D:14} 7

G goal {G:8,E:9,D:14} H
no expand
Uniform Cost Search (UCS)

generalSearch(problem, priorityQueue)
S
# of nodes tested: 6, expanded: 5 start
expnd. Frontier list
node 5 2 4
{S}
A B C
S {B:2,C:4,A:5}
B {C:4,A:5,G:8} 9 4 6 2
C {A:5,F:6,G:8}
6 G 1
A {F:6,G:8,E:9,D:14} D E goal F
F {G:7,G:8,E:9,D:14}
G {G:8,E:9,D:14} 7
path: S,C,F,G
H cost: 7
Uniform Cost Search (UCS)
Properties
• What nodes does UCS expand?
b c1
• Processes all nodes with cost less than cheapest solution! …
• If that solution costs C* and minimum arcs cost at least  , c2
C*/
then the “effective depth” is roughly C*/
“tiers” c3
• Takes time O(b C*/
) (exponential in effective depth)

• How much space does the fringe take?


• Has roughly the last tier, so O(bC*/)

• Is it complete?
• Assuming best solution has a finite cost and minimum arc
cost is positive, yes!

• Is it optimal?
• Yes! (Proof next lecture via A*)
Uniform Cost Issues
… c1
• Remember: UCS explores increasing c2
cost contours c3

• The good: UCS is complete and


optimal!

• The bad:
• Explores options in every “direction” Start Goal
• No information about goal location

• We’ll fix that soon!


A Note on Implementation
Nodes have
state, parent, action, path-cost

A child of node by action a has


state = result(node.state,a)
parent = node
action = a
path-cost = node.path_cost +
step_cost(node.state, a, self.state)
Extract solution by tracing back parent pointers, collecting actions
Uniform Cost Search (UCS)
Properties
• What nodes does UCS expand?
• Processes all nodes with cost less than cheapest solution!
• If that solution costs C* and arcs cost at least  , then the
“effective depth” is roughly C*/
• Takes time O(bC*/) (exponential in effective depth)
b c1

• How much space does the frontier take? c2
• Has roughly the last tier, so O(bC*/) C*/ “tiers”
c3
• Is it complete?
• Assuming best solution has a finite cost and minimum arc cost is
positive, yes!

• Is it optimal?
• Yes! (Proof next lecture via A*)
Uniform Cost Issues
• Remember: … c1
c2
 UCS explores increasing cost contours
c3

• The good:
 UCS is complete and optimal!

• The bad:
• Explores options in every “direction”
• No information about goal location Start Goal

• We’ll fix that soon!


Iterative-Deepening Search (IDS)

• IDS is a general strategy often used with depth first search, that finds
the best depth limit.
• Gradually increases the limit, first 0, then 1, then 2 and so on until a
goal is found.
• This occurs when the depth limit reaches d, the depth of shallowest
goal node.
Iterative-Deepening Search (IDS)

• IDS combines benefits of both DFS and BFS.

• Like depth-first search, its memory requirements are very modest:


O(bd) to be precise.

• Like breadth-first search, it is complete when the branching factor is


finite and optimal when the path cost is a nondecreasing function of
the depth of the node.
Iterative-Deepening Search (IDS)

In general, iterative deepening is the preferred uninformed search method when there is a
large search space and the depth of the solution is not known.
Iterative-Deepening Search (IDS)

deepeningSearch(problem)
S
depth: 1, # of nodes tested: 1, expanded: 1 start
expnd. Frontier
node 5 2 4
{S}
S not goal {A,B,C} A B C

9 4 6 2
6 G 1
D E goal F

H
22
Iterative-Deepening Search (IDS)

deepeningSearch(problem)
S
depth: 1, # of nodes tested: 2, expanded: 1 start
expnd. Frontier
node 5 2 4
{S}
S {A,B,C} A B C
A not goal {B,C} no expand
9 4 6 2
6 G 1
D E goal F

H
23
Iterative-Deepening Search (IDS)

deepeningSearch(problem)
S
depth: 1, # of nodes tested: 3, expanded: 1 start
expnd. Frontier
node 5 2 4
{S}
S {A,B,C} A B C
A {B,C}
9 4 6 2
B not goal {C} no expand
6 G 1
D E goal F

H
24
Iterative-Deepening Search (IDS)

deepeningSearch(problem)
S
depth: 1, # of nodes tested: 4, expanded: 1 start
expnd. Frontier
node 5 2 4
{S}
S {A,B,C} A B C
A {B,C}
9 4 6 2
B {C}
C not goal { } no expand- 6 G 1
D E goal F
FAIL
7

H
25
Iterative-Deepening Search (IDS)

deepeningSearch(problem)
S
depth: 2, # of nodes tested: 4, expanded: 2 start
expnd. Frontier
node 5 2 4
{S}
S {A,B,C} A B C
A {B,C}
9 4 6 2
B {C}
C {} 6 G 1
D E goal F
S no test {A,B,C}
7

H
26
Iterative-Deepening Search (IDS)

deepeningSearch(problem)
S
depth: 2, # of nodes tested: 4, expanded: 3 start
expnd. Frontier
node 5 2 4
{S}
S {A,B,C} A B C
A {B,C}
9 4 6 2
B {C}
C {} 6 G 1
D E goal F
S {A,B,C}
A no test {D,E,B,C} 7

H
27
Iterative-Deepening Search (IDS)

deepeningSearch(problem)
S
depth: 2, # of nodes tested: 5, expanded: 3 start
expnd. Frontier
node 5 2 4
{S}
S {A,B,C} A B C
A {B,C}
9 4 6 2
B {C}
C {} 6 G 1
D E goal F
S {A,B,C}
A {D,E,B,C} 7
D not goal {E,B,C} no
expand H
28
Iterative-Deepening Search (IDS)

deepeningSearch(problem)
S
depth: 2, # of nodes tested: 6, expanded: 3 start
expnd. Frontier
node 5 2 4
{S}
S {A,B,C} A B C
A {B,C}
9 4 6 2
B {C}
C {} 6 G 1
D E goal F
S {A,B,C}
A {D,E,B,C} 7
D {E,B,C}
E not goal {B,C} no expand H
29
Iterative-Deepening Search (IDS)
deepeningSearch(problem)

depth: 2, # of nodes tested: 6, expanded: 4

expnd. Frontier S
node start
{S} 5 2 4
S {A,B,C}
A {B,C} A B C
B {C}
C {} 9 4 6 2
S {A,B,C} 6 G 1
D E goal F
A {D,E,B,C}
D {E,B,C}
7
E {B,C}
B no test {G,C} H
30
Iterative-Deepening Search (IDS)
deepeningSearch(problem)
depth: 2, # of nodes tested: 7, expanded: 4

expnd. Frontier
S
node start
{S}
S {A,B,C} 5 2 4
A {B,C}
A B C
B {C}
C {} 9 4 6 2
S {A,B,C}
6 G 1
A {D,E,B,C} D E goal F
D {E,B,C}
E {B,C} 7
B {G,C}
G goal {C} no expand H
31
Iterative-Deepening Search (IDS)

deepeningSearch(problem)
depth: 2, # of nodes tested: 7, expanded: 4
expnd. Frontier S
node start
{S} 5 2 4
S {A,B,C}
A {B,C} A B C
B {C}
C {} 9 4 6 2
S {A,B,C} 6 G 1
A {D,E,B,C} D E goal F
D {E,B,C}
7
E {B,C}
path: S,B,G
B {G,C} H cost: 8
G {C} 32
Iterative Deepening
• Idea: get DFS’s space advantage with BFS’s
b
time / shallow-solution advantages …
• Run a DFS with depth limit 1. If no solution…
• Run a DFS with depth limit 2. If no solution…
• Run a DFS with depth limit 3. …..

• Isn’t that wastefully redundant?


• Generally most work happens in the lowest level
searched, so not so bad!
Properties of iterative deepening search

• Complete? Yes

• Time? (d+1)b0 + d b1 + (d-1)b2 + … + bd = O(bd)

• Space? O(bd)

• Optimal? Yes, if step cost = 1

34
• Notes added on LMS
• https://www.oreilly.com/library/view/graph-algorithms/
9781492047674/ch04.html
Acknowledgment

• Most of the Content of these slides are taken from


Dr. Seemab Latif (Assoc. Prof/HoD DS & AI).
• Other resources include:
• http://aima.cs.berkeley.edu/

• It is only for educational purposes with no


copyright infringement intended

36

You might also like