0% found this document useful (0 votes)
19 views128 pages

2022 Slide3 UninformSearch Eng

Uploaded by

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

2022 Slide3 UninformSearch Eng

Uploaded by

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

Artificial Intelligence

Solving Problems by searching


2
Outline: Problem solving by searching

• Introduction to Problem Solving

• Uninformed search (Blind Search)


• Problem formulation
• Search strategies: depth-first, breadth-first

• Informed search
• Search strategies: best-first, A*
• Heuristic functions

3
Example: Measuring problem!

9l
3l 5l

Problem: Using these three buckets,


measure 7 liters of water.

4
Example: Measuring problem!

• (one possible) Solution:

a b c 9l
0 0 0 start 3l 5l
3 0 0
0 0 3 a b c
3 0 3
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

5
Example: Measuring problem!

• (one possible) Solution:

a b c 9l
0 0 0 start 3l 5l
3 0 0
0 0 3 a b c
3 0 3
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

6
Example: Measuring problem!

• (one possible) Solution:

a b c 9l
0 0 0 start 3l 5l
3 0 0
0 0 3 a b c
3 0 3
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

7
Example: Measuring problem!

• (one possible) Solution:

a b c 9l
0 0 0 start 3l 5l
3 0 0
0 0 3 a b c
3 0 3
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

8
Example: Measuring problem!

• (one possible) Solution:

a b c 9l
0 0 0 start 3l 5l
3 0 0
0 0 3 a b c
3 0 3
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

9
Example: Measuring problem!

• (one possible) Solution:

a b c 9l
0 0 0 start 3l 5l
3 0 0
0 0 3 a b c
3 0 3
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

10
Example: Measuring problem!

• (one possible) Solution:

a b c 9l
0 0 0 start 3l 5l
3 0 0
0 0 3 a b c
3 0 3
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

11
Example: Measuring problem!

• (one possible) Solution:

a b c 9l
0 0 0 start 3l 5l
3 0 0
0 0 3 a b c
3 0 3
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

12
Example: Measuring problem!

• (one possible) Solution:

a b c 9l
0 0 0 start 3l 5l
3 0 0
0 0 3 a b c
3 0 3
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

13
Example: Measuring problem!

• (one possible) Solution:

a b c 9l
0 0 0 start 3l 5l
3 0 0
0 0 3 a b c
3 0 3
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

14
Example: Measuring problem!

• Another Solution:

a b c 9l
0 0 0 start 3l 5l
0 5 0
0 0 3 a b c
3 0 3
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

15
Example: Measuring problem!

• Another Solution:

a b c 9l
0 0 0 start 3l 5l
0 5 0
3 2 0 a b c
0 0 3
3 0 3
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

16
Example: Measuring problem!

• Another Solution:

a b c 9l
0 0 0 start 3l 5l
0 5 0
3 2 0 a b c
3 0 2
3 0 3
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

17
Example: Measuring problem!

• Another Solution:

a b c 9l
0 0 0 start 3l 5l
0 5 0
3 2 0 a b c
3 0 2
3 5 2
0 0 6
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

18
Example: Measuring problem!

• Another Solution:

a b c 9l
0 0 0 start 3l 5l
0 5 0
3 2 0 a b c
3 0 2
3 5 2
3 0 7 goal
3 0 6
0 3 6
3 3 6
1 5 6
0 5 7 goal

19
Which solution do we prefer?

• Solution 1: • Solution 2:

a b c a b c
0 0 0 start 0 0 0 start
3 0 0 0 5 0
0 0 3 3 2 0
3 0 3 3 0 2
0 0 6 3 5 2
3 0 6 3 0 7 goal
0 3 6
3 3 6
1 5 6
0 5 7 goal

20
Other Example:

21
Search Problems

