Solving problems by searching Part I: Uninformed Search - - PowerPoint PPT Presentation
Solving problems by searching Part I: Uninformed Search - - PowerPoint PPT Presentation
Solving problems by searching Part I: Uninformed Search Formula<ng a Problem Domain State: Some descrip<on of the current world state Ac<on:
Formula<ng ¡a ¡Problem ¡Domain ¡
- State: ¡Some ¡descrip<on ¡of ¡the ¡current ¡world ¡
state ¡
- Ac<on: ¡Means ¡to ¡manipulate ¡the ¡world. ¡
- Goal: ¡The ¡desired ¡descrip<on ¡of ¡the ¡world. ¡
- Problem: ¡Descrip<on ¡of ¡the ¡problem ¡to ¡be ¡
- solved. ¡
- Solu<on: ¡Sequence ¡of ¡ac<ons ¡that ¡will ¡lead ¡us ¡
from ¡to ¡the ¡goal ¡state. ¡
Example: ¡Romania ¡
- On ¡holiday ¡in ¡Romania; ¡currently ¡in ¡Arad. ¡
- Flight ¡leaves ¡tomorrow ¡from ¡Bucharest ¡
¡
- Formulate ¡goal: ¡
– be ¡in ¡Bucharest ¡ ¡
- Formulate ¡problem: ¡
– states: ¡various ¡ci<es ¡ – ac<ons: ¡drive ¡between ¡ci<es ¡ ¡
- Find ¡solu<on: ¡
– sequence ¡of ¡ci<es, ¡e.g., ¡Arad, ¡Sibiu, ¡Fagaras, ¡Bucharest ¡ ¡
Example: ¡Romania ¡
Problem ¡types ¡
- Determinis<c, ¡fully ¡observable ¡à ¡single-‑state ¡problem ¡
– Agent ¡knows ¡exactly ¡which ¡state ¡it ¡will ¡be ¡in; ¡solu<on ¡is ¡a ¡sequence ¡ ¡
- Non-‑observable ¡à ¡sensorless ¡problem ¡(conformant ¡problem) ¡
– Agent ¡may ¡have ¡no ¡idea ¡where ¡it ¡is; ¡solu<on ¡is ¡a ¡sequence ¡ ¡
- Nondeterminis<c ¡and/or ¡par<ally ¡observable ¡à ¡con<ngency ¡
problem ¡
– percepts ¡provide ¡new ¡informa<on ¡about ¡current ¡state ¡ – oRen ¡interleave} ¡search, ¡execu<on ¡ ¡
- Unknown ¡state ¡space ¡à ¡explora<on ¡problem ¡
Single-‑state ¡problem ¡formula<on ¡
A ¡problem ¡is ¡defined ¡by ¡four ¡items: ¡
- 1. ini<al ¡state ¡e.g., ¡"at ¡Arad" ¡
¡
- 2. ac<ons ¡or ¡successor ¡func<on ¡S(x) ¡= ¡set ¡of ¡ac<on–state ¡pairs ¡ ¡
– e.g., ¡S(Arad) ¡= ¡{<Arad ¡à ¡Zerind, ¡Zerind>, ¡… ¡} ¡ ¡
- 3. goal ¡test, ¡can ¡be ¡
– explicit, ¡e.g., ¡x ¡= ¡"at ¡Bucharest" ¡ – implicit, ¡e.g., ¡Checkmate(x) ¡ ¡
- 4. path ¡cost ¡(addi<ve) ¡
– e.g., ¡sum ¡of ¡distances, ¡number ¡of ¡ac<ons ¡executed, ¡etc. ¡ – c(x,a,y) ¡is ¡the ¡step ¡cost, ¡assumed ¡to ¡be ¡≥ ¡0 ¡
- A ¡solu<on ¡is ¡a ¡sequence ¡of ¡ac<ons ¡leading ¡from ¡the ¡ini<al ¡state ¡to ¡a ¡
goal ¡state ¡
Selec<ng ¡a ¡state ¡space ¡
- Real ¡world ¡is ¡absurdly ¡complex ¡ ¡
à ¡state ¡space ¡must ¡be ¡abstracted ¡for ¡problem ¡solving ¡ ¡
- (Abstract) ¡state ¡= ¡set ¡of ¡real ¡states ¡
¡
- (Abstract) ¡ac<on ¡= ¡complex ¡combina<on ¡of ¡real ¡ac<ons ¡
– e.g., ¡"Arad ¡à ¡Zerind" ¡represents ¡a ¡complex ¡set ¡of ¡possible ¡routes, ¡detours, ¡rest ¡ stops, ¡etc. ¡ ¡
- For ¡guaranteed ¡realizability, ¡any ¡real ¡state ¡"in ¡Arad“ ¡must ¡get ¡to ¡some ¡real ¡
state ¡"in ¡Zerind" ¡ ¡
- (Abstract) ¡solu<on ¡= ¡ ¡
– set ¡of ¡real ¡paths ¡that ¡are ¡solu<ons ¡in ¡the ¡real ¡world ¡ ¡
- Each ¡abstract ¡ac<on ¡should ¡be ¡"easier" ¡than ¡the ¡original ¡problem ¡
¡
Example: ¡The ¡8-‑puzzle ¡
- states ¡= ¡integer ¡loca<ons ¡of ¡<les ¡
- ac<ons ¡= ¡move ¡blank ¡leR, ¡right, ¡up, ¡down ¡
- goal ¡test: ¡= ¡goal ¡state ¡(given) ¡path ¡
- cost: ¡1 ¡per ¡move ¡ ¡
- [Note: ¡op<mal ¡solu<on ¡of ¡n-‑Puzzle ¡family ¡is ¡NP-‑hard] ¡ ¡
2
Start State Goal State
5 1 3 4 6 7 8 5 1 2 3 4 6 7 8 5
Example: ¡robo<c ¡assembly ¡
- states: ¡
– real-‑valued ¡coordinates ¡of ¡robot ¡joint ¡angles ¡ – parts ¡of ¡object ¡to ¡be ¡assembled ¡
- ac<ons: ¡con<nuous ¡mo<on ¡of ¡robot ¡joints ¡
- goal ¡test: ¡complete ¡assembly ¡
- path ¡cost: ¡<me ¡to ¡execute ¡
R R R P R R
Tree ¡search ¡example ¡
- Simple ¡means ¡to ¡find ¡a ¡path ¡to ¡the ¡goal ¡state. ¡
14 ¡Jan ¡2004 ¡ CS ¡3243 ¡-‑ ¡Blind ¡Search ¡ 11 ¡
Tree ¡search ¡example ¡
Rimnicu Vilcea
Lugoj Zerind Sibiu Arad Fagaras Oradea Timisoara Arad Arad Oradea Arad
14 ¡Jan ¡2004 ¡ CS ¡3243 ¡-‑ ¡Blind ¡Search ¡ 12 ¡
Tree ¡search ¡example ¡
Rimnicu Vilcea
Lugoj Arad Fagaras Oradea Arad Arad Oradea Zerind Arad Sibiu Timisoara
14 ¡Jan ¡2004 ¡ CS ¡3243 ¡-‑ ¡Blind ¡Search ¡ 13 ¡
Tree ¡search ¡example ¡
Lugoj Arad Arad Oradea
Rimnicu Vilcea
Zerind Arad Sibiu Arad Fagaras Oradea Timisoara
Tic ¡Tac ¡Toe ¡Example ¡
X X X X X X X X X −
Tic ¡Tac ¡Toe ¡Example ¡
X X X X X X X X X X X O O X O . . . −
Tic ¡Tac ¡Toe ¡Example ¡
X X X X X X X X X X X O O X O X O X O X O X X X . . . . . . −
Tic ¡Tac ¡Toe ¡Example ¡
X X X X X X X X X X X O O O X O O O O O O O X O X O X O X X X X X X X X O X X O X X O X . . . . . . . . . . . . . . . . . . . . . X X −1 +1
Uninformed ¡search ¡strategies ¡
- Uninformed ¡strategies ¡use ¡only ¡the ¡
informa<on ¡available ¡in ¡the ¡problem ¡ defini<on ¡ ¡
– Breadth-‑first ¡search ¡ – Uniform-‑cost ¡search ¡ – Depth-‑first ¡search ¡ – Depth-‑limited ¡search ¡ – Itera<ve ¡deepening ¡search ¡ ¡
Search ¡strategies ¡
- A ¡strategy ¡is ¡defined ¡by ¡picking ¡the ¡order ¡of ¡node ¡
expansion ¡ ¡
- Strategies ¡are ¡evaluated ¡along ¡the ¡following ¡dimensions: ¡
– completeness—does ¡it ¡always ¡find ¡a ¡solu<on ¡if ¡one ¡exists? ¡ – <me ¡complexity—number ¡of ¡nodes ¡generated/expanded ¡ – space ¡complexity—maximum ¡number ¡of ¡nodes ¡in ¡memory ¡ – op<mality—does ¡it ¡always ¡find ¡a ¡least-‑cost ¡solu<on? ¡ ¡
- Time ¡and ¡space ¡complexity ¡are ¡measured ¡in ¡terms ¡of ¡
– b—maximum ¡branching ¡factor ¡of ¡the ¡search ¡tree ¡ – d—depth ¡of ¡the ¡least-‑cost ¡solu<on ¡ – m—maximum ¡depth ¡of ¡the ¡state ¡space ¡(may ¡be ¡∞) ¡ ¡
Breadth-‑first ¡search ¡
Expand ¡shallowest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡FIFO ¡queue ¡new ¡successors ¡go ¡at ¡the ¡end: ¡ ¡
A B C D E F G
Breadth-‑first ¡search ¡
Expand ¡shallowest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡FIFO ¡queue ¡new ¡successors ¡go ¡at ¡the ¡end: ¡ ¡
A B C D E F G
Breadth-‑first ¡search ¡
Expand ¡shallowest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡FIFO ¡queue ¡new ¡successors ¡go ¡at ¡the ¡end: ¡ ¡ A B C D E F G
Breadth-‑first ¡search ¡
Expand ¡shallowest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡FIFO ¡queue ¡new ¡successors ¡go ¡at ¡the ¡end: ¡ ¡ A B C D E F G
Proper<es ¡of ¡Breadth ¡First ¡Search ¡
- Complete: ¡Yes ¡(if ¡b ¡is ¡finite) ¡
- Time: ¡1+b+b2+b3+...+bd+b(bd−1) ¡= ¡O(bd+1) ¡
- Space: ¡O(bd+1) ¡(keeps ¡every ¡node ¡in ¡memory) ¡
- Op<mal: ¡
– Yes ¡(if ¡cost ¡= ¡1 ¡per ¡step) ¡ – Not ¡op<mal ¡in ¡general ¡
- Space ¡is ¡the ¡big ¡problem; ¡can ¡easily ¡generate ¡nodes ¡
at ¡100MB/sec ¡so ¡24hrs ¡= ¡8640GB. ¡ ¡
Depth-‑first ¡search ¡
Expand ¡deepest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡LIFO ¡queue; ¡put ¡successors ¡at ¡front: ¡ ¡
A B C D E F G H I J K L M N O
Depth-‑first ¡search ¡
Expand ¡deepest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡LIFO ¡queue; ¡put ¡successors ¡at ¡front: ¡ ¡
A B C D E F G H I J K L M N O
Depth-‑first ¡search ¡
Expand ¡deepest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡LIFO ¡queue; ¡put ¡successors ¡at ¡front: ¡ ¡
A B C D E F G H I J K L M N O
Depth-‑first ¡search ¡
Expand ¡deepest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡LIFO ¡queue; ¡put ¡successors ¡at ¡front: ¡ ¡
A B C D E F G H I J K L M N O
Depth-‑first ¡search ¡
Expand ¡deepest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡LIFO ¡queue; ¡put ¡successors ¡at ¡front: ¡ ¡
A B C D E F G H I J K L M N O
Depth-‑first ¡search ¡
Expand ¡deepest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡LIFO ¡queue; ¡put ¡successors ¡at ¡front: ¡ ¡
A B C D E F G H I J K L M N O
Depth-‑first ¡search ¡
Expand ¡deepest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡LIFO ¡queue; ¡put ¡successors ¡at ¡front: ¡ ¡
A B C D E F G H I J K L M N O
Depth-‑first ¡search ¡
Expand ¡deepest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡LIFO ¡queue; ¡put ¡successors ¡at ¡front: ¡ ¡
A B C D E F G H I J K L M N O
Depth-‑first ¡search ¡
Expand ¡deepest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡LIFO ¡queue; ¡put ¡successors ¡at ¡front: ¡ ¡
A B C D E F G H I J K L M N O
Depth-‑first ¡search ¡
Expand ¡deepest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡LIFO ¡queue; ¡put ¡successors ¡at ¡front: ¡ ¡
A B C D E F G H I J K L M N O
Depth-‑first ¡search ¡
Expand ¡deepest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡LIFO ¡queue; ¡put ¡successors ¡at ¡front: ¡ ¡
A B C D E F G H I J K L M N O
Depth-‑first ¡search ¡
Expand ¡deepest ¡unexpanded ¡node ¡ Implementa<on: ¡ ¡fringe ¡is ¡a ¡LIFO ¡queue; ¡put ¡successors ¡at ¡front: ¡ ¡
A B C D E F G H I J K L M N O
Proper<es ¡of ¡Depth ¡First ¡Search ¡
- Complete: ¡No: ¡(fails ¡with ¡infinite-‑depth, ¡loops) ¡
– Modify ¡to ¡avoid ¡repeated ¡states ¡
- Complete ¡in ¡finite ¡state ¡spaces. ¡
¡
- Time: ¡O(bm) ¡(terrible ¡if ¡m ¡is ¡much ¡larger ¡than ¡d) ¡
- Space: ¡O(bm) ¡linear ¡(beler!) ¡
- Op<mal: ¡No ¡
Depth-‑limited ¡search ¡
- Depth-‑first ¡search ¡with ¡depth ¡limit, ¡L ¡
– (i.e., ¡pretend ¡nodes ¡at ¡depth ¡L ¡have ¡no ¡successors) ¡
- Itera<ve ¡deepening ¡search ¡
– Repeated ¡applica<on ¡of ¡depth-‑limited ¡search ¡
- Start ¡depth ¡at ¡0 ¡
- Increase ¡depth ¡un<l ¡solu<on ¡is ¡found ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡
(up ¡to ¡a ¡poten<al ¡cutoff) ¡
Itera<ve ¡deepening ¡search ¡
Limit = 0
A A
Itera<ve ¡deepening ¡search ¡
Limit = 1
A B C A B C A B C A B C
Itera<ve ¡deepening ¡search ¡
Limit = 2
A B C D E F G A B C D E F G A B C D E F G A B C D E F G A B C D E F G A B C D E F G A B C D E F G A B C D E F G
Itera<ve ¡deepening ¡search ¡
Limit = 3
A B C D E F G H I J K L M N O A B C D E F G H I J K L M N O A B C D E F G H I J K L M N O A B C D E F G H I J K L M N O A B C D E F G H I J K L M N O A B C D E F G H I J K L M N O A B C D E F G H I J K L M N O A B C D E F G H I J K L M N O A B C D E F G H I J K L M N O A B C D E F G H I J K L M N O A B C D E F G H J K L M N O I A B C D E F G H I J K L M N O
Proper<es ¡of ¡IDS ¡
- Complete: ¡Yes ¡
- Time: ¡(d+1)b0 ¡+db1 ¡+(d−1)b2 ¡+...+bd ¡=O(bd) ¡ ¡
- Space: ¡O(bd) ¡
- Op<mal: ¡Yes, ¡if ¡step ¡cost ¡= ¡1 ¡
- IDS ¡combines ¡the ¡low ¡memory ¡use ¡of ¡DFS ¡with ¡the ¡
completeness ¡of ¡BFS ¡search. ¡
Summary ¡
- Problem ¡formula<on ¡usually ¡requires ¡abstrac<ng ¡
away ¡real-‑world ¡details ¡to ¡define ¡a ¡state ¡space ¡that ¡ can ¡feasibly ¡be ¡explored ¡ ¡
- Variety ¡of ¡uninformed ¡search ¡strategies ¡ ¡
- Itera<ve ¡deepening ¡search ¡uses ¡only ¡linear ¡space ¡