0% found this document useful (0 votes)
5 views54 pages

Lecture 2

The document covers search methods in artificial intelligence, focusing on agents that plan ahead, search problems, and various uninformed search techniques like Depth-First Search, Breadth-First Search, and Uniform-Cost Search. It discusses the characteristics of reflex and planning agents, the structure of state space graphs and search trees, and the properties of different search algorithms. Additionally, it highlights the importance of search strategies and their implications for finding optimal solutions in AI applications.

Uploaded by

nomorebluepen
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)
5 views54 pages

Lecture 2

The document covers search methods in artificial intelligence, focusing on agents that plan ahead, search problems, and various uninformed search techniques like Depth-First Search, Breadth-First Search, and Uniform-Cost Search. It discusses the characteristics of reflex and planning agents, the structure of state space graphs and search trees, and the properties of different search algorithms. Additionally, it highlights the importance of search strategies and their implications for finding optimal solutions in AI applications.

Uploaded by

nomorebluepen
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/ 54

CMPT 310: Artificial Intelligence

Search

Instructor: Steven Bergner


Simon Fraser University
(slides adapted from UC Berkeley CS188 slides)
Today
o Agents that Plan Ahead

o Search Problems

o Uninformed Search Methods


o Depth-First Search
o Breadth-First Search
o Uniform-Cost Search
Agents that Plan
Reflex Agents

o Reflex agents:
o Choose action based on current percept
(and maybe memory)
o May have memory or a model of the
world’s current state
o Do not consider the future consequences of
their actions
o Consider how the world IS

o Can a reflex agent be rational?


Video of Demo Reflex Optimal
Video of Demo Reflex Odd
Planning Agents

o Planning agents:
o Ask “what if”
o Decisions based on (hypothesized)
consequences of actions
o Must have a model of how the world
evolves in response to actions
o Must formulate a goal (test)
o Consider how the world WOULD BE

o Optimal vs. complete planning

o Planning vs. replanning


Video of Demo Replanning
Video of Demo Mastermind
Search Problems
Search Problems
o A search problem consists of:

o A state space

o A successor function “N”, 1.0


(with actions, costs)

“E”, 1.0
o A start state and a goal test

o A solution is a sequence of actions (a plan)


which transforms the start state to a goal state
Search Problems Are Models
Example: Traveling in Romania

o State space:
o Cities
o Successor function:
o Roads: Go to adjacent city with
cost = distance
o Start state:
o Arad
o Goal test:
o Is state == Bucharest?

o Solution?
What’s in a State Space?
The world state includes every last detail of the environment

A search state keeps only the details needed for planning (abstraction)

o Problem: Pathing o Problem: Eat-All-Dots


o States: (x,y) location o States: {(x,y), dot booleans}
o Actions: NSEW o Actions: NSEW
o Successor: update location o Successor: update location
only and possibly a dot boolean
o Goal test: is (x,y)=END o Goal test: dots all false
State Space Sizes?

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

o How many
o World states?
120x(230)x(122)x4
o States for pathing?
120
o States for eat-all-dots?
120x(230)
Quiz: Safe Passage

o Problem: eat all dots while keeping the ghosts perma-scared


o What does the state space have to specify?
o (agent position, dot booleans, power pellet booleans, remaining scared time)
State Space Graphs and Search Trees
State Space Graphs

o State space graph: A mathematical


representation of a search problem
o Nodes are (abstracted) world configurations
o Arcs represent successors (action results)
o The goal test is a set of goal nodes (maybe only one)

o In a state space graph, each state occurs only


once!

o We can rarely build this full graph in


memory (it’s too big), but it’s a useful idea
State Space Graphs

o State space graph: A mathematical


representation of a search problem a G
o Nodes are (abstracted) world configurations b c
o Arcs represent successors (action results)
e
o The goal test is a set of goal nodes (maybe only d f
one) S h
p q r
o In a state space graph, each state occurs
only once!
Tiny state space graph
o We can rarely build this full graph in for a tiny search problem
memory (it’s too big), but it’s a useful idea
Search Trees
This is now / start

“N”, 1.0 “E”, 1.0


Possible futures

o A search tree:
o A “what if” tree of plans and their outcomes
o The start state is the root node
o Children correspond to successors
o Nodes show states, but correspond to PLANS that achieve those states
o For most problems, we can never actually build the whole tree
State Space Graphs vs. Search Trees

State Space Graph Each NODE in


in the search Search Tree
tree is an S

a G entire PATH in d e p
b c the state b c e h r q
d
e
f
space graph. h r p q f
a a
S h
We construct p q f q c G
p q r
only what we q c G a
need on demand a
Quiz: State Space Graphs vs. Search Trees

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

S G

b
Quiz: State Space Graphs vs. Search Trees

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

a s
a b
S G
b G a G

b a G b G

… …

Important: Lots of repeated structure in the search tree!


Tree Search
Search Example: Romania
Searching with a Search Tree

o Search:
o Expand out potential plans (tree nodes)
o Maintain a fringe of partial plans under consideration
o Try to expand as few tree nodes as possible
General Tree Search

o Important ideas:
o Fringe
o Expansion
o Exploration strategy

o Main question: which fringe nodes to explore?