22
Search
• We will consider the problem of designing goal-
based agents in fully observable,
deterministic, discrete, known environments
• The agent must find a sequence of actions that reaches
the goal
• The performance measure is defined by (a) reaching
the goal and (b) how “expensive” the path to the goal is
Search problem components

• Initial state Initial


state
• Actions
• Transition model
• What state results from
performing a given action
in a given state?
• Goal state
• Path cost
• Assume that it is a sum of Goal
nonnegative step costs
state
• A solution is a sequence of actions (a plan) which transforms
the start state to a goal state
• The optimal solution is the sequence of actions that gives
the lowest path cost for reaching the goal
Example: Romania

• On vacation in Romania; currently in Arad


• Flight leaves tomorrow from Bucharest
• Initial state
• Arad
• Actions
• Go from one city to another
• Transition model
• If you go from city A to
city B, you end up in city B
• Goal state
• Bucharest
• Path cost
• Sum of edge costs (total
distance traveled)
Task Environment - PEAS

Performance measure
 -1 per step; +10 food; +500 win; -500 die;
+200 hit scared ghost
Environment
 Pacman dynamics (incl ghost behavior)
Actuators
 North, South, East, West, (Stop)
Sensors
 Entire state is visible
Environment Types – Quiz?

Pacman Taxi
Fully or partially observable
Single agent or multi-agent
Deterministic or stochastic
Static or dynamic
Discrete or continuous
State space
• The initial state, actions, and transition model define
the state space of the problem
• The set of all states reachable from initial state by any sequence of
actions
• Can be represented as a directed graph where the nodes are states
and links between nodes are actions
• What is the state space for the Romania problem?
State Space Graphs

• State space graph: A mathematical


representation of a search problem
• Nodes are (abstracted) world configurations
• Arcs represent transitions resulting from actions
• The goal test is a set of goal nodes (maybe only
one)

• In a state space graph, each state occurs


only once!

• We can rarely build this full graph in


memory (it’s too big), but it’s a useful idea
More Examples

Oradea
71
Neamt

Zerind 87
151
75
Iasi
Arad
140
92
Sibiu Fagaras
99
118
Vaslui
80
Rimnicu Vilcea
Timisoara
142
111 Pitesti 211
Lugoj 97
70 98
85 Hirsova
Mehadia 146 101 Urziceni
75 138 86
Bucharest
Drobeta 120
90
Craiova Eforie
Giurgiu
More Examples

R
L R

L
S S

R R
L R L R

L L
S S
S S
R
L R

S S
Example: 8-puzzle

start state goal state

• State (trạng thái):


• Actions :
• Goal test:
• Path cost:

32
Example: 8-puzzle

start state goal state

• State: integer location of tiles (ignore intermediate locations)


• Actions: moving blank left, right, up, down (ignore jamming)
• Goal test: does state match goal state?
• Path cost: 1 per move

33
Example: 8-puzzle

start state goal state

Why search algorithms?


• 8-puzzle has 362,800 states
• 15-puzzle has 10^12 states
• 24-puzzle has 10^25 states

So, we need a principled way to look for a solution in these


huge search spaces…
34
State Space Sizes?

• World state:
• Agent positions: 120
• Food count: 30
• Ghost positions: 12
• Agent facing: NSEW

• How many
• World states?
120x(230)x(122)x4
• States for pathing?
120
• States for eat-all-dots?
120x(230)
Search

• Given:
• Initial state
• Actions
• Transition model
• Goal state
• Path cost
• How do we find the optimal solution?
• How about building the state space and then using Dijkstra’s
shortest path algorithm?
• Complexity of Dijkstra’s is O(E + V log V), where V is the size of the state
space
• The state space may be huge!
Search: Basic idea

• Let’s begin at the start state and expand it by making a


list of all possible successor states
• Maintain a frontier or a list of unexpanded states
• At each step, pick a state from the frontier to expand
• Keep going until you reach a goal state
• Try to expand as few states as possible
Search tree
• “What if” tree of sequences of actions and
outcomes
Starting
state
• The root node corresponds to the starting state
• The children of a node correspond to the Action
successor states of that node’s state
Successor
• A path through the tree corresponds to a
state

