Professional Documents
Culture Documents
Search
§ Searching
§ Reflex Agent:
§ Choose action base on current percept (and
maybe memory)
§ May have memory or a model of the world’s
current state
§ Do not consider the future consequences of
their actions
Video of Demo Reflex Optimal
§ Pacman environment
§ Đi sang ô cạnh
§ Di chuyển: -1
§ Ăn: 10
§ Reflect agent:
§ Cứ tăng điểm thì đi
Video of Demo Reflex Odd
Planning Agents
§ Planning Agent:
§ Look into future: What if ?
§ Decisions plan with considerations a
consequence
§ Think by having a model of the world/actions
§ Have a goal
§ State space
“N”, 1.0
§ Transition Function
§ Space:
§ Cities
§ Transition function:
§ Roads: Go to adjacent city with cost =
distance
§ Start:
§ Arad
§ End:
§ Is state == Bucharest?
§ Solution?
What’s in a State Space?
Fully Observable
§ How many
§ Full space:
120x(230)x(122)x4
§ Path finding:
120
§ Eating all dots:
120x(230)
Safety path planning
§ Problem: Ăn hết các chấm + luôn để các con ghost sợ hãi (N = 10)
§ How we define a state?
Graph Search Space vs Tree Search Space
State Space Graphs
Possible futures
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 q r
q c G a
a
Đồ thị không gian trạng thái vs. Cây tìm kiếm
S G
§ Main approach:
§ Go from start
§ Expand the nodes which are not expanded
§ Avoid repeating nodes
Pseudocode
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
DFS is good or bad?
Search Properties
§ Completeness: Always find a solution if it exists
§ Optimal: Always find the best solution
§ Run time
§ Memory 1 node
b
… b nodes
b2 nodes
§ Parameters:
§ b: chỉ số rẽ nhánh - branching factor m tiers
§ m: độ sâu is the maximum depth
§ Lời giải có thể nằm ở các độ sâu khác nhau
bm nodes
§ How many nodes?
§ 1 + b + b2 + …. bm = O(bm)
DFS properties
§ Time complexity
§ Move from left to right 1 node
b
§ Looking for the entire tree … b nodes
§ If m is finite, takes time O(bm) b2 nodes
m tiers
§ Memory complexity
§ O(bm)
§ Completeness bm nodes
§ Need m < infinity
§ Optimal
§ No
Breadth-First Search
Breadth-First Search
Use: queue a G
b c
Instead stack
e
d f
S h
p q r
d e p
Increase
b c e h r q
level of
searching
a a h r p q f
p q f q c G
q c G a
a
BFS properties
§ Time complexity:
§ O(bs) 1 node
b
§ If s < m, then we have advantage over DFS … b nodes
s
§ Memory complexity? b2 nodes
§ O(bs)
bs nodes
§ Store the last row
§ Completeness:
§ Yes bm nodes
§ Optimal
§ Find the least edges path
Quiz: DFS vs BFS
DFS vs BFS
a GOAL
2 2
b c
3
2
1 8
2 e
3 d
f
9 8 2
START h
1 4 2
p 4 r
15
q
Uniform Cost Search
Uniform cost search - UCS
UCS, a.k.a Dijkstra
2 a G
Uniform cost search - UCS b c
1 8 2
Go from nodes with least 2 e
3 d f
9 2
cost S h 8 1
1 p q r
15
S 0
d 3 e 9 p 1
b 4 c e 5 h 17 r 11 q 16
11
Boundary a 6 a h 13 r 7 p q f
Of search
p q f 8 q c G
q 11 c G 10 a
a
Properties
§ Complexity
§ Visit all node have cost < C*
b c£1
§ Let e be the min edges, maximum depth C*/e …
§ O(bC*/e) c£2
C*/e depth
c£3
§ Memory
§ O(bC*/e)
§ Completeness
§ Require > 0
§ Optimal
§ Yes
Properties
§ Càng đi nhiều bước thì "đường viền" tìm c£1
…
kiếm càng rộng c£2
c£3
§ The bad:
§ Phải tìm kiếm về mọi hướng
§ Không có thông tin về điểm đến
§ Ví dụ: bài toán giao thông tìm đường đi ngắn
nhất (đi về hướng nào đó)
Start Goal
Cấu trúc dữ liệu cần thiết