lecture 2: fun with search - drexel ccigreenie/cs510/cs510-18-02.pdf · lecture 2: fun with search...
TRANSCRIPT
![Page 1: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/1.jpg)
Lecture 2:
Fun with SearchRachel Greenstadt
Guest Lecturer: Edwin Dauber
CS 510, October 1, 2018
![Page 2: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/2.jpg)
Reminder!
• Project pre-proposals due next week
• No class next week
• Homework 1 Available
• Due next class (two weeks)
![Page 3: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/3.jpg)
Overview
• Uninformed search
• BFS, DFS, Uniform-Cost, Graph-
Search
• Informed search
• Heuristics, A*, admissibility,
consistency, memory-bounded A*
• Discussions
![Page 4: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/4.jpg)
Why search?
• Agents with several immediate options
of unknown value can choose actions
by:
• examining different sequences of
actions
• choosing the best sequence
• Examples?
![Page 5: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/5.jpg)
Tree Search
• Explore state space by
generating successors
of explored states
• Need
• Initial State
• Successor function
• Goal test
• Path cost
How to get from Arad to
Bucharest?
![Page 6: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/6.jpg)
Tree Search
• Initial State : In(Arad)
• Successor function
• <action, successor>
• (Go(Sibiu), In(Sibiu))
• Go( Timisoara), In(Timisoara)
• Go(Zerind), In(Zerind)
• Goal test: In(Bucharest)
• Path cost: sum of step costs (in km)
How to get from Arad to
Bucharest?
![Page 7: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/7.jpg)
Class Exercise
• You have three jugs: 12 gal, 8 gal, and 3 gal and a water faucet.
• You can fill the jugs up or pour them out from one into another or onto
the ground
• You need to measure out exactly one gal
• In groups, determine the following precisely enough to implement:
• Initial state
• Goal test
• Successor function
• Cost function
![Page 8: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/8.jpg)
Applications
![Page 9: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/9.jpg)
The Mother of All
Search Algorithms• current_state <= start_state
• loop:
• is current_state = goal_state? if yes, output
path and terminate
• generate all next states of current_state and
add to fringe set
• current_state <= choose from fringe set
![Page 10: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/10.jpg)
Complications• How to choose next state from fringe set?
• Answer has significant implications on:
• Time complexity• Number of loops
• Space complexity• Size of fringe set
• Completeness• Does loop terminate?
• Optimality• Quality of solution path
![Page 11: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/11.jpg)
Measuring complexity
• b: maximum branching factor (largest
number of next states of any state)
• d: steps to goal
• m: maximum possible path length
• not always finite
![Page 12: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/12.jpg)
Breadth-first search• Expand shallowest unexpanded node
• Implementation: FIFO queue is data
structure for fringe set
A
B
GFED
C
![Page 13: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/13.jpg)
Breadth-first search• Expand shallowest unexpanded node
• Implementation: FIFO queue is data
structure for fringe set
A
B
GFED
C
![Page 14: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/14.jpg)
Breadth-first search• Expand shallowest unexpanded node
• Implementation: FIFO queue is data
structure for fringe set
A
B
GFED
C
![Page 15: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/15.jpg)
Breadth-first search• Expand shallowest unexpanded node
• Implementation: FIFO queue is data
structure for fringe set
A
B
GFED
C
![Page 16: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/16.jpg)
Properties of BFS
• Complete?
• Optimal?
• Space?
• Size of fringe set? O(bd+1)
• Time?
![Page 17: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/17.jpg)
Depth-first search• Expand deepest unexpanded node
• Implementation: LIFO (stack) is data
structure for fringe setA
B
GFED
C
H I J K L M N O
![Page 18: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/18.jpg)
Depth-first search• Expand deepest unexpanded node
• Implementation: LIFO (stack) is data
structure for fringe setA
B
GFED
C
H I J K L M N O
![Page 19: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/19.jpg)
Depth-first search• Expand deepest unexpanded node
• Implementation: LIFO (stack) is data
structure for fringe setA
B
GFED
C
H I J K L M N O
![Page 20: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/20.jpg)
Depth-first search• Expand deepest unexpanded node
• Implementation: LIFO (stack) is data
structure for fringe setA
B
GFED
C
H I J K L M N O
![Page 21: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/21.jpg)
Depth-first search• Expand deepest unexpanded node
• Implementation: LIFO (stack) is data
structure for fringe setA
B
GFED
C
H I J K L M N O
![Page 22: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/22.jpg)
Depth-first search• Expand deepest unexpanded node
• Implementation: LIFO (stack) is data
structure for fringe setA
B
GFED
C
H I J K L M N O
D
![Page 23: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/23.jpg)
Depth-first search• Expand deepest unexpanded node
• Implementation: LIFO (stack) is data
structure for fringe setA
B
GFED
C
H I J K L M N O
D
![Page 24: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/24.jpg)
Depth-first search• Expand deepest unexpanded node
• Implementation: LIFO (stack) is data
structure for fringe setA
B
GFED
C
H I J K L M N O
D
J
![Page 25: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/25.jpg)
Depth-first search• Expand deepest unexpanded node
• Implementation: LIFO (stack) is data
structure for fringe setA
B
GFED
C
H I J K L M N O
B
D E
J
![Page 26: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/26.jpg)
Depth-first search• Expand deepest unexpanded node
• Implementation: LIFO (stack) is data
structure for fringe setA
B
GFED
C
H I J K L M N OJ
ED
B
![Page 27: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/27.jpg)
Properties of DFS
• Space?
• bm+1
• Time?
• Optimal?
• Complete?
• No. Why?
![Page 28: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/28.jpg)
Properties of DFS
• Complete?
• Spaces with loops
• Modify to avoid repeated states along path
• Infinite-depth spaces
• What if we cut off after depth limit L
• Depth-Limited DFS
![Page 29: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/29.jpg)
Guaranteeing
Completeness
• Idea: Invoke Depth-Limited DFS with
iteratively increasing values of L
• This is called Iterative Deepening
Search
![Page 30: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/30.jpg)
Iterative Deepening
L=0
![Page 31: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/31.jpg)
Iterative Deepening
L=1
![Page 32: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/32.jpg)
Iterative Deepening
L=2
![Page 33: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/33.jpg)
Iterative Deepening
L=3
Etc.
![Page 34: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/34.jpg)
Iterative Deepening
Search--how efficient?• Re-expanding all those nodes seems bad
• # of nodes in depth-limited search L=d
• N = b0 + b1+b2+...+bd-2+bd-1+bd
• # of nodes in iterated deepening search to L=d
• N = (d+1)b0 + db1+(d-1)b2+...+3bd-2+2bd-1+bd
• For b=10, d=5
• N= 1+10+100+1,000+10,000+100,000=111,111
• N=6+50+400+3,000+20,000+100,000=123,456
• Overhead = (123,456-111,111)/111,111=12,345/111,111=11.11%
![Page 35: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/35.jpg)
Bi-directional Search
• Search gets less efficient with depth
• Minimize depth by doing two searches
• Forward from the Start State
• Backward from the Goal
• Catch: sometimes it’s hard to go
backward from the goal
![Page 36: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/36.jpg)
What if not all paths
are equal?
![Page 37: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/37.jpg)
Uniform-cost search• Expand least-cost unexpanded node
• Implementation: fringe is priority queue
ordered by path cost
• Same as breath first search if all steps equal
A
B
GFED
C
0
1
4
3
34
![Page 38: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/38.jpg)
Uniform-cost search• Expand least-cost unexpanded node
• Implementation: fringe is priority queue
ordered by path cost
• Same as breath first search if all steps equal
B
GFED
C
0
1
4
3
34
A
![Page 39: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/39.jpg)
Uniform-cost search• Expand least-cost unexpanded node
• Implementation: fringe is priority queue
ordered by path cost
• Same as breath first search if all steps equal
B
GFED
C
0
1
4
3
34
A
![Page 40: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/40.jpg)
Uniform-cost search• Expand least-cost unexpanded node
• Implementation: fringe is priority queue
ordered by path cost
• Same as breath first search if all steps equal
B
GFED
C
0
1
4
3
34
A
![Page 41: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/41.jpg)
Notation: g(n)• g(n) : cost of path from start to node n
• Fringe is priority queue ordered by g(n)
• Goal test when expanded rather than
generated (avoid suboptimal path)
B
GFED
C
0
1
4
3
34
A
g=1 g=3
g=3g=4 g=5 g=7
![Page 42: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/42.jpg)
Uniform-cost Search
• Complete? If step cost >= Epsilon
• Time and Space?
• Cost of Optimal Soln = C*
• Cost = O(b1+floor(C*/E))
![Page 43: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/43.jpg)
Graph Search
• Remove repeated states
![Page 44: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/44.jpg)
Summary of
algorithms
Note: should be floor not ceiling in Uniform-Cost search
![Page 45: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/45.jpg)
What about
complexity?
![Page 46: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/46.jpg)
What about
complexity?
Or, hey these AI algorithms don’t seem so smart!
![Page 47: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/47.jpg)
Heuristics
• NP-Complete problems: impossible to
guarantee optimality and sub-
exponential run-time
• A heuristic algorithm gives up one or
both
• Gives good average run-time or “good”
(but not guaranteed optimal) solutions
![Page 48: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/48.jpg)
Heuristic in Search
• Heuristic: a “rule of thumb”
• Formally: function that maps a state onto an estimate of the cost to the
goal from that state
• Define h(n) = estimated cost of path from node n to goal
• if n is goal then h(n)=0.h(a)=10
S b
a
n’
c
G
g(n’)
h(c)=7
h(b)=18 h(G)=0
![Page 49: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/49.jpg)
Using Heuristics in
Informed Search
• Assume h(n) is given. How can we use it to do search?
• Data structure for the fringe set?
h(a)=10
S b
a
n’
c
G
g(n’)
h(c)=7
h(b)=18 h(G)=0
![Page 50: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/50.jpg)
Greedy Best-First
Search• Priority queue using h(n)
• Pick the node closest to the goal
• Example fringe (b,18) (a,10) (c,7)h(a)=10
S b
a
n’
c
G
g(n’)
h(c)=7
h(b)=18 h(G)=0
![Page 51: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/51.jpg)
When Greedy Search Goes Bad
• Expand successors of n’
• Fringe set [(b,h(b)=3), (a, h(a)=1)]
• Expand successors of a
• Fringe set [(b, h(b)=3), (G,h(G)=0)]
• Expand G...found goal...solution path: S...n’->a->G
• cost = g(n’)+100+1
• Not optimal, g(n’) + 4 exists
h(a)=1
S b
a
n’ G
g(n’)
h(b)=3
h(G)=0
ef
h(f)=1h(e)=2
100
1 111
1
![Page 52: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/52.jpg)
How to fix?
• So we have
• g(n) : Cost from start to n
• uniform-cost search
• h(n) : Estimated cost from n to goal
• greedy best-first search
• Ideas?
![Page 53: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/53.jpg)
A* Search
• Take into account total path cost
• Fringe set as a priority queue ordered by f(n) = g(n) + h(n)
• f(b) = ?
• f(a) = ?
• A* is really important
h(a)=1
S b
a
n’ G
g(n’) = 10
h(b)=3
h(G)=0
ef
h(f)=1h(e)=2
100
1 111
1
![Page 54: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/54.jpg)
A* Search Example
• In state n’
• Two successors, a and b
• f(a) = g(a) + h(a) = 10 + 100 + 1 = 111
• f(b) = g(b) + h(b) = 10 + 1 + 3 = 14
• Fringe set ={(b,14), (a,111)}
• Choose to expand b
• Next fringe = {(f,14),(a,111)}
h(a)=1
S b
a
n’ G
g(n’) = 10
h(b)=3
h(G)=0
ef
h(f)=1h(e)=2
100
1 111
1
![Page 55: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/55.jpg)
Is A* Guaranteed Optimal?
• Nope, see h(b)
• A* will return S...n’-> a -> G
• Heuristics can be wrong
h(a)=1
S b
a
n’ G
g(n’) = 10
h(b)=200
h(G)=0
ef
h(f)=1h(e)=2
100
1 111
1
![Page 56: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/56.jpg)
“Good” Heuristics : Admissibility
• Let h*(n) be the real cost of cheapest path from n to goal
• Definition: h(n) is admissible iff
• for all n, h(n) is less than or equal h*(n)
• Is h(n’) = 99 admissible?
• Is h(n’) = 4 admissible?
• Is h(b) = 4 admissible?
• Is h(b) = 0 admissible?
• Straight line distance on a map?
h(a)=1
S b
a
n’ G
g(n’) = 10
h(b)=200
h(G)=0
ef
h(f)=1h(e)=2
100
1 111
1
![Page 57: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/57.jpg)
Theorem: If h(n) is admissible, A* is
optimal (if no repeated states)
• Suppose G2 is suboptimal and path (S...n’...G2) is returned by A*
• Let n be the first unexpanded node in the optimal path to G1
• In A*, the only way G2 is expanded before n is if f(n) > f(G2)
• This is how priority queues work
• Assume f(n) > f(G2) : This is a contradiction, why?
S
n
n’ G2
G1
Optimal Soln
![Page 58: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/58.jpg)
Proof:• f(n) > f(G2)
• f(G2) = g(G2) + h(G2)
• f(G2) = g(G2)
• f(G2) > g(G1)
• f(G2) > g(n) + h*(n)
• f(G2) > g(n) + h(n)
• f(G2) > f(n) (Contradiction)
• Assumption
• def of f
• def of h (G2 is a goal
state)
• G2 is suboptimal
• n is on opt path to G1
• h is admissible
• def of f
![Page 59: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/59.jpg)
When Admissibility Fails
• Is h admissible?
h(a)=5
S b
a
n G
g(n’) = 10
h(b)=1
h(G)=0
4
h(n)=7
2
4
1
![Page 60: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/60.jpg)
When Admissibility Fails
• Expand node n:
• f(a) = 12 + 5 = 17
• f(b) = 14 + 1 = 15
• Fringe set {(a,17), (b,15)}
• Expand b:
• f(G) = 14+4 = 18
• Fringe set {(G,18),(a,17)}
• Expand a : Ignore b since b already visited
• Expand G : test for goal, done. But suboptimal
h(a)=5
S b
a
n G
g(n’) = 10
h(b)=1
h(G)=0
4
h(n)=7
2
4
1
![Page 61: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/61.jpg)
Still not optimal using
Graph-Search
• Graph-Search avoids repeated states by
ignoring previously seen states
• What if the second path to the state is optimal?
• Graph-Search discards it
• This is why the proof breaks down if repeated states
• Need yet another requirement...
![Page 62: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/62.jpg)
Consistency
• What is wrong with h?
h(a)=5
S b
a
n G
g(n’) = 10
h(b)=1
h(G)=0
4
h(n)=7
2
4
1
![Page 63: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/63.jpg)
Consistency
• Require that
• h(a) <= h(b) + cost(a,b)
• Make the heuristic obey the triangle inequality
h(a)=5
S b
a
n G
g(n’) = 10
h(b)=1
h(G)=0
4
h(n)=7
2
4
1
![Page 64: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/64.jpg)
Consistent Heuristics
• A heuristic is consistent if
• For every node n
• And every successor n’ of n
• Generated by any action a
• cost(n,a,n’) + h(n’) >= h(n)
![Page 65: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/65.jpg)
Consistent heuristics
• If h is consistent, f(n) is non-
decreasing along any path
• f(n’) = g(n’) + h(n’)
• = g(n) + c(n,a,n’) + h(n’)
• >= g(n) + h(n)
• f(n’) >= f(n)
c(n,a,n’)
h(n’)
h(n)
n’G
n
![Page 66: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/66.jpg)
Consistent Implies
Admissible• Thm: h(n) <= h*(n) for all n
• Proof by induction:
• Base case: h*(n) = 0 ; n is a goal state so h(n) = 0 by definition
• Inductive hypothesis: For all n’ after n on shortest path to Goal
• Assume h(n’) <= h*(n’)
• Lemma: h(n) <= h*(n)
• h(n) <= c(n,n’) + h(n’) by consistency
• <= c(n,n’) + h*(n’) by inductive hypothesis
• h(n) <= h*(n) by definition
![Page 67: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/67.jpg)
Properties of A*
• Complete: yes (unless infinite nodes
where f<=f(G) )
• Time: exponential
• Space: All nodes in memory
• Optimal: Yes (if using consistent
heuristic and Graph-Search)
![Page 68: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/68.jpg)
Time: find a good
admissible heuristic
• What kind of heuristics?
![Page 69: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/69.jpg)
Time: find a good
admissible heuristic
• h1(n) = # of misplaced tiles
• h2(n) = manhattan distance to goal (total number of squares from goal
state)
• h1(S) = 8
• h2(S) = 3+1+2+2+2+3+3+2=18
![Page 70: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/70.jpg)
Dominance
• if h2(n) >= h1(n) for all n (both admissible)
• then h2 dominates h1
• h2 is better for search
• Average search costs
IDS A*(h1) A*(h2)
8-puzzle 6384 39 25
12-puzzle 3644035 227 73
24-puzzle too big 39135 1641
![Page 71: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/71.jpg)
Complexity
• So time might be manageable with
good heuristics, but space?
• Memory-bounded A*
![Page 72: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/72.jpg)
Simplified Memory-
Bounded A*• Use all available memory
• Expand best leaves until you can’t
• Remove worst leaf (highest f-value)
• Solve ties by expanding newest best
leaf and removing oldest worst leaf
• Complete if soln reachable, optimal if
optimal soln reachable
![Page 73: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/73.jpg)
Iterative Deepening
A* (IDA*)
• Use iterative deepening to
progressively expand the memory
usage based on f-cost
• Runs into the same problems as
Uniform-Cost if paths/heuristics are
real-valued
![Page 74: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/74.jpg)
Recursive Best First
Search (RBFS)
• Keep track of the best alternative path
(f-limit)
• When current f-values exceed f-limit
• Backtrack and
• Store best f-value of children at
backtracked nodes
![Page 75: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/75.jpg)
Readings this week:
• Lawrence Page, Sergey Brin, Rajeev Motwani, Terry Winograd, The
PageRank Citation Ranking: Bringing Order to the Web, Stanford
University, SIDL-WP-1999-0120, November 1999.
• Katia Sycara. Multiagent Systems. AAAI Magazine, 1999
• Remember: Discussion points by Friday at 6 pm, online replies by
Monday at 3 pm.
![Page 76: Lecture 2: Fun with Search - Drexel CCIgreenie/cs510/cs510-18-02.pdf · Lecture 2: Fun with Search Rachel Greenstadt Guest Lecturer: Edwin Dauber CS 510, October 1, 2018. ... You](https://reader033.vdocuments.site/reader033/viewer/2022050405/5f82384dc741805a970df9a9/html5/thumbnails/76.jpg)
Reminder!
• Project pre-proposals due next week
• No class next week
• Homework 1 Available
• Due next class (two weeks)
• Need BFS, DFS, Iterative Deepening
• A* is extra credit