sequence of actions
• A solution is a path ending in the goal
state
• Nodes vs. states
• A state is a representation of the world,
………
while a node is a data structure that is
part of the search tree Goal state
• Node has to keep pointer to parent, path cost,
possibly other info
State Space Graphs vs. Search Trees

Consider this 4-state graph: How big is its search tree (from S)?
S

a
a b
S G
b G G a
b G a b G


Important: Lots of repeated structure in the search tree!
Tree Search Algorithm Outline

Function General-Search(problem, strategy) returns a solution, or failure


initialize the search tree using the initial state problem
loop do
if there are no candidates for expansion then return failure
choose a leaf node for expansion according to strategy search
if the node contains a goal state then
return the corresponding solution
else expand the node and add resulting nodes to the search tree
end

40
Problem-Solving

• Problem solving:
• Goal formulation
• Problem formulation (states, operators)
• Search for solution

• Problem formulation:
• Initial state
• Actions
• Goal test
• Path cost

41
Finding a solution

Solution: is ???

Function General-Search(problem, strategy) returns a solution, or failure


initialize the search tree using the initial state problem
loop do
if there are no candidates for expansion then return failure
choose a leaf node for expansion according to strategy
if the node contains a goal state then return the corresponding solution
else expand the node and add resulting nodes to the search tree
end

42
Finding a solution

Solution: is a sequence of actions that bring you from current state


to the goal state.

Function General-Search(problem, strategy) returns a solution, or failure


initialize the search tree using the initial state problem
loop do
if there are no candidates for expansion then return failure
choose a leaf node for expansion according to strategy
if the node contains a goal state then return the corresponding solution
else expand the node and add resulting nodes to the search tree
end

Strategy: The search strategy is determined by ???

43
Finding a solution

Solution: is a sequence of actions that bring you from current state


to the goal state

Function General-Search(problem, strategy) returns a solution, or failure


initialize the search tree using the initial state problem
loop do
if there are no candidates for expansion then return failure
choose a leaf node for expansion according to strategy
if the node contains a goal state then return the corresponding solution
else expand the node and add resulting nodes to the search tree
end

Strategy: The search strategy is determined by the order in which


the nodes are expanded.

44
Example: Traveling from Arad To Bucharest

45
Tree search example

46
Tree search example

47
Tree search example

48
Tree search example

49
Tree search example

Start: Arad
Goal: Bucharest
Tree search example

Start: Arad
Goal: Bucharest
Tree search example

Start: Arad
Goal: Bucharest
Tree search example

Start: Arad
Goal: Bucharest
Tree search example

Start: Arad
Goal: Bucharest
Tree search example

Start: Arad
Goal: Bucharest
Tree search example

Start: Arad
Goal: Bucharest
Handling repeated states

• To handle repeated states:


• Every time you expand a node, add that state to the
explored set; do not put explored states on the frontier again
• Every time you add a node to the frontier, check whether it already exists in the frontier
with a higher path cost, and if yes, replace that node with the new one

57
Implementation of search algorithms

Function General-Search(problem, Queuing-Fn) returns a solution, or failure


nodes  make-queue(make-node(initial-state[problem]))
loop do
if nodes is empty then return failure
node  Remove-Front(nodes)
if Goal-Test[problem] applied to State(node) succeeds then return node
nodes  Queuing-Fn(nodes, Expand(node, Operators[problem]))
end

Queuing-Fn(queue, elements) is a queuing function that inserts a set


of elements into the queue and determines the order of node expansion.
Varieties of the queuing function produce varieties of the search algorithm.

58
Function TREE_SEARCH(problem) returns a solution, or failure

