Search: Introduc0on To Ar0ficial Intelligence
Search: Introduc0on To Ar0ficial Intelligence
Search
• One
of
the
most
basic
techniques
in
AI
• Underlying
sub-‐module
in
most
AI
systems
• Can
solve
many
problems
that
humans
are
not
good
at
(achieving
super-‐human
performance)
• Very
useful
as
a
general
algorithmic
technique
for
solving
many
non-‐AI
problems.
1
How
do
we
plan
our
holiday?
• We
must
take
into
account
various
preferences
and
constraints
to
develop
a
schedule.
• An
important
technique
in
developing
such
a
schedule
is
“hypotheJcal”
reasoning.
2
How
do
we
plan
our
holiday?
• This
kind
of
hypotheJcal
reasoning
involves
asking
• what
state
will
I
be
in
aUer
taking
certain
acJons,
or
aUer
certain
sequences
of
events?
• From
this
we
can
reason
about
parJcular
sequences
of
events
or
acJons
one
should
try
to
bring
about
to
achieve
a
desirable
state.
• Search
is
a
computaJonal
method
for
capturing
a
parJcular
version
of
this
kind
of
reasoning.
3
Many
problems
can
be
solved
by
search:
4
Why
Search?
• Successful
• Success
in
game
playing
programs
based
on
search.
• Many
other
AI
problems
can
be
successfully
solved
by
search.
• PracJcal
• Many
problems
don't
have
specific
algorithms
for
solving
them.
CasJng
as
search
problems
is
oUen
the
easiest
way
of
solving
them.
• Search
can
also
be
useful
in
approximaJon
(e.g.,
local
search
in
opJmizaJon
problems).
• Problem
specific
heurisJcs
provides
search
with
a
way
of
exploiJng
extra
knowledge.
• Some
criJcal
aspects
of
intelligent
behaviour,
e.g.,
planning,
can
be
naturally
cast
as
search.
5
Limita0ons
of
Search
• There
are
many
difficult
quesJons
that
are
not
resolved
by
search.
In
parJcular,
the
whole
quesJon
of
how
does
an
intelligent
system
formulate
the
problem
it
wants
to
solve
as
a
search
problem
is
not
addressed
by
search.
• Search
only
shows
how
to
solve
the
problem
once
we
have
it
correctly
formulated.
6
Search
Search
• FormulaJng
a
problem
as
search
problem
(representaJon)
• HeurisJc
Search
• Game-‐Tree-‐Search
• Readings
• IntroducJon:
Chapter
3.1
–
3.3
• Uninformed
Search:
Chapter
3.4
• HeurisJc
Search:
Chapters
3.5,
3.6
7
Represen0ng
a
problem:
The
Formalism
8
Represen0ng
a
problem:
The
Formalism
9
The
Formalism
Once
the
problem
has
been
formulated
as
a
state
space
search,
various
algorithms
can
be
uJlized
to
solve
the
problem.
• A
soluJon
to
the
problem
will
be
a
sequence
of
acJons/moves
that
can
transform
your
current
state
into
a
state
where
your
desired
condiJon
holds.
10
Example
1:
Romania
Travel.
Currently
in
Arad,
need
to
get
to
Bucharest
by
tomorrow
to
catch
a
flight.
What
is
the
State
Space?
11
Example
1.
• State
space.
• States:
the
various
ciJes
you
could
be
located
in.
• Our
abstracJon:
we
are
ignoring
the
low
level
details
of
driving,
states
where
you
are
on
the
road
between
ciJes,
etc.
• AcJons:
drive
between
neighboring
ciJes.
• IniJal
state:
in
Arad
• Desired
condiJon
(Goal):
be
in
a
state
where
you
are
in
Bucharest.
(How
many
states
saJsfy
this
condiJon?)
• SoluJon
will
be
the
route,
the
sequence
of
ciJes
to
travel
through
to
get
to
Bucharest.
12
Example
2.
• Water
Jugs
• We
have
a
3
gallon
(liter)
jug
and
a
4
gallon
jug.
We
can
fill
either
jug
to
the
top
from
a
tap,
we
can
empty
either
jug,
or
we
can
pour
one
jug
into
the
other
(at
least
unJl
the
other
jug
is
full).
• States:
pairs
of
numbers
(gal3,
gal4)
where
gal3
is
the
number
of
gallons
in
the
3
gallon
jug,
and
gal4
is
the
number
of
gallons
in
the
4
gallon
jug.
• AcJons:
Empty-‐3-‐Gallon,
Empty-‐4-‐Gallon,
Fill-‐3-‐Gallon,
Fill-‐4-‐
Gallon,
Pour-‐3-‐into-‐4,
Pour
4-‐into-‐3.
• IniJal
state:
Various,
e.g.,
(0,0)
• Desired
condiJon
(Goal):
Various,
e.g.,
(0,2)
or
(*,
3)
where
*
means
we
don't
care.
13
Example
2.
• Water
Jugs
• If
we
start
off
with
gal3
and
gal4
as
integer,
can
only
reach
integer
values.
• Some
values,
e.g.,
(1,2)
are
not
reachable
from
some
iniJal
state,
e.g.,
(0,0).
• Some
acJons
are
no-‐ops.
They
do
not
change
the
state,
e.g.,
• (0,0)
à
Empty-‐3-‐Gallon
à
(0,0)
14
Example
3.
The
8-‐Puzzle
15
Example
3.
The
8-‐Puzzle
• State
space.
• States:
The
different
configuraJons
of
the
Jles.
How
many
different
states?
• AcJons:
Moving
the
blank
up,
down,
leU,
right.
Can
every
acJon
be
performed
in
every
state?
• IniJal
state:
e.g.,
state
shown
on
previous
slide.
• Desired
condiJon
(Goal):
be
in
a
state
where
the
Jles
are
all
in
the
posiJons
shown
on
the
previous
slide.
• SoluJon
will
be
a
sequence
of
moves
of
the
blank
that
transform
the
iniJal
state
to
a
goal
state.
16
Example
3.
The
8-‐Puzzle
• Although
there
are
9!
different
configuraJons
of
the
Jles
(362,880)
in
fact
the
state
space
is
divided
into
two
disjoint
parts.
• Only
when
the
blank
is
in
the
middle
are
all
four
acJons
possible.
• Our
goal
condiJon
is
saJsfied
by
only
a
single
state.
But
one
could
easily
have
a
goal
condiJon
like
• The
8
is
in
the
upper
leU
hand
corner.
• How
many
different
states
saJsfy
this
goal?
17
More
complex
situa0ons
18
Algorithms
for
Search
Inputs:
• a
specified
iniJal
state
(a
specific
world
state)
• a
successor
funcJon
S(x)
=
{set
of
states
that
can
be
reached
from
state
x
via
a
single
acJon}.
• a
goal
test
a
funcJon
that
can
be
applied
to
a
state
and
returns
true
if
the
state
saJsfies
the
goal
condiJon.
• An
acJon
cost
funcJon
C(x,a,y)
which
determines
the
cost
of
moving
from
state
x
to
state
y
using
acJon
a.
(C(x,a,y)
=
∞
if
a
does
not
yield
y
from
x).
Note
that
different
acJons
might
generate
the
same
move
of
x
à
y.
19
Algorithms
for
Search
Output:
• a
sequence
of
states
leading
from
the
iniJal
state
to
a
state
saJsfying
the
goal
test.
• The
sequence
might
be,
opJmal
in
cost
for
some
algorithms,
opJmal
in
length
for
some
algorithms,
come
with
no
opJmality
guarantees
from
other
algorithms.
20
Algorithms
for
Search
Obtaining
the
acJon
sequence.
• The
set
of
successors
of
a
state
x
might
arise
from
different
acJons,
e.g.,
• x
→
a
→
y
• x
→
b
→
z
• Successor
funcJon
S(x)
yields
a
set
of
states
that
can
be
reached
from
x
via
any
single
acJon.
• Rather
than
just
return
a
set
of
states,
we
annotate
these
states
by
the
acJon
used
to
obtain
them:
• S(x)
=
{<y,a>,
<z,b>}
y
via
acJon
a,
z
via
acJon
b.
• S(x)
=
{<y,a>,
<y,b>}
y
via
acJon
a,
also
y
via
alternaJve
acJon
b.
21
Template
Search
Algorithms
• The
search
space
consists
of
states
and
acJons
that
move
between
states.
• A
path
in
the
search
space
is
a
sequence
of
states
connected
by
acJons,
<s0,
s1,
s2,
…,
sk>,
for
every
si
and
its
successor
si+1
there
must
exist
an
acJon
ai
that
transiJons
si
to
si+1.
• Alternately
a
path
can
be
specified
by
(a)
an
iniJal
state
s0,
and
(b)
a
sequence
of
acJons
that
are
applied
in
turn
starJng
from
s0.
22
Template
Algorithm
for
Search
• We
maintain
a
set
of
FronJer
nodes
also
called
the
OPEN
set.
• These
nodes
are
paths
in
the
search
space
that
all
start
at
the
iniJal
state.
• IniJally
we
set
OPEN
=
{<Start
State>}
• The
path
(node)
that
starts
and
terminates
at
the
start
state.
• At
each
step
we
select
a
node
n
from
OPEN.
Let
x
be
the
state
n
terminates
at.
We
check
if
x
saJsfies
the
goal,
if
not
we
add
all
extensions
of
n
to
OPEN
(by
finding
all
states
in
S(x)).
23
Template
Algorithm
for
Search
24
{<Arad>},
{<A,Z>,
<A,T>,
<A,
S>},
25
{<Arad>},
{<A,Z>,
<A,T>,
<A,
S>},
{<A,Z>,
<A,T>,
<A,S,A>,
<A,S,O>,
<A,S,F>,
<A,S,R>}
{<A,Z>, <A,T>, <A,S,A>, <A,S,O>, <A,S,F>, <A,S,R,S>, <A,S,R,C>, <A,S,R,P,R>, <A,S,R,P,C>, <A,S,R,P,B>}
Solu0on:
Arad
-‐>
Sibiu
-‐>
Rimnicu
Vilcea
-‐>
Pites0
-‐>
Bucharest
Cost:
140
+
80
+
97
+
101
=
418
26
{<Arad>},
{<A,Z>,
<A,T>,
<A,
S>},
{<A,Z>,
<A,T>,
<A,S,A>,
<A,S,O>,
<A,S,F>,
<A,S,R>}
{<A,Z>,
<A,T>,
<A,S,A>,
<A,S,O>,
<A,S,R>,
<A,S,F,S>,
<A,S,F,B>}
…..
28
How
to
select
the
next
path
from
OPEN?
All
search
techniques
keep
OPEN
as
an
ordered
set
(e.g.,
a
priority
queue)
and
repeatedly
execute:
• If
OPEN
is
empty,
terminate
with
failure.
• Get
the
next
path
from
OPEN.
• If
the
path
leads
to
a
goal
state,
terminate
with
success.
• Extend
the
path
(i.e.
generate
the
successor
states
of
the
terminal
state
of
the
path)
and
put
the
new
paths
in
OPEN.
29
Cri0cal
Proper0es
of
Search
• Completeness:
will
the
search
always
find
a
soluJon
if
a
soluJon
exists?
• OpJmality:
will
the
search
always
find
the
least
cost
soluJon?
(when
acJons
have
costs)
• Time
complexity:
what
is
the
maximum
number
of
nodes
(paths)
than
can
be
expanded
or
generated?
• Space
complexity:
what
is
the
maximum
number
of
nodes
(paths)
that
have
to
be
stored
in
memory?
30
Water Jug Problem – Self-Practical