Download Uninformed search algorithms

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Uninformed search algorithms
Chapter 3, Section 4
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
1
Tree search algorithms
Basic idea:
offline, simulated exploration of state space
by generating successors of already-explored states
(a.k.a. expanding states)
function Tree-Search( problem) returns a solution, or failure
initialize the frontier using the initial state of problem
loop do
if the frontier is empty then return failure
choose a leaf node and remove it from the frontier
if the node contains a goal state then return the corresponding solution
expand the chosen node and add the resulting nodes to the frontier
end
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
2
Tree search example
Arad
Timisoara
Sibiu
Arad
Fagaras
Oradea
Rimnicu Vilcea
Arad
Zerind
Lugoj
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Arad
Oradea
Chapter 3, Section 4
3
Tree search example
Arad
Timisoara
Sibiu
Arad
Fagaras
Oradea
Rimnicu Vilcea
Arad
Zerind
Lugoj
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Arad
Oradea
Chapter 3, Section 4
4
Tree search example
Arad
Timisoara
Sibiu
Arad
Fagaras
Oradea
Rimnicu Vilcea
Arad
Zerind
Lugoj
Arad
Oradea
Note: Arad is one of the expanded nodes!
This corresponds to going to Sibiu and then returning to Arad.
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
5
Implementation: states vs. nodes
A state is a (representation of) a physical configuration
A node is a data structure constituting part of a search tree
– includes the state, parent, children, depth, and the path cost g(x)
States do not have parents, children, depth, or path cost!
parent, action
State
5
4
6
1
Node
depth = 6
g=6
7
3
88
22
state
The Expand function creates new nodes, filling in the various fields and
using the SuccessorFn of the problem to create the corresponding states.
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
6
Implementation: general tree search
function Tree-Search( problem) returns a solution, or failure
frontier ← {Make-Node(Initial-State[problem])}
loop do
if frontier is empty then return failure
node ← Remove-Front(frontier)
if Goal-Test(problem, State[node]) return node
frontier ← InsertAll(Expand(node, problem), frontier)
function Expand( node, problem) returns a set of nodes
successors ← the empty set
for each action, result in Successor-Fn(problem, State[node]) do
s ← a new Node
Parent-Node[s] ← node; Action[s] ← action; State[s] ← result
Path-Cost[s] ← Path-Cost[node] +
Step-Cost(State[node], action, result)
Depth[s] ← Depth[node] + 1
add s to successors
return successors
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
7
Search strategies
A strategy is defined by picking the order of node expansion
Strategies are evaluated along the following dimensions:
completeness—does it always find a solution if one exists?
optimality—does it always find a least-cost solution?
time complexity—number of nodes generated/expanded
space complexity—maximum number of nodes in memory
Time and space complexity are measured in terms of
b—maximum branching factor of the search tree
d—depth of the least-cost solution
m—maximum depth of the state space (may be ∞)
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
8
Uninformed search strategies
Uninformed strategies use only the information available
in the problem definition
♦ Breadth-first search
♦ Uniform-cost search
♦ Depth-first search
♦ Depth-limited search
♦ Iterative deepening search
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
9
Breadth-first search
Expand the shallowest unexpanded node
Implementation:
frontier is a FIFO queue, i.e., new successors go at end
A
B
D
C
E
F
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
G
Chapter 3, Section 4
10
Breadth-first search
Expand shallowest unexpanded node
Implementation:
frontier is a FIFO queue, i.e., new successors go at end
A
B
D
C
E
F
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
G
Chapter 3, Section 4
11
Breadth-first search
Expand shallowest unexpanded node
Implementation:
frontier is a FIFO queue, i.e., new successors go at end
A
B
D
C
E
F
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
G
Chapter 3, Section 4
12
Breadth-first search
Expand shallowest unexpanded node
Implementation:
frontier is a FIFO queue, i.e., new successors go at end
A
B
D
C
E
F
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
G
Chapter 3, Section 4
13
Properties of breadth-first search
Complete?? Yes (if b is finite)
Time?? 1 + b + b2 + b3 + . . . + bd + b(bd − 1) = O(bd),
i.e., exponential in d
Space?? O(bd) (keeps every node in memory)
Optimal?? Yes, if step cost = 1
Not optimal in general
Space is the big problem:
it can easily generate 1M nodes/second
so after 24hrs it has used 86,000GB
(and then it has only reached depth 9 in the search tree)
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
14
Uniform-cost search
Expand the cheapest unexpanded node
Implementation:
frontier = priority queue ordered by path cost g(n)
Equivalent to breadth-first search, if all step costs are equal
Complete?? Yes, if step cost ≥ ǫ > 0
∗
⌈C ∗ /ǫ⌉
Time?? # of nodes with g(n) ≤ C , i.e., O(b
where C ∗ is the cost of the optimal solution
and ǫ is the minimal step cost
)
Space?? Same as time
Optimal?? Yes—nodes are expanded in increasing order of g(n)
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
15
Depth-first search
Expand the deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
A
B
C
D
H
E
I
J
F
K
L
G
M
N
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
O
Chapter 3, Section 4
16
Depth-first search
Expand the deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
A
B
C
D
H
E
I
J
F
K
L
G
M
N
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
O
Chapter 3, Section 4
17
Depth-first search
Expand the deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
A
B
C
D
H
E
I
J
F
K
L
G
M
N
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
O
Chapter 3, Section 4
18
Depth-first search
Expand the deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
A
B
C
D
H
E
I
J
F
K
L
G
M
N
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
O
Chapter 3, Section 4
19
Depth-first search
Expand the deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
A
B
C
D
H
E
I
J
F
K
L
G
M
N
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
O
Chapter 3, Section 4
20
Depth-first search
Expand the deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
A
B
C
D
H
E
I
J
F
K
L
G
M
N
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
O
Chapter 3, Section 4
21
Properties of depth-first search
Complete?? No: it fails in infinite-depth spaces
it also fails in finite spaces with loops
but if we modify the search to avoid repeated states
⇒ complete in finite spaces (even with loops)
Time?? O(bm): terrible if m is much larger than d
but if solutions are dense, it may be much faster than breadth-first
Space?? O(bm): i.e., linear space!
Optimal?? No
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
22
Depth-limited search
Depth-first search with depth limit l, i.e., nodes at depth l have no successors
Recursive implementation:
function Depth-Limited-Search( problem, limit) returns soln/failure/cutoff
Recursive-DLS(Make-Node(Initial-State[problem]), problem, limit)
function Recursive-DLS(node, problem, limit) returns soln/failure/cutoff
if Goal-Test(problem, State[node]) then return node
else if limit = 0 then return cutoff
else
cutoff-occurred? ← false
for each action in Actions(State[node], problem) do
child ← Child-Node(problem, node, action)
result ← Recursive-DLS(child, problem, limit – 1)
if result = cutoff then cutoff-occurred? ← true
else if result 6= failure then return result
if cutoff-occurred? then return cutoff else return failure
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
23
Iterative deepening search
Successive depth-limited searches, with higher and higher depth limits,
until a goal is found.
function Iterative-Deepening-Search( problem) returns solution/failure
for depth ← 0 to ∞ do
result ← Depth-Limited-Search( problem, depth)
if result 6= cutoff then return result
end
Note: This means that shallow nodes will be recalculated several times!
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
24
Iterative deepening search l = 0
Limit = 0
A
A
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
25
Iterative deepening search l = 1
Limit = 1
A
B
A
C
B
A
C
B
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
A
C
B
Chapter 3, Section 4
C
26
Iterative deepening search l = 2
Limit = 2
A
A
B
D
C
E
F
B
G
D
C
E
A
C
E
F
F
G
D
C
E
D
C
E
F
B
G
D
C
E
A
B
G
A
B
A
B
D
A
F
D
C
E
G
A
B
G
F
F
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
B
G
D
C
E
F
Chapter 3, Section 4
G
27
Iterative deepening search l = 3
Limit = 3
A
A
B
C
D
H
E
J
I
B
F
K
L
N
C
D
G
M
O
H
E
I
J
K
C
E
I
J
G
M
L
N
D
O
H
E
I
C
E
I
J
I
J
K
J
L
K
L
G
G
M
N
O
H
J
M
N
O
H
I
J
F
K
O
H
E
I
J
L
G
L
G
M
N
O
H
J
M
N
O
H
E
I
J
F
L
K
G
M
B
F
K
O
N
O
A
E
I
N
C
D
C
D
M
L
B
F
K
G
A
B
F
K
N
E
A
E
I
M
L
C
D
C
D
C
D
G
B
F
B
F
K
H
F
A
B
H
O
E
C
A
D
D
B
A
B
F
K
N
C
A
B
H
G
M
L
A
B
F
A
D
A
L
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
G
M
N
C
D
O
H
E
I
J
F
K
L
G
M
Chapter 3, Section 4
N
28
O
Properties of iterative deepening search
Complete?? Yes
Time?? (d + 1)b0 + db1 + (d − 1)b2 + . . . + bd = O(bd)
Space?? O(bd)
Optimal?? Yes, if step cost = 1
it can be modified to explore a uniform-cost tree
Numerical comparison for b = 10 and d = 5:
N (BFS) = 10 + 100 + 1, 000 + 10, 000 + 100, 000 = 111, 110
N (IDS) = 50 + 400 + 3, 000 + 20, 000 + 100, 000 = 123, 450
Note: IDS recalculates shallow nodes several times,
but this doesn’t have a big effect compared to BFS!
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
29
Summary of algorithms
Criterion
BreadthFirst
Complete?
Time
Space
Optimal?
b
d
m
l
ǫ
C∗
=
=
=
=
=
=
the
the
the
the
the
the
UniformCost
DepthFirst
Yes
Yes, if ǫ > 0
No
∗
bd
b⌈C /ǫ⌉
bm
∗
bd
b⌈C /ǫ⌉
bm
Yes∗
Yes
No
∗
if all step costs are identical
DepthLimited
Iterative
Deepening
Yes, if l ≥ d
bl
bl
No
Yes
bd
bd
Yes∗
branching factor
depth of the shallowest solution
maximum depth of the tree
depth limit
smallest step cost
cost of the optimal solution
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
30
Repeated states
Failure to detect repeated states can turn a linear problem exponential!
A
A
B
C
B
C
B
C
C
C
D
Solution: Use graph search instead of tree search!
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
31
Graph search
We augment the tree search algorithm with a set explored,
which remembers every expanded node
function Graph-Search( problem) returns a solution, or failure
frontier ← {Make-Node(Initial-State[problem])}
explored ← { }
loop do
if frontier is empty then return failure
node ← Remove-Front(frontier)
if Goal-Test(problem, State[node]) then return node
add State[node] to explored
if State[node] is not in frontier ∪ explored then
frontier ← InsertAll(Expand(node, problem), frontier)
end
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
32
Summary
Variety of uninformed search strategies:
– breadth-first search
– uniform-cost search
– depth-first search
– depth-limited search
– iterative deepening search
Iterative deepening search uses only linear space
and not much more time than other uninformed algorithms
Graph search can be exponentially more efficient than tree search
c
Artificial Intelligence, spring 2013, Peter Ljunglöf; based on AIMA Slides Stuart
Russel and Peter Norvig, 2004
Chapter 3, Section 4
33
Related documents