initialize the frontier as a specific work list (stack, queue, priority queue)
add initial state of problem to frontier
loop do
if the frontier is empty then
return failure
choose a node and remove it from the frontier
if the node contains a goal state then
return the corresponding solution

for each resulting child from node


add child to the frontier
Function GRAPH_SEARCH(problem) returns a solution, or failure
initialize the explored set to be empty
initialize the frontier as a specific work list (stack, queue, priority queue)
add initial state of problem to frontier
loop do
if the frontier is empty then
return failure
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
Encapsulating state information in nodes

61
Evaluation of search strategies (Các tiêu chí đánh giá các chiến lược tìm
kiếm)

• A search strategy is defined by picking the order of node expansion (Một chiến lược tìm
kiếm được định nghĩa bằng chọn thứ tự của việc mở rộng nút)
• Completeness (độ hoàn chỉnh): Có phải lúc nào cũng tìm ra nghiệm nếu có không?
• Time complexity (độ phức tạp về thời gian): số lượng các trạng thái đã đến
• Space complexity (độ phức tạp về không gian): số lượng các trạng thái tối đa phải lưu trong
bộ nhớ
• Optimality (độ tối ưu): có phải lúc nào cũng tìm ra nghiệm có chi phí nhỏ nhất không?
• Các tham số để tính độ phức tạp về không gian và thời gian:
• b: maximum branching factor of the search tree (số trạng thái kề)
• d: depth of the least-cost solution (độ sâu của trạng thái kết thúc)
• m: maximum depth of the state space (may be ∞)(độ sâu lớn nhất)

62
Binary Tree Example

Depth = 0
root

Depth = 1
N1 N2

Depth = 2 N3 N4 N5 N6

Number of nodes: n = 2 max depth


Number of levels (max depth) = log(n) (could be n)
63
Complexity

• Why worry about complexity of algorithms?

 because a problem may be solvable in principle but may take too long to
solve in practice

64
Complexity: Tower of Hanoi

65
Complexity:
Tower of Hanoi

66
Complexity: Tower of Hanoi

 3-disk problem: 23 - 1 = 7 moves

 64-disk problem: 264 - 1.


 210 = 1024  1000 = 103,
 264 = 24 * 260  24 * 1018 = 1.6 * 1019

 One year  3.2 * 107 seconds

67
Complexity: Tower of Hanoi

 The wizard’s speed = one disk / second

1.6 * 1019 = 5 * 3.2 * 1018 =


5 * (3.2 * 107) * 1011 =
(3.2 * 107) * (5 * 1011)

68
Complexity: Tower of Hanoi

 The time required to move all 64 disks from needle 1 to needle 3 is


roughly 5 * 1011 years.

 It is estimated that our universe is about 15 billion = 1.5 * 1010


years old.

5 * 1011 = 50 * 1010  33 * (1.5 * 1010).

69
Complexity: Tower of Hanoi

 Assume: a computer with 1 billion = 109 moves/second.


 Moves/year=(3.2 *107) * 109 = 3.2 * 1016

 To solve the problem for 64 disks:


 264  1.6 * 1019 = 1.6 * 1016 * 103 =
(3.2 * 1016) * 500

 500 years for the computer to generate 264 moves at the


rate of 1 billion moves per second.

70
Complexity

• Why worry about complexity of algorithms?


 because a problem may be solvable in principle but may take too
long to solve in practice

• How can we evaluate the complexity of algorithms?


 through asymptotic (tiệm cận) analysis, i.e., estimate time (or
number of operations) necessary to solve an instance of size n of
a problem when n tends towards infinity
 See AIMA, Appendix A.

71
Complexity of Algorithms

• T(n) is O(f(n)) means there exists n0, k such that for all n >n0 T(n) <= kf(n):
• N = input size
• T(n) = total number of step of the algorithm
• Independent of the implementation, compiler, …
• Asymtotic analysis: For large n, an O(n) algorithm is better than an O(n2) algorithm.
• O() abstract over constant factors:
• T(100n +1000) is better than T(n2 + 1) only for n > 110
• O() notation is a good compromise between precision and easy of analysis

