Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 32

CS 416

Artificial Intelligence
Lecture
Lecture 33
Uninformed
Uninformed Searches
Searches
(mostly
(mostly copied
copied from
from Berkeley)
Berkeley)
Outline
Problem
Problem Solving
Solving Agents
Agents
•• Restricted
Restricted form
form of
of general
general agent
agent
Problem
Problem Types
Types
•• Fully
Fully vs.
vs. partially
partially observable,
observable, deterministic
deterministic vs.
vs. stochastic
stochastic
Problem
Problem Formulation
Formulation
•• State
State space,
space, initial
initial state,
state, successor
successor function,
function, goal
goal test,
test, path
path cost
cost
Example
Example Problems
Problems
Basic
Basic Search
Search Algorithms
Algorithms
Problem Solving Agents
Restricted
Restricted form
form of
of general
general agent:
agent:
function
function SIMPLE-PROBLEM-SOLVING-AGENT(
SIMPLE-PROBLEM-SOLVING-AGENT(percept
percept)) returns
returns an
an action
action
static
static:: seq
seq,, an
an action
action sequence,
sequence, initially
initially empty
empty
state
state,, some
some description
description of of the
the current
current world
world state
state
goal
goal,, aa goal,
goal, initially
initially null
null
problem
problem,, aa problem
problem definition
definition
state
state <-<- UPDATE-STATE(
UPDATE-STATE(state
state,, percept
percept))
if
if seq
seq is
is empty
empty then
then
goal
goal <-
<- FORMULATE-GOAL(
FORMULATE-GOAL(state
state))
problem
problem <-
<- FORMULATE-PROBLEM(
FORMULATE-PROBLEM(state
state,, goal
goal))
seq
seq <-
<- SEARCH(
SEARCH(problem
problem))
action
action <-<- RECOMMENDATION(
RECOMMENDATION(seq,
seq, state)
state)
seq
seq <-
<- REMAINDER(
REMAINDER(seq,
seq, state
state))
return
return action
action
Note:
Note: This
This is
is offline
offline problem
problem solving;
solving; solution
solution with
with “eyes
“eyes closed.”
closed.”
Online
Online problem
problem solving
solving involves
involves acting
acting without
without complete
complete knowledge
knowledge
Example: Romania
On
On holiday
holiday in
in Romania;
Romania; currently
currently in
in Arad.
Arad.
Flight
Flight leaves
leaves tomorrow
tomorrow from
from Bucharest.
Bucharest.
Formulate
Formulate Goal:
Goal:
•• be
be in
in Bucharest
Bucharest
Formulate
Formulate Problem:
Problem:
•• states
states:: various
various cities
cities
•• actions
actions:: drive
drive between
between citites
citites
Find
Find Solution:
Solution:
•• Sequence
Sequence of
of cities,
cities, e.g.,
e.g., Arad,
Arad, Sibiu,
Sibiu, Fagaras,
Fagaras, Bucharest
Bucharest
Example: Romania
Problem Types
Deterministic,
Deterministic, fully observable 
fully observable  single-state
single-state problem
problem
•• Agent
Agent knows
knows exactly
exactly what
what state
state itit will
will be
be in;
in; solution
solution is
is aa sequence
sequence
Non-observable 
Non-observable  conformant
conformant problem
problem
•• Agent
Agent may
may have
have no
no idea
idea where
where itit is;
is; solution
solution (if
(if any)
any) is
is aa sequence
sequence
Non-deterministic
Non-deterministic and/or
and/or partially
partially observable
observable
•• Percepts
Percepts provide
provide new
new information
information about
about current
current state
state
•• Solution
Solution is
is aa tree
tree or
or policy
policy
•• Often
Often interleave
interleave search,
search, execution
execution
Unknown
Unknown state space 
state space  exploration
exploration problem
problem (“online”)
(“online”)
Example: Vacuum World
Single-state,
Single-state, start
start in
in #5.
#5.
•• Solution??
Solution??
Example: Vacuum World
Single-state,
Single-state, start
start in
in #5.
#5.
•• Solution:
Solution: [Right,
[Right, Suck]
Suck]

