AI - Lecture 2 - Uninformed Search
AI - Lecture 2 - Uninformed Search
Spring 2011
Announcements
Project 0: Python Tutorial
Due Friday 5pm.
Lab session Wednesday 3-5pm in 271 Soda
The lab time is optional, but P0 itself is not
On submit, you should get email from the autograder
Project 1: Search
Out today, due next week Friday 5pm.
Start early and ask questions. It’s longer than most!
1
Today
Reflex Agents
Reminder
Only a very small fraction of AI is about making
computers play games intelligently
Recall: computer vision, natural language,
robotics, machine learning, computational
biology, etc.
2
Reflex Agent
Choose action based 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
Reflex agent
While(food left)
Sort the possible directions to move according
to the amount of food in each direction
Go in the direction with the largest amount of
food
3
A reflex agent for pacman (2)
Reflex agent
While(food left)
Sort the possible directions to move according
to the amount of food in each direction
Go in the direction with the largest amount of
food
Reflex agent
While(food left)
Sort the possible directions to move according to the
amount of food in each direction
Go in the direction with the largest amount of food
But, if other options are available, exclude the direction we
just came from
4
A reflex agent for pacman (4)
Reflex agent
While(food left)
If can keep going in the current direction, do so
Otherwise:
Sort directions according to the amount of food
Go in the direction with the largest amount of food
But, if other options are available, exclude the direction we just
came from
Reflex agent
While(food left)
If can keep going in the current direction, do so
Otherwise:
Sort directions according to the amount of food
Go in the direction with the largest amount of food
But, if other options are available, exclude the direction we just
came from
5
Reflex Agent Goal-based Agents
Choose action based on Plan ahead
current percept (and Ask “what if”
maybe memory) Decisions based on
May have memory or a (hypothesized)
model of the world’s consequences of
current state actions
Do not consider the future Must have a model of
consequences of their how the world evolves
actions in response to actions
Search Problems
A search problem consists of:
A state space
“N”, 1.0
A successor function
“E”, 1.0
A start state and a goal test
6
Example: Romania
State space:
Cities
Successor
function:
Go to adj city
with cost = dist
Start state:
Arad
Goal test:
Is state ==
Bucharest?
Solution?
7
State Space Sizes?
Search Problem:
Eat all of the food
Pacman positions:
10 x 12 = 120
Food count: 30
Ghost positions: 12
Pacman facing:
up, down, left, right
Search Trees
A search tree:
This is a “what if” tree of plans and outcomes
Start state at the root node
Children correspond to successors
Nodes contain states, correspond to PLANS to those states
For most problems, we can never actually build the whole tree
8
Another Search Tree
Search:
Expand out possible plans
Maintain a fringe of unexpanded plans
Try to expand as few tree nodes as possible
Important ideas:
Fringe Detailed pseudocode
Expansion is in the book!
Exploration strategy
9
Example: Tree Search
a G
b c
e
d f
S h
p r
q
d e p
We construct both b c e h r q
on demand – and
we construct as a a h r p q f
little as possible.
p q f q c G
q c a
G
a
10
Review: Depth First Search
a G
Strategy: expand b c
deepest node first
e
d f
Implementation:
Fringe is a LIFO S h
stack p r
q
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
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
11
Search Algorithm Properties
Complete? Guaranteed to find a solution if one exists?
Optimal? Guaranteed to find the least cost path?
Time complexity?
Space complexity?
Variables:
n Number of states in the problem
b The average branching factor B
(the average number of successors)
C* Cost of least cost solution
s Depth of the shallowest solution
m Max depth of the search tree
DFS
Algorithm Complete Optimal Time Space
DFS Depth First N N N LMAX)
Search N O(B
Infinite O(LMAX)
Infinite
START a
GOAL
12
DFS
With cycle checking, DFS is complete.*
1 node
b
… b nodes
b2 nodes
m tiers
bm nodes
BFS
Algorithm Complete Optimal Time Space
DFS w/ Path
Checking Y N O(bm) O(bm)
BFS Y N* O(bs+1) O(bs+1)
1 node
b
… b nodes
s tiers
b2 nodes
bs nodes
bm nodes
13
Comparisons
Iterative Deepening
Iterative deepening uses DFS as a subroutine:
b
1. Do a DFS which only searches for paths of …
length 1 or less.
2. If “1” failed, do a DFS which only searches paths
of length 2 or less.
3. If “2” failed, do a DFS which only searches paths
of length 3 or less.
….and so on.
14
Costs on Actions
a GOAL
2 2
b c
3
2
1 8
2 e
3 d
f
9 8 2
START h
1 4 1
p 4 r
15
q
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
15
Priority Queue Refresher
b
…
* UCS can fail if
C*/ε tiers actions can get
arbitrarily cheap
16
Uniform Cost Issues
Remember: explores … c≤1
increasing cost contours c≤2
c≤3
The good: UCS is
complete and optimal!
The bad:
Explores options in every
“direction”
No information about goal
location Start Goal
Search Heuristics
Any estimate of how close a state is to a goal
Designed for a particular search problem
Examples: Manhattan distance, Euclidean distance
10
5
11.2
17
Heuristics
18
Best First / Greedy Search
A common case: b
Best-first takes you straight …
to the (wrong) goal
19
Can we leverage the heuristic information
in a more sound way?
A* search
20