72
Remember: Implementation of search algorithms

Function General-Search(problem, Queuing-Fn) returns a solution, or failure


nodes  make-queue(make-node(initial-state[problem]))
loop do
if nodes is empty then return failure
node  Remove-Front(nodes)
if Goal-Test[problem] applied to State(node) succeeds then return node
nodes  Queuing-Fn(nodes, Expand(node, Operators[problem]))
end

Queuing-Fn(queue, elements) is a queuing function that inserts a set


of elements into the queue and determines the order of node expansion.
Varieties of the queuing function produce varieties of the search algorithm.

73
Types of search strategies

• Uninformed/blind search
• Không hiểu biết gì về đối tượng
• Duyệt qua để tìm được đối tượng cần tìm
• Informed/heuristic search:
• Dựa vào kinh nghiệm và sự hiểu biết của chúng ta để xây dựng hàm
đánh giá hướng dẫn tìm kiếm
• Các chiến lược tìm kiếm tối ưu
• Các phương pháp tìm kiếm có đối thủ

74
Uninformed/Blind search
strategies (Các chiến lược
tìm kiếm mù)

75
Uninformed/Blind search strategies (Các chiến
lược tìm kiếm mù)

• Tìm kiếm theo bề rộng (breadth-first search)


• Tìm kiếm theo chiều sâu (depth-first search)
• Tìm kiếm theo chiều sâu có giới hạn (depth-limited
search)
• Tìm kiếm theo chiều sâu lặp (iterative deepening depth-
first search)

76
Breadth-first search (Tìm kiếm theo chiều rộng)- Idea

• Tại mỗi bước, chọn trạng thái để phát triển là trạng thái được sinh ra trước các trạng thái
chờ phát triển khác
• Nói một cách khác, chúng ta sẽ quét cây tìm kiếm theo từng lớp tính từ gốc trở đi
• Đỉnh mới được sinh ra sẽ được lưu vào một danh sách tổ chức theo kiểu “hàng đợi”
(queue FIFO)

77
Breadth-first search

A D Move downwards,
level by level,
until goal is
B D A E reached.

C E E B B F

D F B F C E A C G

G C G F
G 78
Example: Traveling from Arad To Bucharest

79
Breadth-first search

80
Breadth-first search

81
Breadth-first search

82
Breadth-first search

Từ thuật toán tìm kiếm tổng quát ta có:

1. Khởi tạo hàng đợi L chỉ chứa trạng thái ban đầu
2. Loop do
2.1 If (L rỗng) then
{thông báo tìm kiếm thất bại; kết thúc}
2.2 Loại trạng thái u ở đầu hàng đợi L;
2.3 If (u là trạng thái kết thúc) then
{thông báo tìm kiếm thành công; kết thúc}
2.4 For (mỗi trạng thái v kề u) do
{Đặt v vào cuối hàng đợi L;}

83
Properties of breadth-first search

• Completeness:
• Time complexity:
• Space complexity:
• Optimality:

• Search algorithms are commonly evaluated according to the following four criteria:
• Completeness: does it always find a solution if one exists?
• Time complexity: how long does it take as function of num. of nodes?
• Space complexity: how much memory does it require?
• Optimality: does it guarantee the least-cost solution?

• Time and space complexity are measured in terms of:


• b – max branching factor of the search tree
• d – depth of the least-cost solution
• m – max depth of the search tree (may be infinity)

84
Properties of breadth-first search

• Completeness: Yes, if b is finite


• Time complexity: 1+b+b2+…+bd = O(b d), i.e., exponential in d
• Space complexity: O(b d) (see following slides)
• Optimality: Yes (assuming cost = 1 per step)

85
Time complexity of breadth-first search

• If a goal node is found on depth d of the tree, all nodes up till that
depth are created.

