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

Search: Introduc0on To Ar0ficial Intelligence

The document provides an introduction to search techniques in artificial intelligence, explaining that search is used to solve problems by exploring states and using actions to transition between states, with the goal of reaching a desired end state, and that representing a problem as a search problem involves defining the state space, possible actions, initial state, and goal.

Uploaded by

ARTS -أرطس
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)
28 views

Search: Introduc0on To Ar0ficial Intelligence

The document provides an introduction to search techniques in artificial intelligence, explaining that search is used to solve problems by exploring states and using actions to transition between states, with the goal of reaching a desired end state, and that representing a problem as a search problem involves defining the state space, possible actions, initial state, and goal.

Uploaded by

ARTS -أرطس
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/ 31

 

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.  

• Example:  On  holiday  in  England  


• Currently  in  Edinburgh  
• Flight  leaves  tomorrow  from  London  
• Need  plan  to  get  to  your  plane  
• If  I  take  a  6  am  train  where  will  I  be  at  2  pm?  Will  I  be  sJll  able  
to  get  to  the  airport  on  Jme?  

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  

To  formulate  a  problem  as  a  search  problem  we  need  the  


following  components:    
1. STATE  SPACE:  Formulate  a  state  space  over  which  we  
perform  search.  The  state  space  is  a  way  or  represenJng  
in  a  computer  the  states  of  the  real  problem.  
2. ACTIONS  or  STATE  SPACE  Transi0ons:  Formulate  acJons  
that  allow  one  to  move  between  different  states.  The  
acJons  reflect  the  acJons  one  can  take  in  the  real  
problem  but  operate  on  the  state  space  instead.    

8
Represen0ng  a  problem:  The  Formalism  

To  formulate  a  problem  as  a  search  problem  we  need  the  


following  components:    
3. INITIAL  or  START  STATE  and  GOAL:  IdenJfy  the  iniJal  
state  that  best  represents  the  starJng  condiJons,  and  the  
goal  or  condiJon  one  wants  to  achieve.  
4. Heuris0cs:  Formulate  various  heurisJcs  to  help  guide  the  
search  process.  

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  

Rule:  Can  slide  a  Jle  into  the  blank  spot.  


                     AlternaJve  view:  move  the  blank  spot  around.    

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  

• Perhaps  acJons  lead  to  mulJple  states,  e.g.,  flip  a  


coin  to  obtain  heads  OR  tails.  Or  we  don't  know  for  
sure  what  the  iniJal  state  is  (prize  is  behind  door  1,  
2,  or  3).  Now  we  might  want  to  consider  how  likely  
different  states  and  acJon  outcomes  are.    
• This  leads  to  probabilisJc  models  of  the  search  space  
and  different  algorithms  for  solving  the  problem.  
• Later  we  will  see  some  techniques  for  reasoning  
under  uncertainty.  

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.  

• The  search  algorithms  perform  search  by  examining  


alternate  paths  of  the  search  space.  The  objects  used  
in  the  algorithm  are  called  nodes—each  node  
contains  a  path.  

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  

Search(OPEN, Successors, Goal? )


While(Open not EMPTY) {
n = select node from OPEN
Curr = terminal state of n
If (Goal?(Curr)) return n.
OPEN = (OPEN– {n}) Us ∈ Successors(Curr)<n,s>
/* Note OPEN could grow or shrink */
}
return FAIL

When  does  OPEN  get  smaller  in  size?  

24  
 {<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>}  

Solu0on:  Arad  -­‐>  Sibiu  -­‐>  Fagaras  -­‐>  Bucharest  


 Cost:                  140      +        99      +        211        =          450  

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>}  

{<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>}  
…..  

cycles  can  cause  non-­‐terminaJon!  


…  we  deal  with  this  issue  later  
27  
Selec0on  Rule  
The  order  paths  are  selected  from  OPEN  has  a  criJcal  
effect  on  the  operaJon  of  the  search:  
• Whether  or  not  a  soluJon  is  found  
• The  cost  of  the  soluJon  found.  
• The  Jme  and  space  required  by  the  search.  

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.    

• How  do  we  order  the  paths  on  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

• Consider the following problem:


A Water Jug Problem: You are given two jugs, a 4-gallon one and a 3-
gallon one, a pump which has unlimited water which you can use to fill
the jug, and the ground on which water may be poured. Neither jug
has any measuring markings on it.
How can you get exactly 2 gallons of water in the 4-gallon jug?

You might also like