Conformant,
Conformant, start
start in
in
{1,2,3,4,5,6,7,8}
{1,2,3,4,5,6,7,8}
•• E.g.,
E.g., right
right goes
goes to
to {2,4,6,8}
{2,4,6,8}
•• Solution??
Solution??
Example: Vacuum World
Single-state,
Single-state, start
start in
in #5.
#5.
•• Solution:
Solution: [Right,
[Right, Suck]
Suck]
Conformant,
Conformant, start
start in
in {1,2,3,4,5,6,7,8}
{1,2,3,4,5,6,7,8}
•• E.g.,
E.g., right
right goes
goes to
to {2,4,6,8}
{2,4,6,8}
•• Solution:
Solution: [Right,
[Right, Suck,
Suck, Left,
Left, Suck]
Suck]
Contingency,
Contingency, start
start in
in #5
#5
•• Murphy’s
Murphy’s Law:
Law: Suck
Suck can
can dirty
dirty aa clean
clean
carpet
carpet
•• Local
Local sensing:
sensing: dirt,
dirt, location
location only
only
•• Solution??
Solution??
Example: Vacuum World
Single-state,
Single-state, start
start in
in #5.
#5.
•• Solution:
Solution: [[Right,
Right, Suck
Suck]]
Conformant,
Conformant, start
start in
in {1,2,3,4,5,6,7,8}
{1,2,3,4,5,6,7,8}
•• E.g.,
E.g., right
right goes
goes to
to {2,4,6,8}
{2,4,6,8}
•• Solution:
Solution: [[Right,
Right, Suck,
Suck, Left,
Left, Suck
Suck]]
Contingency,
Contingency, start
start in
in #5
#5
•• Murphy’s
Murphy’s Law:
Law: Suck
Suck can
can dirty
dirty aa clean
clean
carpet
carpet
•• Local
Local sensing:
sensing: dirt,
dirt, location
location only
only
•• Solution:
Solution: [[Right,
Right, ifif dirt
dirt then
then Suck
Suck]]
Single-state problem formation
A
A problem
problem is
is defined
defined by
by four
four items:
items:
Initial
Initial state
state
•• E.g.,
E.g., “at
“at Arad”
Arad”
Successor
Successor function
function S(x)
S(x) == set
set of
of action-state
action-state pairs
pairs
•• E.g.,
E.g., S(Arad)
S(Arad) == {<Arad Zerind,Zerind>,
{<Arad Zerind,Zerind>, <Arad
<AradSibiu,Sibiu>,…}
Sibiu,Sibiu>,…}
Goal
Goal test,
test, can
can be
be
•• Explicit,
Explicit, e.g.,
e.g., “at
“at Bucharest”
Bucharest”
•• Implicit,
Implicit, e.g.,
e.g., NoDirt(x)
NoDirt(x)
Path
Path cost
cost (additive)
(additive)
•• E.g.,
E.g., aa sum
sum of
of distances,
distances, number
number of
of actions
actions executed,
executed, etc.
etc.
•• C(x,a,y)
C(x,a,y) is
is the
the step
step cost,
cost, assumed
assumed to
to be
be non-negative
non-negative
A
A solution
solution is
is aa sequence
sequence of
of actions
actions leading
leading from
from the
the initial
initial state
state to
to aa goal
goal state
state
State Space
Real
Real world
world is
is absurdly complex 
absurdly complex  state
state space
space must
must be
be
abstracted
abstracted for
for problem
problem solving
solving
•• (Abstract)
(Abstract) state
state == set
set of
of real
real states
states
•• (Abstract)
(Abstract) action
action == complex
complex combination
combination of
of real
real actions,
actions, e.g.,
e.g.,
“Arad
“AradZerind”
Zerind” represents
represents aa complex
complex set
set of
of possible
possible routes,
routes, detours,
detours,
rest
rest stops,
stops, etc.
etc.
•• (Abstract)
(Abstract) solution
solution == set
set of
of real
real paths
paths that
that are
are solutions
solutions in
in the
the real
real world
world

Each
Each abstract
abstract action
action should
should be
be “easier”
“easier” than
than the
the original
original
problem!
problem!
Example: Vacuum World state space
graph

States?
States? Actions?
Actions? Goal
Goal test?
test? Path
Path cost?
cost?
Example: Vacuum World state space
graph
States:
States:
•• Integer
Integer dirt
dirt and
and robot
robot locations
locations
(ignore
(ignore dirt
dirt amounts)
amounts)