d
m
b G

• Thus: O(bd)

86
Space complexity of breadth-first

• Largest number of nodes in QUEUE is reached on the level d of


the goal node.

d
m
b G

• QUEUE contains all and G nodes. (Thus: 4) .


• In General: bd

87
Examples

• Giả sử b=10, kiểm tra 1000 trạng thái cần 1 giây, lưu một trạng
thái cần 100 byte

Độ sâu d Thời gian Không gian


4 11 giây 1 megabyte
6 18 giây 111 megabyte
8 31 giờ 11 gigabyte
10 128 ngày 1terabyte
12 35 năm 111 terabyte

14 3500 năm 11 111 terabyte

88
Depth First Search (Tìm kiếm theo chiều sâu)- Idea

• Tại mỗi bước, chọn trạng thái để phát triển là trạng thái được sinh ra sau cùng trong các
trạng thái chờ phát triển
• Nói một cách khác, chúng ta sẽ quét cây tìm kiếm theo từng nhánh tính từ gốc trở đi
• Tương tự như thuật toán tìm kiếm chiều rộng chỉ khác là sử dụng một danh sách theo kiểu
“ngăn xếp” (stack LIFO) chứ không phải theo kiểu “hàng đợi”.

89
Depth First Search

C E

D F

90
Romania with step costs in km

91
Depth-first search

92
Depth-first search

93
Depth-first search

94
Depth-first search

Từ thuật toán tổng quát ta có:

1. Khởi tạo ngăn xếp L chỉ chứa trạng thái ban đầu
2. Loop do
2.1 If (L rỗng) then
{thông báo tìm kiếm thất bại; kết thúc}
2.2 Loại trạng thái u ở đầu ngăn xếp L;
2.3 If (u là trạng thái kết thúc) then
{thông báo tìm kiếm thành công; kết thúc}
2.4 For (mỗi trạng thái v kề u) do
{Đặt v vào đầu ngăn xếp L;}

95
Properties of depth-first search

• Completeness: No, fails in infinite state-space (yes if finite


state space)
• Time complexity: O(b m)
• Space complexity: O(bm)
• Optimality: No

Remember:
b = branching factor
m = max depth of search tree

96
Time complexity of depth-first: details

• In the worst case:


• the (only) goal node may be on the right-most branch,

m
b

• Time complexity == bm + bm-1 + … + 1 = bm+1 -1


• Thus: O(bm) b-1
97
Space complexity of depth-first

• Largest number of nodes in QUEUE is reached in bottom left-


most node.
• Example: m = 3, b = 3 :

...

• QUEUE contains all nodes. Thus: 7.


• In General: ((b-1) * m) + 1
• Order: O(m*b)
98
Tránh các trạng thái lặp (Avoiding repeated states)

• Trong cây tìm kiếm có thể chứa nhiều đỉnh ứng với cùng một
trạng thái – các trạng thái này được gọi là trạng thái lặp
• Các thuật toán tìm kiếm sẽ lãng phí rất nhiều thời gian để phát
triển lại các trạng thái mà ta đã gặp và đã phát triển
• Cách giải quyết: đánh dấu các trạng thái đã được sinh ra, không
sinh ra lại những trạng thái đã được sinh ra

99
Exercise

Find path from A to K


by:
- Breadth-first
- Depth-first

100
Exercise (2)

101
Breadth-First Search

Strategy: expand a a G
shallowest node first b c
Implementation: e
d f
Frontier is a FIFO queue S h
p q r

d e p
Search
b c e h r q
Tiers
a a h r p q f

p q f q c G

q c G a

a
Depth-First Search

Strategy: a G
b c
expand a e
d f
deepest node S h
first p q r

Implementation S

: Frontier is a d e p
LIFO stack b c e h r q
a a h r p q f
p q f q c G

q c G a
a
Depth-limited search

Is a depth-first search with depth limit l


