AI.2a-Solving Problems by Searching (5-10)
AI.2a-Solving Problems by Searching (5-10)
• Search Problems
• Uninformed Search
• Informed Search
Artificial Intelligence 2
CONTENTS
• Search Problems
• Uninformed Search
• Informed Search
Artificial Intelligence 3
CONTENTS
• Search Problems
• Problem solving agents
• Search Trees
Artificial Intelligence 4
Search Problems
Artificial Intelligence 5
Problem solving agents
Artificial Intelligence 6
…Problem solving agents
• State space:
• Cities
• Successor function:
• go to adjacent city with cost =
distance
• Start state:
• Arad
• Goal test:
• Is state == Bucharest?
• Solution?
Artificial Intelligence 7
…Problem solving agents
Artificial Intelligence 8
…Problem solving agents
• State space:
• {(x,y), dot booleans}
• Successor function
• update location and “N”, 1.0
possibly a dot boolean
Artificial Intelligence 9
…Problem solving agents
Example: vacuum world
• State space:
• agent location & dirt locations
• Successor function:
• Left, Right, Suck
• Star state:
• Any state can be designated
• Goal stest:
• This checks whether all the squares are clean
Artificial Intelligence 10
…Problem solving agents
Artificial Intelligence 11
…Problem solving agents
Artificial Intelligence 12
…Problem solving agents
Artificial Intelligence 13
…Problem solving agents
Artificial Intelligence 14
Search Trees
a G d e p
b c
b c e h r q
e
d f a a h r p q f
S h
p q f q c G
p r We construct both on
q
demand – and we construct q c G a
as little as possible.
a
Artificial Intelligence 15
…Search Trees
Artificial Intelligence 16
…Search Trees
Artificial Intelligence 17
…Search Trees
Artificial Intelligence 18
…Search Trees
• Example
a G
b c
e
d f
S h
p q r
Artificial Intelligence 19
…Search Trees
• Example
a G
b c
e
d f
S h
p q r
S s
sd
d e p se
sp
b c e h r q sdb
sdc
a a h r p q f sde
sdeh
p q f q c G
sder
a sderf
q c G
sderfc
a sderfG
Artificial Intelligence 20
CONTENTS
• Search Problems
• Uninformed Search
• https://www.massey.ac.nz/~mjjohn
so/notes/59302/l03.html
• Informed Search
Artificial Intelligence 21
CONTENTS
• Uninformed search
• Depth-First Search (Tìm kiếm theo chiều sâu )
• Breadth-First Search (Tìm kiếm theo chiều rộng)
• Iterative-Deepening Search (Tìm kiếm sâu dần)
• Uniform-Cost Search (Tìm kiếm với chi phí cực tiểu)
Artificial Intelligence 22
Depth-First Search (DFS)
Artificial Intelligence 23
… Depth-First Search (DFS)
a G
b c
e
d f
S h
p q r
d e p
b c e h r q
a a h r p q f
p q f q c G
q c G a
a
Artificial Intelligence 24
…Depth-First Search (DFS)
Properties
• Complete: Guaranteed to find a solution if one exists?
• Optimal: Guaranteed to find the least cost path?
• Time complexity?
• Space complexity?
b 1 node
• Cartoon of search tree: … b nodes
• b is the branching factor b2 nodes
• m is the maximum depth m tiers
Artificial Intelligence 27
…Breadth-First Search (BFS)
a G
b c
e
d f
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
Artificial Intelligence 28
…Breadth-First Search (BFS)
Artificial Intelligence 29
…Breadth-First Search (BFS)
Artificial Intelligence 30
…Breadth-First Search (BFS)
Artificial Intelligence 31
…Breadth-First Search (BFS)
Artificial Intelligence 32
…Breadth-First Search (BFS)
Artificial Intelligence 33
…Breadth-First Search (BFS)
Artificial Intelligence 34
…Breadth-First Search (BFS)
Artificial Intelligence 35
…Breadth-First Search (BFS)
Artificial Intelligence 36
…Breadth-First Search (BFS)
Artificial Intelligence 37
…Breadth-First Search (BFS)
Artificial Intelligence 38
…Breadth-First Search (BFS)
Artificial Intelligence 39
…Breadth-First Search (BFS)
Artificial Intelligence 40
…Breadth-First Search (BFS)
Artificial Intelligence 41
…Breadth-First Search (BFS)
Artificial Intelligence 42
…Breadth-First Search (BFS)
Artificial Intelligence 43
…Breadth-First Search (BFS)
Properties
Artificial Intelligence 44
…Breadth-First Search (BFS)
DFS vs BFS
Artificial Intelligence 45
Iterative-Deepening Search (IDS)
Artificial Intelligence 46
…Iterative-Deepening Search (IDS)
IDS: d = 0
Artificial Intelligence 47
…Iterative-Deepening Search (IDS)
IDS: d = 1
B C
Artificial Intelligence 48
…Iterative-Deepening Search (IDS)
IDS: d = 2
B C
D E F G
Artificial Intelligence 49
…Iterative-Deepening Search (IDS)
IDS: d = 3
B C
D E F G
H I J K L M
GOAL
Artificial Intelligence 50
…Iterative-Deepening Search (IDS)
Artificial Intelligence 51
…Iterative-Deepening Search (IDS)
Properties
• Complete
• Có
• Time:
• (d+1).b0 + d.b1 + (d-1).b2+ … +bd = O(bd)
• Space:
• O(b.d)
• Optimal
• Có - nếu chi phí cho mỗi buớc = 1
Artificial Intelligence 52
Uniform Cost Search (UCS)
(Djikstra’s algorithm)
Artificial Intelligence 53
…Uniform Cost Search(UCS)
Artificial Intelligence 54
…Uniform Cost Search(UCS)
Artificial Intelligence 55
…Uniform Cost Search(UCS)
Artificial Intelligence 56
…Uniform Cost Search(UCS)
Artificial Intelligence 57
…Uniform Cost Search(UCS)
Artificial Intelligence 58
…Uniform Cost Search(UCS)
Artificial Intelligence 59
…Uniform Cost Search(UCS)
Artificial Intelligence 60
…Uniform Cost Search(UCS)
Artificial Intelligence 61
…Uniform Cost Search(UCS)
Artificial Intelligence 62
…Uniform Cost Search(UCS)
2 G
a
b c
1 8 2
2
3 e
d f
9 2
S 8
h 1
1 p r
q
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
• Contours show equal cost.
a
Artificial Intelligence 63
…Uniform Cost Search(UCS)
Artificial Intelligence 64
…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*/
• Time: O(bC*/) (exponential in effective depth)
• Space: has roughly the last tier, so O(bC*/)
b c1
• complete? …
c2
C*/ “tiers”
• Assuming best solution has a finite cost c3
and minimum arc cost is positive, yes!
• optimal?
• Yes! (Proof next lecture via A*)
Artificial Intelligence 65
…Uniform Cost Search(UCS)
• The bad:
• Explores options in every “direction”
• No information about goal location
Start Goal
• We’ll fix that soon!
Artificial Intelligence 66
Uninformed Search
Artificial Intelligence 67
CONTENTS
• Search Problems
• Uninformed Search
• Informed Search
Artificial Intelligence 68
CONTENTS
Artificial Intelligence 69
Heuristic Function
A heuristic is
A function that estimates how close a state is to a goal
Designed for a particular search problem
10
5
11.2
Artificial Intelligence 70
…Heuristic Function
Example: Heuristic Function h(x)
Artificial Intelligence 71
…Heuristic Function
• h(u) = 8
= the number of misplaced tiles
(all of the eight tiles are out of position)
• h(u) = 3+1+2+2+2+3+3+2 = 18
= the sum of the distances of the tiles from their goal positions.
Artificial Intelligence 72
…Heuristic Function
Artificial Intelligence 73
Greedy Search
Artificial Intelligence 74
Greedy Search
Artificial Intelligence 75
…Greedy Search
h(x)
Artificial Intelligence 76
…Greedy Search
Artificial Intelligence 77
…Greedy Search
Artificial Intelligence 78
…Greedy Search
Artificial Intelligence 80
A* Search
Artificial Intelligence 81
A* Search
UCS Greedy
A*
Artificial Intelligence 82
A* Search
• Uniform-cost orders by path cost, or backward cost g(n)
• Greedy orders by goal proximity, or forward cost h(n)
8 g=0
S h=6
g=1
e h=1
h=5 a
1
1 3 2 g=2 g=9
S a d G g=4
h=6 b d e h=1
h=2
h=6 1 h=5
h=2 h=0
1 g=3 g=6 g = 10
c b h=7 c G h=0 d h=2
h=7 h=6
g = 12
G h=0
• A* Search orders by the sum: f(n) = g(n) + h(n)
• >> Đường đi ngắn nhất: S – a – d - G
Artificial Intelligence 83
…A* Search
Artificial Intelligence 84
…A* Search
Artificial Intelligence 85
…A* Search
Artificial Intelligence 86
…A* Search
Artificial Intelligence 87
…A* Search
Artificial Intelligence 88
…A* Search
Properties of A* Search
Uniform-Cost A*
b b
… …
A*
Artificial Intelligence 91
…A* Search
Comparison
Artificial Intelligence 92
…A* Search
A* Applications
• Video games
• Pathing / routing problems
• Resource planning problems
• Robot motion planning
• Language analysis
• Machine translation
• Speech recognition
•…
Artificial Intelligence 93
…A* Search
Artificial Intelligence 94
SUMMARY
• Search Problems
• Uninformed Search
• Informed Search
Artificial Intelligence 95
Nhân bản – Phụng sự – Khai phóng
Artificial Intelligence 96