01. [AI - Slides] Search - Uninformed Search
01. [AI - Slides] Search - Uninformed Search
1
Models To Be Studied in CS 540
State-based Models
– Model task as a graph of all possible states
⚫ Called a “state-space graph”
⚫ Puzzles
⚫ Games
⚫ Navigation
⚫ Assignment
⚫ Motion planning
⚫ Scheduling
⚫ Routing
Search Example: Route Finding
Goal: All on
right side of river
Rules:
1) Farmer must row the boat
2) Only room for one other Actions: F>, F<,
3) Without the farmer present: FC>, FC<, FD>,
• Dog bites sheep FD<, FS>, FS<
• Sheep eats cabbage
Search Example: 8-Puzzle
4 3
Search Example: Robot Motion Planning
12
What Goal does the Agent want to
Achieve?
⚫ How do you know when the goal is reached?
– with a goal test that defines what it means
to have achieved the goal
– or, with a set of goal states
13
What Actions does the Agent Need?
⚫ Given:
– an action (aka operator or move)
– a description of the current state of the world
15
Search Example: 8-Puzzle
⚫ States = configurations
⚫ Actions = up to 4 kinds of moves: up, down, left,
right
Water Jugs Problem
Given 4-liter and 3-liter pitchers, how do you get exactly 2
liters into the 4-liter pitcher?
4 3
State: (x, y) for # liters in 4-liter and 3-liter pitchers, respectively
Actions: empty, fill, pour water between pitchers
Initial state: (0, 0)
Goal state: (2, *)
Action / Successor Functions
19
Formalizing Search in a State Space
20
Formalizing Search in a State Space
21
Formalizing Search in a State Space
22
Search Summary
a GOAL
t
b c
e
d
f
START h
p r
q
u
28
8-Puzzle State-Space Search Tree
(Not all nodes shown;
e.g., no “backwards”
moves)
Uninformed Search Strategies
Goal
Breadth-First Search (BFS)
generalSearch(problem, queue)
S
# of nodes tested: 0, expanded: 0 start
expnd. node Frontier list
{S} 5 2 4
A B C
9 4 6 2
6 G 1
D E goal F
H
33
Breadth-First Search (BFS)
generalSearch(problem, queue)
S
# of nodes tested: 1, expanded: 1 start
expnd. node Frontier list
{S} 5 2 4
S not goal {A,B,C}
A B C
9 4 6 2
6 G 1
D E goal F
H
34
Breadth-First Search (BFS)
generalSearch(problem, queue)
S
# of nodes tested: 2, expanded: 2 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A not goal {B,C,D,E}
9 4 6 2
6 G 1
D E goal F
H
35
Breadth-First Search (BFS)
generalSearch(problem, queue)
S
# of nodes tested: 3, expanded: 3 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A {B,C,D,E}
B not goal {C,D,E,G}
9 4 6 2
6 G 1
D E goal F
H
36
Breadth-First Search (BFS)
generalSearch(problem, queue)
S
# of nodes tested: 4, expanded: 4 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A {B,C,D,E}
B {C,D,E,G}
9 4 6 2
C not goal {D,E,G,F}
6 G 1
D E goal F
H
37
Breadth-First Search (BFS)
generalSearch(problem, queue)
S
# of nodes tested: 5, expanded: 5 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A {B,C,D,E}
B {C,D,E,G}
9 4 6 2
C {D,E,G,F}
6 G 1
D not goal {E,G,F,H} D E goal F
H
38
Breadth-First Search (BFS)
generalSearch(problem, queue)
S
# of nodes tested: 6, expanded: 6 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A {B,C,D,E}
B {C,D,E,G}
9 4 6 2
C {D,E,G,F}
6 G 1
D {E,G,F,H} D E goal F
E not goal {G,F,H,G}
7
H
39
Breadth-First Search (BFS)
generalSearch(problem, queue)
S
# of nodes tested: 7, expanded: 6 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A {B,C,D,E}
B {C,D,E,G}
9 4 6 2
C {D,E,G,F}
6 G 1
D {E,G,F,H} D E goal F
E {G,F,H,G}
G goal {F,H,G} no expand 7
H
40
Breadth-First Search (BFS)
generalSearch(problem, queue)
S
# of nodes tested: 7, expanded: 6 start
expnd. node Frontier list
{S} 5 2 4
S {A,B,C}
A B C
A {B,C,D,E}
B {C,D,E,G}
9 4 6 2
C {D,E,G,F}
6 G 1
D {E,G,F,H} D E goal F
E {G,F,H,G}
G {F,H,G} 7
path: S,B,G
H cost: 8
41
Evaluating Search Strategies
⚫ Completeness
If a solution exists, will it be found?
– a complete algorithm will find a solution (not all)
⚫ Optimality / Admissibility
If a solution is found, is it guaranteed to be optimal?
– an admissible algorithm will find a solution with
minimum cost
43
Evaluating Search Strategies
⚫ Time Complexity
How long does it take to find a solution?
– usually measured for worst case
– measured by counting number of nodes expanded,
including goal node, if found
⚫ Space Complexity
How much space is used by the algorithm?
– measured in terms of the maximum size
of Frontier during the search
44
What’s in the Frontier for BFS?
Goal
Breadth-First Search (BFS)
⚫ Complete?
– Yes
⚫ Optimal / Admissible?
– Yes, if all operators (i.e., arcs) have the same
constant cost, or costs are positive, non-decreasing
with depth
– otherwise, not optimal but does guarantee finding
solution of shortest length (i.e., fewest arcs)
46
Breadth-First Search (BFS)
47
Breadth-First Search (BFS)
48
Depth-First Search
Expand the deepest node first
1. Select a direction, go deep to the end
2. Slightly change the end
3. Slightly change the end some more…
Use a Stack to order nodes in Frontier
Goal
Depth-First Search (DFS)
generalSearch(problem, stack)
S
# of nodes tested: 0, expanded: 0 start
expnd. node Frontier
{S} 5 2 4
A B C
9 4 6 2
6 G 1
D E goal F
H
53
Depth-First Search (DFS)
generalSearch(problem, stack)
S
# of nodes tested: 1, expanded: 1 start
expnd. node Frontier
{S} 5 2 4
S not goal {A,B,C}
A B C
9 4 6 2
6 G 1
D E goal F
H
54
Depth-First Search (DFS)
generalSearch(problem, stack)
S
# of nodes tested: 2, expanded: 2 start
expnd. node Frontier
{S} 5 2 4
S {A,B,C}
A B C
A not goal {D,E,B,C}
9 4 6 2
6 G 1
D E goal F
H
55
Depth-First Search (DFS)
generalSearch(problem, stack)
S
# of nodes tested: 3, expanded: 3 start
expnd. node Frontier
{S} 5 2 4
S {A,B,C}
A B C
A {D,E,B,C}
D not goal {H,E,B,C}
9 4 6 2
6 G 1
D E goal F
H
56
Depth-First Search (DFS)
generalSearch(problem, stack)
S
# of nodes tested: 4, expanded: 4 start
expnd. node Frontier
{S} 5 2 4
S {A,B,C}
A B C
A {D,E,B,C}
D {H,E,B,C}
9 4 6 2
H not goal {E,B,C}
6 G 1
D E goal F
H
57
Depth-First Search (DFS)
generalSearch(problem, stack)
S
# of nodes tested: 5, expanded: 5 start
expnd. node Frontier
{S} 5 2 4
S {A,B,C}
A B C
A {D,E,B,C}
D {H,E,B,C}
9 4 6 2
H {E,B,C}
6 G 1
E not goal {G,B,C} D E goal F
H
58
Depth-First Search (DFS)
generalSearch(problem, stack)
S
# of nodes tested: 6, expanded: 5 start
expnd. node Frontier
{S} 5 2 4
S {A,B,C}
A B C
A {D,E,B,C}
D {H,E,B,C}
9 4 6 2
H {E,B,C}
6 G 1
E {G,B,C} D E goal F
G goal {B,C} no expand
7
H
59
Depth-First Search (DFS)
generalSearch(problem, stack)
S
# of nodes tested: 6, expanded: 5 start
expnd. node Frontier
{S} 5 2 4
S {A,B,C}
A B C
A {D,E,B,C}
D {H,E,B,C}
9 4 6 2
H {E,B,C}
6 G 1
E {G,B,C} D E goal F
G {B,C}
7
path: S,A,E,G
H cost: 15
60
Depth-First Search (DFS)
⚫ May not terminate without a depth bound
i.e., cutting off search below a fixed depth, D
⚫ Not complete
– with or without cycle detection
– and, with or without a depth cutoff
63
Depth-First Search (DFS)
64
Uniform-Cost Search (UCS)
65
Uniform-Cost Search (UCS)
generalSearch(problem, priorityQueue)
S
# of nodes tested: 0, expanded: 0 start
expnd. node Frontier list
{S} 5 2 4
A B C
9 4 6 2
6 G 1
D E goal F
H
66
Uniform-Cost Search (UCS)
generalSearch(problem, priorityQueue)
S
# of nodes tested: 1, expanded: 1 start
expnd. node Frontier list
{S:0} 5 2 4
S not goal {B:2,C:4,A:5}
A B C
9 4 6 2
6 G 1
D E goal F
H
67
Uniform-Cost Search (UCS)
generalSearch(problem, priorityQueue)
S
# of nodes tested: 2, expanded: 2 start
expnd. node Frontier list
{S} 5 2 4
S {B:2,C:4,A:5}
A B C
B not goal {C:4,A:5,G:2+6}
9 4 6 2
6 G 1
D E goal F
H
68
Uniform-Cost Search (UCS)
generalSearch(problem, priorityQueue)
S
# of nodes tested: 3, expanded: 3 start
expnd. node Frontier list
{S} 5 2 4
S {B:2,C:4,A:5}
A B C
B {C:4,A:5,G:8}
C not goal {A:5,F:4+2,G:8}
9 4 6 2
6 G 1
D E goal F
H
69
Uniform-Cost Search (UCS)
generalSearch(problem, priorityQueue)
S
# of nodes tested: 4, expanded: 4 start
expnd. node Frontier list
{S} 5 2 4
S {B:2,C:4,A:5}
A B C
B {C:4,A:5,G:8}
C {A:5,F:6,G:8}
9 4 6 2
A not goal {F:6,G:8,E:5+4,
D:5+9} 6 G 1
D E goal F
H
70
Uniform-Cost Search (UCS)
generalSearch(problem, priorityQueue)
S
# of nodes tested: 5, expanded: 5 start
expnd. node Frontier list
{S} 5 2 4
S {B:2,C:4,A:5}
A B C
B {C:4,A:5,G:8}
C {A:5,F:6,G:8}
9 4 6 2
A {F:6,G:8,E:9,D:14}
6 G 1
F not goal {G:4+2+1,G:8,E:9, D E goal F
D:14}
7
H
71
Uniform-Cost Search (UCS)
generalSearch(problem, priorityQueue)
S
# of nodes tested: 6, expanded: 5 start
expnd. node Frontier list
{S} 5 2 4
S {B:2,C:4,A:5}
A B C
B {C:4,A:5,G:8}
C {A:5,F:6,G:8}
9 4 6 2
A {F:6,G:8,E:9,D:14}
6 G 1
F {G:7,G:8,E:9,D:14} D E goal F
G goal {G:8,E:9,D:14}
no expand 7
H
72
Uniform-Cost Search (UCS)
generalSearch(problem, priorityQueue)
S
# of nodes tested: 6, expanded: 5 start
expnd. node Frontier list
{S} 5 2 4
S {B:2,C:4,A:5}
A B C
B {C:4,A:5,G:8}
C {A:5,F:6,G:8}
9 4 6 2
A {F:6,G:8,E:9,D:14}
6 G 1
F {G:7,G:8,E:9,D:14} D E goal F
G {G:8,E:9,D:14}
7
path: S,C,F,G
H cost: 7
73
Uniform-Cost Search (UCS)
⚫ Complete
⚫ Optimal / Admissible
– requires that the goal test is done when a node is
removed from the Frontier rather than when the
node is generated by its parent node
76
Uniform-Cost Search (UCS)
77
Example
S
1 5 8
A B C
3 7 9 4 5 How are nodes expanded by
⚫ Breadth-First Search: S A B C D E G
Solution found: S A G
⚫ Uniform-Cost Search: S A D B C E G
Solution found: S B G