0% found this document useful (0 votes)
46 views

AI - Lecture 2 - Uninformed Search

This document summarizes key points from a lecture on queue-based search algorithms in an artificial intelligence course. It discusses reflex agents that choose actions based only on current percepts versus goal-based agents that plan ahead. It introduces search problems, state space graphs, and search trees. It then reviews depth-first search, breadth-first search, and uniform-cost search before introducing heuristic search methods like greedy search.

Uploaded by

HunterxHunter03
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

AI - Lecture 2 - Uninformed Search

This document summarizes key points from a lecture on queue-based search algorithms in an artificial intelligence course. It discusses reflex agents that choose actions based only on current percepts versus goal-based agents that plan ahead. It introduces search problems, state space graphs, and search trees. It then reviews depth-first search, breadth-first search, and uniform-cost search before introducing heuristic search methods like greedy search.

Uploaded by

HunterxHunter03
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

CS 188: Artificial Intelligence

Spring 2011

Lecture 2: Queue-Based Search


1/24/2010

Pieter Abbeel – UC Berkeley


Many slides from Dan Klein

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!

 Sections starting this week Thursday and Friday


 See course webpage for details

1
Today
 Reflex Agents

 Agents that Plan Ahead

 Formalization: Search Problems

 Uninformed Search Methods (part review for some)


 Depth-First Search
 Breadth-First Search
 Uniform-Cost Search

 Heuristic Search Methods (new for all)


 Greedy Search

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.

 That being said: games tend to provide relatively


simple example settings which are great to
illustrate concepts and learn about algorithms
which underlie many areas of AI

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

 Act on how the world IS

 Can a reflex agent be


rational?

A reflex agent for pacman

4 actions: move North, East,


South or West

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

A reflex agent for pacman (3)

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

A reflex agent for pacman (5)

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

 Act on how the world IS  Act on how the world


WOULD BE
 Can a reflex agent be
rational?

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

 A solution is a sequence of actions (a plan)


which transforms the start state to a goal state

6
Example: Romania
 State space:
 Cities
 Successor
function:
 Go to adj city
with cost = dist
 Start state:
 Arad
 Goal test:
 Is state ==
Bucharest?

 Solution?

State Space Graphs


 State space graph: A
mathematical a G
representation of a b c
search problem
e
 For every search problem, d f
there’s a corresponding
S h
state space graph
 The successor function is p r
represented by arcs q

Ridiculously tiny search graph


 We can rarely build this
for a tiny search problem
graph in memory (so
we don’t)

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

“N”, 1.0 “E”, 1.0

 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

General Tree Search

 Important ideas:
 Fringe Detailed pseudocode
 Expansion is in the book!
 Exploration strategy

 Main question: which fringe nodes to explore?

9
Example: Tree Search
a G
b c

e
d f
S h
p r
q

State Graphs vs. Search Trees


a G Each NODE in in the
b c search tree is an
e entire PATH in the
d f problem graph.
S h
p r
q
S

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

Review: Breadth First Search


a G
Strategy: expand
b c
shallowest node first
e
Implementation: d f
Fringe is a FIFO S h
queue 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

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

 Infinite paths make DFS incomplete…


 How can we fix this?

12
DFS
 With cycle checking, DFS is complete.*

1 node
b
… b nodes
b2 nodes
m tiers

bm nodes

Algorithm Complete Optimal Time Space


DFS w/ Path
Checking Y N O(bm) O(bm)

 When is DFS optimal?


* Or graph search – next lecture.

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

 When is BFS optimal?

13
Comparisons

 When will BFS outperform DFS?

 When will DFS outperform BFS?

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.

Algorithm Complete Optimal Time Space


DFS w/ Path
Checking Y N O(bm) O(bm)
BFS Y N* O(bs+1) O(bs+1)
ID Y N* O(bs+1) O(bs)

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

Notice that BFS finds the shortest path in terms of number of


transitions. It does not find the least-cost path.
We will quickly cover an algorithm which does find the least-cost path.

Uniform Cost Search


2 a G
b c
Expand cheapest node first: 1 8 2
2 e
3 d f
Fringe is a priority queue 9 1
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
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

 A priority queue is a data structure in which you can insert


and retrieve (key, value) pairs with the following operations:

pq.push(key, value) inserts (key, value) into the queue.


pq.pop() returns the key with the lowest value, and
removes it from the queue.

 You can decrease a key’s priority by pushing it again


 Unlike a regular queue, insertions aren’t constant time,
usually O(log n)
 We’ll need priority queues for cost-sensitive search methods

Uniform Cost Search


Algorithm Complete Optimal Time (in nodes) Space
DFS w/ Path
Checking Y N O(bm) O(bm)
BFS Y N O(bs+1) O(bs+1)
UCS Y* Y O(bC*/ε) O(bC*/ε)

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

Best First / Greedy Search


 Expand the node that seems closest…

 What can go wrong?

18
Best First / Greedy Search
 A common case: b
 Best-first takes you straight …
to the (wrong) goal

 Worst-case: like a badly-


guided DFS in the worst
case
 Can explore everything
 Can get stuck in loops if no
cycle checking b

 Like DFS in completeness


(finite states w/ cycle
checking)

Search Gone Wrong?

19
 Can we leverage the heuristic information
in a more sound way?

A* search

We will cover that on Wednesday!

20

You might also like