Actions:
Actions:
•• Left,
Left, Right,
Right, Suck,
Suck, NoOp
NoOp

Goal
Goal test:
test:
•• No
No dirt
dirt

Path
Path cost:
cost:
•• 11 per
per action
action (0
(0 for
for NoOp
NoOp))
Other Examples
Eight
Eight puzzle
puzzle
Robotic
Robotic Assembly
Assembly
States?
States? Actions?
Actions? Goal
Goal test?
test? Path
Path cost?
cost?
Tree Search Algorithms
Basic
Basic idea:
idea:
•• Offline,
Offline, simulated
simulated exploration
exploration of
of state
state space
space by
by generating
generating successors
successors of
of
already
already explored
explored states
states (AKA
(AKA expanding
expanding states)
states)

function
function TREE-SEARCH(
TREE-SEARCH(problem,
problem, strategy
strategy)) returns
returns aa solution,
solution, or
or failure
failure
initialize
initialize the
the search
search tree
tree using
using the
the initial
initial state
state of
of problem
problem
loop
loop do
do
if
if there
there are
are no
no more
more candidates
candidates for
for expansion
expansion then
then return
return failure
failure
choose
choose aa leaf
leaf node
node for
for expansion
expansion according
according to
to strategy
strategy
if
if the
the node
node contains
contains aa goal
goal state
state then
then return
return the
the corresponding
corresponding solution
solution
else
else expand
expand the
the node
node and
and add
add the
the resulting
resulting nodes
nodes to
to the
the search
search tree
tree
end
end
Implementation: states vs. nodes
State
State
•• (Representation
(Representation of)
of) aa physical
physical configureation
configureation
Node
Node
•• Data
Data structure
structure constituting
constituting part
part of
of aa search
search tree
tree
–– Includes
Includes parent,
parent, children,
children, depth,
depth, path
path cost
cost g(x)
g(x)
States
States do
do not
not have
have parents,
parents, children,
children, depth,
depth, or
or
path
path cost!
cost!
Implementation: general tree search
function
function TREE-SEARCH
TREE-SEARCH ((problem
problem,, fringe
fringe)) returns
returns aa solution,
solution, or
or failure
failure
fringe 
fringe  INSERT(MAKE-NODE(INITIAL-STATE[problem]),
INSERT(MAKE-NODE(INITIAL-STATE[problem]), fringe
fringe))
loop
loop do
do
if
if fringe
fringe is
is empty
empty then
then return
return false
false
node 
node  REMOVE-FRONT(
REMOVE-FRONT(fringe
fringe))
if
if GOAL-TEST[
GOAL-TEST[problem
problem]] applied
applied toto STATE(
STATE(node
node)) succeeds
succeeds return
return node
node
fringe 
fringe  INSERTALL(EXPAND(
INSERTALL(EXPAND(node
node,, problem
problem),
), fringe
fringe))

function
function EXPAND
EXPAND ((node
node,, problem
problem)) returns
returns aa set
set of
of states
states
successors 
successors  the
the empty
empty set
set
for
for each
each action,
action, result
result in
in SUCCESSOR-FN[problem](STATE[
SUCCESSOR-FN[problem](STATE[node node])
]) do
do
ss 
 aa new