Implementation:
• In the above figure, the depth-limit is 1.
• Depth-first search is a special case of
depth-limited search.
Complete: if cutoff chosen appropriately
then it is guaranteed to find a solution.
Optimal: it does not guarantee to find the
least-cost solution

104
Iterative Deepening

• Idea: get DFS’s space advantage with


BFS’s time / shallow-solution
b
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!
Iterative deepening search

Function Iterative-deepening-Search(problem) returns a solution,


or failure
for depth = 0 to  do
result  Depth-Limited-Search(problem, depth)
if result succeeds then return result
end
return failure

Combines the best of breadth-first and depth-first search


strategies.
• Completeness: Yes,
• Time complexity: O(b d)
• Space complexity: O(bd)
• Optimality: Yes, if step cost = 1 106
Romania with step costs in km

107
108
109
110
111
112
113
114
115
Iterative deepening search
Iterative deepening complexity

• In iterative deepening, nodes at bottom level are expanded


once, level above twice, etc. up to root (expanded d+1 times)
so total number of expansions is:
(d+1)1 + (d)b + (d-1)b^2 + … + 3b^(d-2) + 2b^(d-1) + 1b^d = O(b^d)

• In general, iterative deepening is preferred to depth-first or


breadth-first when search space large and depth of solution
not known.

117
Uniform-cost search

• For each frontier node (queue), save the total cost of the path from the
initial state to that node
• Expand the frontier node with the lowest path cost
• Implementation: frontier is a priority queue ordered by path cost
• Equivalent to breadth-first if step costs all equal
• Equivalent to Dijkstra’s algorithm in general
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
loop do
if the frontier is empty then
return failure
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 example
Uniform-cost search example

• Expansion order:
(S,p,d,b,e,a,r,f,e,G)
Another example of uniform-cost search

Source: Wikipedia
Properties of uniform-cost search

• Complete?
Yes, if step cost is greater than some positive
constant ε (we don’t want infinite sequences of
steps that have a finite total cost)
• Optimal?
Yes
Optimality of uniform-cost search

• Graph separation property: every path from the initial


state to an unexplored state has to pass through a state
on the frontier
• Proved inductively

• Optimality of UCS: proof by contradiction


• Suppose UCS terminates at goal state n with path cost
g(n) but there exists another goal state n’ with g(n’) <
g(n)
• By the graph separation property, there must exist a
node n” on the frontier that is on the optimal path to n’
• But because g(n”) ≤ g(n’) < g(n), n” should have been
expanded first!
Properties of uniform-cost search

• Complete?
Yes, if step cost is greater than some positive constant ε
(we don’t want infinite sequences of steps that have a
finite total cost)
• Optimal?
Yes – nodes expanded in increasing order of path cost
• Time?
Number of nodes with path cost ≤ cost of optimal solution
(C*), O(bC*/ ε)
This can be greater than O(bd): the search can explore
long paths consisting of small steps before exploring
shorter paths consisting of larger steps
• Space?
O(bC*/ ε)
Comparing uninformed search strategies

Criterion Breadth Uniform Depth- Depth- Iterative


first cost first limited deepening

Time b^d b^d b^m b^l b^d

Space b^d b^d bm bl bd

Optimal? Yes Yes No No Yes

Complete? Yes Yes No Yes, Yes


if ld

• b – max branching factor of the search tree


• d – depth of the least-cost solution
• m – max depth of the state-space (may be infinity)
• l – depth cutoff
126
Summary

• Problem formulation usually requires abstracting away real-world details to define a state
space that can be explored using computer algorithms.

• Once problem is formulated in abstract form, complexity analysis helps us picking out best
algorithm to solve problem.

• Variety of uninformed search strategies; difference lies in method used to pick node that
will be further expanded.

127
References

• AIMA textbook
• Slides of CMU AI course
• Slides of UC Berkeley AI course

128

You might also like