Breadth-First Searches G5AIAI – Introduction to AI Breadth-First Search • Using a breadth-first strategy we expand the root level first and then we.

Download Report

Transcript Breadth-First Searches G5AIAI – Introduction to AI Breadth-First Search • Using a breadth-first strategy we expand the root level first and then we.

Breadth-First Searches
G5AIAI – Introduction to AI
Breadth-First Search
• Using a breadth-first strategy we expand the root level first and then
we expand all those nodes (i.e. those at level 1) before we expand any
nodes at level 2.
• Or to put it another way, all nodes at level d are expanded before any
nodes at level d+1.
Function BREADTH-FIRST-SEARCH(problem) returns a solution or
failure
Return GENERAL-SEARCH(problem,ENQUEUE-AT-END)
• To illustrate this search pattern we will be using an example node set
containing 26 nodes (states). The initial state will be node A, and the
goal state is node L. Press space to see the example node set.
The example node set
Initial state
A
B
C
D
E
F
Goal state
G H
I
J
K
L
M N
O
P
Q
S
T
U V
W X
Y
Z
R
Press space to see a BFS of the example node set
We
Node
The
then
B
search
isbacktrack
expanded
then moves
to
then
expand
to
removed
thenode
firstfrom
C,
nodethe
queue.
and
in the
theThe
queue.
process
revealed
Press
continues.
nodes
space Press
to
arecontinue.
added
spaceto the
END of the queue. Press space.
B
G H
C
I
A
Node
This
We begin
node
A is removed
is
with
then
our
expanded
from
initialthe
state:
to
queue.
reveal
the Each
node
further
revealed
labeled(unexpanded)
A.
node
Press
is added
spacenodes.
to continue
the Press
END space
of the
queue. Press space to continue the search.
D
J
K
E
L
F
M N
O
P
Node L is located and the search returns
a solution. Press space to end.
Q
R
S
T
U
Press space to continue
begin thethe
search
search
Size of Queue: 010
987651
Queue: A
B,J,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
Empty
K,
G,
C,
F,
M,
D,
E,
H,K,
I,
L,
J,
G,
L,
H,
F,
D,
E,
M,
I,
N,L,
K,
G,
J,
M,
H,
I,
F,
E,
O,
N,
M,
K,
L,
J,
G,
H,
I,
FN,
P,
O,
K,
M,
J,
L,
N,
H
I,O,
Q,
P,
K,
L,
JM,
O,
N,
P,
Q,
R,M,
LP,
O,
N,
Q,
S,
R,Q,
N
O,
P,
T,
R,
S,R
Q
U
P
S
T
Nodes expanded: 11
9876543210
10
CurrentFINISHED
Action: Backtracking
Expanding
SEARCH
Current level: 210n/a
BREADTH-FIRST SEARCH PATTERN