search i
play

Search I School of Data Science, Fudan University February - PowerPoint PPT Presentation

Search I School of Data Science, Fudan University February 27 th , 2019 Outline Search Problems Uninformed Search Depth-First Search Breadth-First Search Uniform-Cost Search Real world


  1. Search I 魏忠钰 复旦大学大数据学院 School of Data Science, Fudan University February 27 th , 2019

  2. Outline ▪ Search Problems ▪ Uninformed Search ▪ Depth-First Search ▪ Breadth-First Search ▪ Uniform-Cost Search

  3. Real world task - Pac-man

  4. Search problems ▪ A search problem consists of: ▪ A state space ▪ A successor function (with actions, costs) ▪ A start state ▪ A goal test

  5. Search Problems - Pac-man ▪ A search problem consists of: ▪ A state space ▪ A successor function (with actions, costs) “N”, 1.0 “E”, 1.0 ▪ A start state ▪ A goal test ▪ Move to a specific position

  6. Real world task : the 8-puzzle Start State Goal State

  7. Search Problems: the 8-puzzle Start State Goal State ▪ State space ▪ integer locations of 8 tiles. ▪ Successor function: ▪ Move blank (up, down, right, left)

  8. Real Task: 8-Queens Puzzle ▪ Place 8 queens on a chessboard so that no two queens attack each other. ▪ A queen attacks any piece in the same row, column or diagonal. ▪ 3 more queens missing

  9. Search Problem: 8-Queens Puzzle ▪ State space : any arrangement of 0 to 8 queens on board ▪ Successor function: add a queen to any square ▪ Start state : blank board ▪ Goal test : 8 queens on board, non attacked

  10. Real world task : Traveling in Romania

  11. Search Problems: Traveling in Romania ▪ State space ▪ Cities ▪ Successor function: ▪ Roads: Go to adjacent city with cost = distance ▪ Start state: ▪ Arad ▪ Goal test: ▪ Is state == Bucharest?

  12. What is 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) ▪ Problem: Pathing ▪ Problem: Eat-All-Dots ▪ States: (x,y) location ▪ States: {(x,y), dot booleans} ▪ Actions: NSEW ▪ Actions: NSEW ▪ Successor: update location ▪ Successor: update location only and possibly a dot boolean ▪ Goal test: is (x,y)=END ▪ Goal test: dots all false

  13. State Space Sizes? • World state: • Board blanks: 64 • Queen number: 8 • How many • World states? • 64 8

  14. State Space Sizes? • World state: • Agent positions: 120 • Food count: 30 • Ghost positions: 12 • Agent facing: NSEW • How many • World states? 120x(2 30 )x(12 2 )x4 • States for pathing? 120 • States for eat-all-dots? 120x(2 30 )

  15. Safe Passage • Problem: eat all dots while keeping the ghosts perma-scared ( 无敌是多么 寂寞 ) • What does the state space have to specify? • (agent position, dot booleans, power dot booleans, remaining scared time)

  16. State Space Graphs and Search Trees

  17. State Space Graph ▪ State space graph: A mathematical representation of a search problem ▪ Nodes are (abstracted) world configurations ▪ Arcs represent successors (action results) ▪ The goal test is a set of goal nodes (maybe only one) ▪ In a state space graph, each state occurs only once! ▪ We can rarely build this full graph in memory (it’s too big), but it’s a useful idea

  18. Search Trees This is now / start “N”, 1.0 “E”, 1.0 Possible futures ▪ A search tree: ▪ The start state is the root node ▪ Children correspond to successors ▪ Nodes show states, but correspond to PLANS that achieve those states ▪ For most problems, we can never actually build the whole tree , why? ▪ PLAN means a series of actions.

  19. Quiz: State Space Graphs vs. Search Trees State Space Graph Search Tree S G e p a d c b q b c e h r e d f h r p q f a a S h q c p q f G p r q a q c G a ▪ Each NODE in the search tree is an entire PATH in the state space graph.

  20. State Space Graphs vs. Search Trees Consider this 4-state graph: a G S How big is its search tree (from S)? b Important: Lots of repeated structure in the search tree!

  21. Tree Search

  22. Search Example: Romania

  23. Search Example G a c b e d f S h p r q

  24. Depth-First Search

  25. Depth-First Search G Strategy: expand a a a c c deepest node first b b e e Implementation: d d f f Fringe is a LIFO stack S h h p p r r q q S e p d q e h r b c h r p q f a a q c p q f G a q c G a

  26. Search Algorithm Properties ▪ Complete: Guaranteed to find a solution if one exists? ▪ Optimal: Guaranteed to find the least cost path? ▪ Time complexity? ▪ Space complexity? 1 node b b nodes … ▪ Cartoon of search tree: b 2 nodes ▪ b is the branching factor m ▪ m is the maximum depth ▪ s is the solutions at various depths b m nodes ▪ Number of nodes in entire tree? ▪ 1 + b + b 2 + …. b m = O(b m )

  27. Depth-First Search (DFS) Properties ▪ What nodes DFS expand (Time Complexity)? ▪ Some left prefix of the tree. ▪ If m is finite, takes time O(b m ) ▪ How much space does the fringe 1 node take (Space Complexity)? b … ▪ Only has siblings on path to root, so b nodes O(bm) b 2 nodes m tiers ▪ Is it complete? ▪ No, m can be infinite ▪ Is it optimal? b m nodes ▪ No, it finds the “leftmost” solution, regardless of depth or cost

  28. Breadth-First Search G a Strategy: expand a c b shallowest node first e Implementation: Fringe d f is a FIFO queue S h p r q S e p d Search q e h r b c Tiers h r p q f a a q c p q f G a q c G a

  29. Breadth-First Search (BFS) Properties ▪ What nodes does BFS expand (Time Complexity)? ▪ Processes all nodes above shallowest solution ▪ Let depth of shallowest solution be s ▪ Search takes time O(b s ) ▪ How much space does the fringe take? 1 node ▪ Has roughly the last tier, so O(b s ) b … b nodes s tiers b 2 nodes ▪ Is it complete? ▪ yes b s ▪ Is it optimal? ▪ Yes (if the cost is equal per step) b m

  30. DFS vs BFS ▪ When will BFS outperform DFS? ▪ The branch factor is relatively small. ▪ The depth of the optimal solution is relatively shallow. ▪ When will DFS outperform BFS? ▪ The tree is deep and the answer is deep and frequent. ▪ It has advantages according to computing complexity.

  31. Iterative Deepening ▪ Idea: get DFS’s space advantage with BFS’s time / shallow-solution advantages ▪ Run a DFS with depth limit 1. If no solution… ▪ Run a DFS with depth limit 2. If no solution… ▪ Run a DFS with depth limit 3. ….. ▪ How many nodes does BFS expand? ▪ O(b d ) ▪ How much space does the fringe take? ▪ O(bd) b … ▪ Is it complete? ▪ yes! d ▪ Is it optimal? ▪ Yes! (if the cost is equal per step)

  32. Cost-Sensitive Search GOAL a 2 2 c b 3 2 1 8 2 e d 3 f 9 8 2 START h 4 2 1 4 p r 15 q 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.

  33. Uniform Cost Search

  34. Uniform Cost Search 2 G a Strategy: expand a cheapest c b 8 1 node first: 2 2 e 3 d f Fringe is a priority queue 9 2 8 S h 1 (priority: cumulative cost) 1 p r q 15 0 S 1 9 e p 3 d q 16 11 5 17 4 e h r b c 11 Cost 7 6 13 h r p q f a a contours q c 8 p q f G Suppose a C* = 10 and  q c 11 10 G equals 3 a

  35. Uniform Cost Search (UCS) Properties ▪ What nodes does UCS expand? ▪ Processes all nodes with cost less than cheapest solution! ▪ If that solution costs C* and arcs cost at least  , then the “effective depth” is roughly C*/  ▪ Takes time O(b C*/  ) (exponential in effective depth) ▪ How much space does the fringe take? ▪ Has roughly the last tier, so O(b C*/  ) b c  1 … C*/  “tiers” ▪ Is it complete? c  2 ▪ Assuming best solution has a finite cost and c  3 minimum arc cost is positive, yes! ▪ Is it optimal? ▪ Yes!

  36. Uniform Cost Issues ▪ Remember: UCS explores increasing cost contours c  1 … c  2 c  3 ▪ The good: UCS is complete and optimal! ▪ The bad: ▪ Explores options in every “direction” ▪ No information about goal location Start Goal

  37. Comparison Algorithm Complete? Optimal? Time? Space? DFS N N O(b m ) O(bm) BFS Y Y O(b d ) O(b d ) O(b d ) IDS Y Y O(bd) O(b C*/  ) O(b C*/  ) UCS Y Y For BFS, Suppose the branching factor b is finite and step costs are identical;

  38. How bad is BFS?

  39. Data structure ▪ LIFO stack ▪ FIFO queue ▪ Priority queue

  40. Last in First out Stack

  41. FIFO queue

  42. Priority queue

  43. The One Queue ▪ All these search algorithms are the same except for fringe strategies ▪ Conceptually, all fringes are priority queues (i.e. collections of nodes with attached priorities) ▪ Can even code one implementation that takes a variable queuing object

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend