Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 188: Artificial Intelligence Fall 2008

Similar presentations


Presentation on theme: "CS 188: Artificial Intelligence Fall 2008"— Presentation transcript:

1 CS 188: Artificial Intelligence Fall 2008
Lecture 2: Queue-Based Search 9/2/2008 Dan Klein – UC Berkeley Many slides from either Stuart Russell or Andrew Moore

2 Announcements Written assignments:
One mini-homework each week (1-2 problems) We’ll drop your two lowest scores First one posted soon! Lab Wednesday 11am to 4pm in Soda 275 Learn Python Come whatever times you like Project 1.1 posted soon, too, due 9/12

3 Today Agents that Plan Ahead Search Problems Uniformed Search Methods
Depth-First Search Breadth-First Search Uniform-Cost Search Heuristic Search Methods Greedy Search A* Search

4 Reflex Agents Reflex agents: Can a reflex agent be rational?
Choose action based on current percept and memory May have memory or a model of the world’s current state Do not consider the future consequences of their actions Can a reflex agent be rational? [demo: reflex optimal / loop ]

5 Goal Based Agents Goal-based agents: Plan ahead
Decisions based on (hypothesized) consequences of actions Must have a model of how the world evolves in response to actions [demo: plan fast / slow ]

6 Search Problems A search problem consists of:
A state space A successor function A start state and a goal test A solution is a sequence of actions (a plan) which transforms the start state to a goal state “N”, 1.0 “E”, 1.0

7 Search Trees A search tree:
“N”, 1.0 “E”, 1.0 A search tree: This is a “what if” tree of plans and outcomes Start state at the root node Children correspond to successors Nodes labeled with states, correspond to PLANS to those states For most problems, can never actually build the whole tree So, have to find ways of using only the important parts of the tree!

8 Laughably tiny search graph for a tiny search problem
State Space Graphs There’s some big graph in which Each state is a node Each successor is an outgoing arc Important: For most problems we could never actually build this graph How many states in Pacman? S G d b p q c e h a f r Laughably tiny search graph for a tiny search problem

9 Example: Romania

10 Another Search Tree Search: Expand out possible plans
Maintain a fringe of unexpanded plans Try to expand as few tree nodes as possible

11 Detailed pseudocode is in the book!
General Tree Search Important ideas: Fringe Expansion Exploration strategy Main question: which fringe nodes to explore? Detailed pseudocode is in the book!

12 Example: Tree Search S G d b p q c e h a f r

13 State Graphs vs Search Trees
d b p q c e h a f r Each NODE in in the search tree is an entire PATH in the problem graph. S a b d p c e h f r q G We almost always construct both on demand – and we construct as little as possible.

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

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

16 Search Algorithm Properties
Complete? Guaranteed to find a solution if one exists? Optimal? Guaranteed to find the least cost path? Time complexity? Space complexity? Variables: n Number of states in the problem b The average branching factor B (the average number of successors) C* Cost of least cost solution s Depth of the shallowest solution m Max depth of the search tree

17 DFS Infinite paths make DFS incomplete… How can we fix this? O(BLMAX)
Algorithm Complete Optimal Time Space DFS Depth First Search N O(BLMAX) O(LMAX) N N Infinite Infinite b START a GOAL Infinite paths make DFS incomplete… How can we fix this?

18 DFS With cycle checking, DFS is complete. When is DFS optimal?
1 node b b nodes b2 nodes m tiers bm nodes Algorithm Complete Optimal Time Space DFS w/ Path Checking Y N O(bm+1) O(bm)

19 BFS Algorithm Complete Optimal Time Space DFS BFS When is BFS optimal?
w/ Path Checking BFS When is BFS optimal? Y N O(bm+1) O(bm) Y N* O(bs+1) O(bs) 1 node b b nodes s tiers b2 nodes bs nodes bm nodes

20 Comparisons When will BFS outperform DFS?
When will DFS outperform BFS?

21 Iterative Deepening Algorithm Complete Optimal Time Space DFS BFS ID Y
Iterative deepening uses DFS as a subroutine: Do a DFS which only searches for paths of length 1 or less. (DFS gives up on any path of length 2) If “1” failed, do a DFS which only searches paths of length 2 or less. If “2” failed, do a DFS which only searches paths of length 3 or less. ….and so on. b Algorithm Complete Optimal Time Space DFS w/ Path Checking BFS ID Y N O(bm+1) O(bm) Y N* O(bs+1) O(bs) Y N* O(bs+1) O(bs)

22 Costs on Actions START GOAL d b p q c e h a f r 2 9 8 1 3 4 15 Notice that BFS finds the shortest path in terms of number of transitions. It does not find the least-cost path. We will quickly cover an algorithm which does find the least-cost path.

23 Uniform Cost Search S G 2 Expand cheapest node first:
b p q c e h a f r 2 Expand cheapest node first: Fringe is a priority queue 1 8 2 2 3 9 1 8 1 1 15 S a b d p c e h f r q G 9 1 3 4 5 17 11 16 11 Cost contours 6 13 7 8 11 10

24 Priority Queue Refresher
A priority queue is a data structure in which you can insert and retrieve (key, value) pairs with the following operations: You can promote or demote keys by resetting their priorities Unlike a regular queue, insertions into a priority queue are not constant time, usually O(log n) We’ll need priority queues for most cost-sensitive search methods. pq.push(key, value) inserts (key, value) into the queue. pq.pop() returns the key with the lowest value, and removes it from the queue.

25 Uniform Cost Search Algorithm Complete Optimal Time Space DFS BFS UCS
w/ Path Checking BFS UCS Y N O(bm+1) O(bm) Y N O(bs+1) O(bs) Y* Y O(C* bC*/) O(bC*/) C*/ tiers b We’ll talk more about uniform cost search’s failure cases later…

26 Uniform Cost Problems Remember: explores increasing cost contours
The good: UCS is complete and optimal! The bad: Explores options in every “direction” No information about goal location c  1 c  2 c  3 Start Goal [demo: ucs contours ]

27 Heuristics

28 Best First / Greedy Search
Expand the node that seems closest… What can go wrong?

29 Best First / Greedy Search
START GOAL d b p q c e h a f r 2 9 8 1 3 5 4 15 h=0 h=8 h=5 h=4 h=11 h=8 h=4 h=6 h=12 h=11 h=6 h=9

30 Best First / Greedy Search
A common case: Best-first takes you straight to the (wrong) goal Worst-case: like a badly-guided DFS in the worst case Can explore everything Can get stuck in loops if no cycle checking Like DFS in completeness (finite states w/ cycle checking) b b

31 Search Gone Wrong?

32 Extra Work? Failure to detect repeated states can cause exponentially more work. Why?

33 Graph Search In BFS, for example, we shouldn’t bother expanding the circled nodes (why?) S a b d p c e h f r q G

34 Graph Search Very simple fix: never expand a state type twice
Can this wreck completeness? Why or why not? How about optimality? Why or why not?

35 Some Hints Graph search is almost always better than tree search (when not?) Fringes are sometimes called “closed lists” – but don’t implement them with lists (use sets)! Nodes are conceptually paths, but better to represent with a state, cost, and reference to parent node


Download ppt "CS 188: Artificial Intelligence Fall 2008"

Similar presentations


Ads by Google