Example: Tree Search
a G
b c
e
d f
S h
p r
q
Example: Tree Search
a G
b c
e
d f
S h
p r
q

S s
sàd
d e p sàe
sàp
b c e h r q
sàdàb
sàdàc
a a h r p q f
sàdàe
q c G
sàdàeàh
p q f
sàdàeàr
q c G
a sàdàeàràf
sàdàeàràfàc
a sàdàeàràfàG
Depth-First Search
Depth-First Search
Strategy: expand a a G
b c
deepest node first
e
d f
Implementation: S h
Fringe is a LIFO stack 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
Search Algorithm Properties
Search Algorithm Properties
o Complete: Guaranteed to find a solution if one exists?
o Optimal: Guaranteed to find the least cost path?
o Time complexity?
o Space complexity? b 1 node
… b nodes
o Cartoon of search tree: b2 nodes
o b is the branching factor m tiers
o m is the maximum depth
o solutions at various depths
bm nodes
o Number of nodes in entire tree?
o 1 + b + b2 + …. bm = O(bm)
Depth-First Search (DFS) Properties
o What nodes DFS expand?
o Some left prefix of the tree. 1 node
o Could process the whole tree! b
… b nodes
o If m is finite, takes time O(bm)
m tiers b2 nodes
o How much space does the fringe take?
o Only has siblings on path to root, so O(bm)

o Is it complete? bm nodes
o m could be infinite, so only if we prevent
cycles (more later)

o Is it optimal?
o No, it finds the “leftmost” solution,
regardless of depth or cost
Breadth-First Search
Breadth-First Search
G
Strategy: expand a a
b c
shallowest node first
e
d f
Implementation: S h
Fringe is a FIFO 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

a
Breadth-First Search (BFS) Properties
o What nodes does BFS expand?
o Processes all nodes above shallowest
b 1 node
solution b

o Let depth of shallowest solution be s s tiers nodes
b2
o Search takes time O(bs)
nodes
bs nodes
o How much space does the fringe
take?
o Has roughly the last tier, so O(bs) bm nodes

o Is it complete?
o s must be finite if a solution exists, so yes!

o Is it optimal?
o Only if costs are all 1 (more on costs later)
Quiz: DFS vs BFS
Video of Demo Maze Water DFS/BFS (part 1)
Video of Demo Maze Water DFS/BFS (part 2)
Quiz: DFS vs BFS
o When will BFS outperform DFS?

o When will DFS outperform BFS?


Iterative Deepening
o Idea: get DFS’s space advantage with
BFS’s time / shallow-solution
b
advantages …
o Run a DFS with depth limit 1. If no
solution…
o Run a DFS with depth limit 2. If no
solution…
o Run a DFS with depth limit 3. …..

o Isn’t that wastefully redundant?


o Generally most work happens in the lowest
level searched, so not so bad!
Cost-Sensitive Search
GOAL
a
2 2
b c
3
2
1 8
2 e
3 d f
9 8 2
START
h
1 4 2
p 4 r
1 q
5
BFS finds the shortest path in terms of number of actions.
It does not find the least-cost path. We will now cover
a similar algorithm which does find the least-cost path.
Uniform Cost Search
Uniform Cost Search
2 G
a
Strategy: expand a b 1 8
c
2
cheapest node first: 3 d
2
e
f
9 8 2
S h
Fringe is a priority queue 1 p r
1

(priority: cumulative cost) 15


q

S 0
d 3 e 9 p 1

e 5 h 17 r 11 q 16
b 4 c 11

Cost a 6 a h 13 r 7 p q f
contours q c
p q f 8 G

q 11 c G 10 a

a
Uniform Cost Search (UCS) Properties
o What nodes does UCS expand?
o Processes all nodes with cost less than cheapest solution!
o If that solution costs C* and arcs cost at least e , then the b c£1

“effective depth” is roughly C*/e c£2
C*/e
o Takes time O(bC*/e) (exponential in effective depth) c£3
“tiers”
o How much space does the fringe take?
o Has roughly the last tier, so O(bC*/e)

o Is it complete?
o Assuming best solution has a finite cost and minimum
arc cost is positive, yes!

o Is it optimal?
o Yes! (Proof via A*)
Uniform Cost Issues
o Remember: UCS explores increasing
cost contours … c£1
c£2
c£3
o The good: UCS is complete and
optimal!

o The bad:
o Explores options in every “direction”
o No information about goal location Start Goal

o We’ll fix that soon!


Video of Demo Empty UCS
Demo Maze with Deep/Shallow Water --- DFS, BFS, or UCS? (part 1)
Demo Maze with Deep/Shallow Water --- DFS, BFS, or UCS? (part 2)
Demo Maze with Deep/Shallow Water --- DFS, BFS, or UCS? (part 3)
The One Queue
o All these search algorithms are the
same except for fringe strategies
o DFS: Fringe is a Stack
o BFS: Fringe is a Queue
o UCS: Fringe is a PriorityQueue
o Can even code one implementation
that takes a variable queuing object
Search and Models

o Search operates over


models of the world
o The agent doesn’t
actually try all the
plans out in the real
world!
o Planning is all “in
simulation”
o Your search is only as
good as your models…
Search Gone Wrong?

You might also like