new NODE
NODE
PARENT-NODE[ss]] 
PARENT-NODE[  node ACTION[ss]] 
node;; ACTION[  action STATE(ss)) 
action;; STATE(  result
result
PATH-COST[ss]] 
PATH-COST[  PATH-COST[
PATH-COST[node
node]] ++ STEP-COST(
STEP-COST(node,
node, action,
action, ss))
DEPTH[ss]] 
DEPTH[  DEPTH[
DEPTH[node
node]] ++ 11
add
add ss to
to successors
successors
return
return successors
successors

Find
Find the
the error
error on
on this
this page!
page!
Search strategies
A
A strategy
strategy is
is defined
defined by
by picking
picking the
the order
order of
of node
node expansion
expansion
Strategies
Strategies are
are evaluated
evaluated along
along the
the following
following dimensions:
dimensions:
•• Completeness
Completeness –– does
does itit always
always find
find aa solution
solution ifif one
one exists?
exists?
•• Time
Time complexity
complexity –– number
number of
of nodes
nodes generated/expanded
generated/expanded
•• Space
Space complexity
complexity –– maximum
maximum nodes
nodes in
in memory
memory
•• Optimality
Optimality –– does
does itit always
always find
find aa least
least cost
cost solution?
solution?
Time
Time and
and space
space complexity
complexity are
are measured
measured in
in terms
terms of:
of:
•• bb –– maximum
maximum branching
branching factor
factor of
of the
the search
search tree
tree
•• dd –– depth
depth of
of the
the least-cost
least-cost solution
solution
•• m
m –– maximum
maximum depth
depth of
of the
the state
state space
space (may
(may be
be infinite)
infinite)
Uninformed Search Strategies
Uninformed
Uninformed strategies
strategies use
use only
only the
the information
information
available
available in
in the
the problem
problem definition
definition
•• Breadth-first
Breadth-first search
search
•• Uniform-cost
Uniform-cost search
search
•• Depth-first
Depth-first search
search
•• Depth-limited
Depth-limited search
search
•• Iterative
Iterative deepening
deepening search
search
Breadth-first search
Expand
Expand shallowest
shallowest unexpanded
unexpanded node
node
Implementation:
Implementation:
•• Fringe
Fringe is
is aa FIFO
FIFO queue,
queue, i.e.,
i.e., new
new successors
successors go
go at
at end
end
•• Execute
Execute first
first few
few expansions
expansions of
of Arad
Arad to
to Bucharest
Bucharest using
using
Breadth-first
Breadth-first search
search
Properties of breadth-first search
Complete??
Complete?? Yes
Yes (if
(if bb is
is finite)
finite)
Time??
Time?? 11 ++ bb ++ bb22 ++ …
… ++ bbdd ++ b(b
b(bdd-1)
-1) == O(b d+1),
O(bd+1 ), i.e.,
i.e.,
exp
exp in
in dd
Space??
Space?? O(b d+1)) (keeps
O(bd+1 (keeps every
every node
node in
in memory)
memory)
Optimal??
Optimal?? IfIf cost
cost == 11 per
per step,
step, not
not optimal
optimal in
in
general
general
Space
Space is
is the
the big
big problem;
problem; can
can easily
easily generate
generate
nodes
nodes at
at 10
10 MB/s,
MB/s, so
so 24hrs
24hrs == 860GB!
860GB!
Uniform-cost search
Expand
Expand least-cost
least-cost unexpanded
unexpanded node
node
Implementation:
Implementation:
•• Fringe
Fringe == queue
queue ordered
ordered by
by path
path cost
cost
Equivalent
Equivalent to
to breadth-first
breadth-first if…
if…
Complete??
Complete?? IfIf step
step cost
cost ≥≥ εε
Time??
Time?? ## of
of nodes
nodes with
with gg ≤≤ cost
cost of
of optimal
optimal solution,
solution, O(b
O(bC/C/εε),), where
where C
C is
is the
the
cost
cost of
of the
the optimal
optimal solution
solution
Space??
Space?? ## of
of nodes
nodes with
with gg ≤≤ cost
cost of
of optimal
optimal solution,
solution, O(b
O(bC/C/εε))
Optimal??
Optimal?? Yes–nodes
Yes–nodes expanded
expanded in
in increasing
increasing order
order of
of g(n)
g(n)
Execute
Execute first
first few
few expansions
expansions of
of Arad
Arad to
to Bucharest
Bucharest using
using Uniform-first
Uniform-first search
search
Depth-first search
Expand
Expand deepest
deepest unexpanded
unexpanded node
node
Implementation:
Implementation:
•• Fringe
Fringe == LIFO
LIFO queue,
queue, i.e.,
i.e., aa stack
stack
•• Execute
Execute first
first few
few expansions
expansions of
of Arad
Arad to
to Bucharest
Bucharest using
using
Depth-first
Depth-first search
search
Depth-first search
Complete??
Complete??
Time??
Time??
Space??
Space??
Optimal??
Optimal??
Depth-first search
Complete??
Complete??
•• No:
No: fails
fails in
in infinite-depth
infinite-depth spaces,
spaces, spaces
spaces with
with loops.
loops.
•• Can
Can be
be modified
modified to
to avoid
avoid repeated
repeated states
states along
along path  complete
path  complete in
in finite
finite spaces
spaces
Time??
Time??
•• O(b
O(bmm)):: terrible
terrible ifif m
m is
is much
much larger
larger than
than dd,, but
but ifif solutions
solutions are
are dense,
dense, may
may be
be much
much faster
faster
than
than breadth-first
breadth-first
Space??
Space??
•• O(bm),
O(bm), i.e.,
i.e., linear
linear space!
space!
Optimal??
Optimal??
•• No
No
Depth-limited search
Depth-first
Depth-first search
search with
with depth
depth limit
limit ll
•• i.e.,
i.e., nodes
nodes at
at depth
depth ll have
have no
no successors
successors
function
function DEPTH-LIMITED-SEARCH
DEPTH-LIMITED-SEARCH ((problem,
problem, limit
limit)) returns
returns soln/fail/cutoff
soln/fail/cutoff
RECURSIVE-DLS(MAKE-NODE(INITIAL-STATE[
RECURSIVE-DLS(MAKE-NODE(INITIAL-STATE[problem
problem],
], problem
problem,, limit
limit))

function
function RECURSIVE-DLS
RECURSIVE-DLS ((node,
node, problem,
problem, limit
limit)) returns
returns soln/fail/cutoff
soln/fail/cutoff
cutoff-occurred? 
cutoff-occurred?  false
false
if
if GOAL-TEST[
GOAL-TEST[problem
problem](STATE[
](STATE[node
node])
]) then
then return
return node
node
else
else if
if DEPTH[
DEPTH[node
node]] == limit
limit then
then return
return cutoff
cutoff
else
else for
for each
each successor
successor inin EXPAND(
EXPAND(node
node,, problem
problem)) do
do
result 
result  RECURSIVE-DLS(
RECURSIVE-DLS(successor,
successor, problem,
problem, limit
limit))
if
if result
result == cutoff
cutoff then cutoff-occurred? 
then cutoff-occurred?  true
true
else
else if
if result
result ≠≠ failure
failure then
then return
return result
result
if
if cutoff-occurred?
cutoff-occurred? tthen
hen return
return cutoff
cutoff else
else return
return failure
failure
Depth-limited search
Complete??
Complete??
Time??
Time??
Space??
Space??
Optimal??
Optimal??
Iterative deepening search
function
function ITERATIVE-DEEPENING-SEARCH(
ITERATIVE-DEEPENING-SEARCH(problem
problem)) returns
returns aa solution
solution
inputs
inputs:: problem
problem,, aa problem
problem
for depth 
for depth  00 to
to ∞∞ do
do
result 
result  DEPTH-LIMITED-SEARCH(
DEPTH-LIMITED-SEARCH(problem
problem,, depth
depth))
if
if result
result ≠≠ cutoff
cutoff then
then return
return result
result
end
end
Properties of iterative deepening
Complete??
Complete??
Time??
Time??
Space??
Space??
Optimal??
Optimal??
Properties of iterative deepening
Complete??
Complete??
•• Yes
Yes
Time??
Time??
•• (d+1)b
(d+1)b00 ++ db
db11 ++ (d-1)b
(d-1)b22 ++ …
… bbdd == O(b
O(bdd))
Space??
Space??
•• O(bd)
O(bd)
Optimal??
Optimal??
•• IfIf step
step cost
cost == 11
•• Can
Can be be modified
modified to
to explore
explore uniform-cost
uniform-cost tree
tree
Summary
All
All tree
tree searching
searching techniques
techniques are
are more
more alike
alike than
than different
different
Breadth-first
Breadth-first has
has space
space issues,
issues, and
and possibly
possibly optimality
optimality issues
issues
Uniform-cost
Uniform-cost has
has space
space issues
issues
Depth-first
Depth-first has
has time
time and
and optimality
optimality issues,
issues, and
and possibly
possibly completeness
completeness
issues
issues
Depth-limited
Depth-limited search
search has
has optimality
optimality and
and completeness
completeness issues
issues
Iterative
Iterative deepening
deepening is
is the
the best
best uninformed
uninformed search
search we
we have
have explored
explored

Next
Next class
class we
we study
study informed
informed searches
searches

You might also like