Computer Science CPSC 322
Le Lecture ture 5 Le Leas ast t Co Cost st an and d In Info form rmed ed Se Search arch
(Ch: h: 3.6 .6, , 3.6 .6.1) .1)
1
Le Lecture ture 5 Le Leas ast t Co Cost st an and d In - - PowerPoint PPT Presentation
Computer Science CPSC 322 Le Lecture ture 5 Le Leas ast t Co Cost st an and d In Info form rmed ed Se Search arch (Ch: h: 3.6 .6, , 3.6 .6.1) .1) 1 Announcements nouncements Assignment 1 posted today Due Tuesday
Computer Science CPSC 322
(Ch: h: 3.6 .6, , 3.6 .6.1) .1)
1
Announcements nouncements
efully read and follow w the instructions on cover sheet
“Graph Searching exercises” available at http://www.aispace.org/exercises.shtml
hard to solve them!
2
Lecture cture Ov Overvie rview
3
Search Strategies are different with respect to how they:
4
5
C.
/remo emove ve paths s from
ntier ier
Search Strategies are different with respect to how they:
6
DFS FS
Depth-First Search, DFS
goal is found) before considering any other path.
7
Breadth eadth-first first search arch (BFS) FS)
before looking at path of length l + 1
8
DFS FS vs. . BFS FS
How can we achieve an acceptable (linear) space complexity while maintaining completeness and optimality? Key Idea: re-compute elements of the frontier rather than saving them. Complete Optimal Time Space DFS NO NO O(bm) O(bm) BFS YES YES O(bm) O(bm) ????? ????? YES YES O(bm) O(bm)
9
depth = 1 depth = 2 depth = 3
Iterative Deepening DFS (IDS) in a Nutshell
– For depth D, ignore any paths with longer length – Depth-bounded depth-first search
If no goal l re-star art t from scratc atch h and get to depth h 2 If no goal l re-star art t from scratc atch h and d get to depth th 3 If no goal l re-star art t from scratc atch h and d get to depth th 4
10
An Analys ysis is of Iter erativ ative e Deepen enin ing g DFS FS (IDS) S)
with limited overhead compared to BSF
11
DFS FS vs. . BFS FS
But what if we have costs associated with search actions (arcs in the search space? Complete Optimal Time Space DFS NO NO O(bm) O(bm) BFS YES YES O(bm) O(bm) IDS YES YES O(bm) O(bm)
12
Lecture cture Ov Overvie rview
13
In this setting we usually want to find the solution that minimizes cost
) , cost( , , cost
1 1
k i i i k
n n n n
Def.: The cost of a path is the sum
Def.: A search algorithm is optimal if when it finds a solution, it is the best one: it has the lowest path cost
Slide 14
cost to a goal node
the frontier.
path cost.
Lowest west-Cost Cost-First First Search rch (LCFS) CFS)
Let’s see how this works in AIspace: in the Search Applet toolbar
15
est-cost cost-firs rst search arch finds the path with the lowest cost to a goal node
Lowest-Cost-First Search (LCFS)
16
18
19
20
Analysi alysis s of f Lowest west-Cost Cost Search arch (1)
negative arc costs could be followed forever. see how this works in AIspace:
Search Tree
*If costs along an infinite path can become infinitively small, their sum can be
finite (e.g. series σ𝑗=1
∞ 1 2𝑗 < 1) and the path can trap LCFS
than a given constant ε*
21
Analysi alysis s of f Lowest west-Cost Cost Search arch (1)
negative arc costs could be followed forever. see how this works in AIspace:
Search Tree
*If costs along an infinite path can become infinitively small, their sum can be
finite (e.g. series σ𝑗=1
∞ 1 2𝑗 < 1) and the path can trap LCFS
than a given constant ε*
22
23
Analysi alysis s of f Lowest west-Cost Cost Search arch (1)
negative arc costs could be followed forever.
greater than a given constant ε *
looks high-cost could end up getting a ``refund''.
is optimal if arc costs are guaranteed to be ≥ 0
see how this works in AIspace:
*If costs along an infinite path can become infinitively small, their sum can be
finite (e.g. series σ𝑗=1
∞ 1 2𝑗 < 1)
24
Analysi alysis s of f Lowest west-Cost Cost Search arch
and the maximum branching factor is b
because it generates all paths from the start that cost less than the cost of the solution
25
Analysi alysis s of f Lowest west-Cost Cost Search arch
has to store all nodes that are m-1 steps away from the start node
26
Summary mary of f Uninformed informed Search arch
Complete Optimal Time Space DFS N N O(bm) O(mb) BFS Y Y (shortest) O(bm) O(bm) IDS Y Y (shortest) O(bm) O(mb) LCFS Y Costs > ε > Y (Least Cost) Costs >=0 O(bm) O(bm)
Slide 27
Su Summary y of Uninfo nforme med d Se Search h (cont. nt.)
called uninformed?
states and the goals to decide which path to expand first
account the specific nature of the problem.
Slide 28
Lecture cture Ov Overvie rview
29
account the goal until they are at a goal node.
used to guide the search:
goal node.
30
Def.: A search heuristic h(n) is an estimate of the cost of the
Estimate: h(n1) Estimate: h(n2) Estimate: h(n3) n3 n2 n1
(easy to compute) about a node.
Slide 31
Example: mple: fi finding ing routes utes
32
Example: mple: fi finding ing routes utes
(Euclidian) distance between source and goal node
33
Example mple 2
Search problem: robot has to find a route from start to goal location on a grid with obstacles Actions: move up, down, left, right from tile to tile Cost : number of moves Possible h(n)?
1 2 3 4 5 6
G
4 3 2 1
S
Slide 34
Example mple 2
Search problem: robot has to find a route from start to goal location on a grid with obstacles Actions: move up, down, left, right from tile to tile Cost : number of moves Possible h(n)? Manhattan distance (L1 distance) between two points (x1, y1), (x2, y2):
|x2 – x1| + |y2 - y1|
1 2 3 4 5 6
G
4 3 2 1
Slide 35
Lecture cture Ov Overvie rview
36
smallest h value.
h.
closest to the goal - chose the solution that is locally the best.
Let’s see how this works in AIspace: in the Search Applet toolbar
37
Anal alysi ysis s of f BestFS tFS
39
Anal alysi ysis s of f BestFS tFS
example in AISPACE
40
Anal alysi ysis s of f BestFS tFS
41
Anal alysi ysis s of f BestFS tFS
from schedule page (save it and then load using “load from file” option)
42
related partial paths on the frontier
fast.
with C1 linked to o123 (cost 3.0)
Anal alysi ysis s of f BestFS tFS
43
goal can speed things up a lot
First Search)
account allows LCSF to find the optimal solution
distance to the goal goes.
What’s Next?
44
How can we more effec fective tively ly use h(p) ) and cost st(p (p)? )? Shall we select from the frontier the path p with:
cost(p) – h(p)
45
46
How can we more effec fective tively ly use h(p) ) and cost st(p (p)? )? Shall we select from the frontier the path p with:
cost(p) – h(p)
47
Lecture cture Ov Overvie rview
48
node n at the end of p)
goal via p.
A* Search arch
c(p) h(p)
f(p)
A* always chooses the path on the frontier with the lowest estimated distance from the start to a goal node constrained to go via that path.
49
f value of ubc kd jb? A.6 C.10
Compu mputing ting f-valu alues es
50
51
f value of ubc kd jb? C.10
Computing mputing f-vale aleues ues
52
53
Compare A* and LCFS on the Vancouver graph
goal via p.
A* Search arch
c(p) h(p)
f(p)
A* always chooses the path on the frontier with the lowest estimated distance from the start to a goal node constrained to go via that path.
54
A* is complete (finds a solution, if one exists) and optimal (finds the optimal path to a goal) if
The book also mentions explicitly that the branching factor b has to be finite, which we have been assuming by default (without this condition even BFS would not be complete)
Op Opti timal mality ity of f A*
55
Admissibi issibility lity of f a he heuristi uristic
Def.: Let c(n) denote the cost of the optimal path from node n to any goal node. A search heuristic h(n) is called admissible if h(n) ≤ c(n) for all nodes n, i.e. if for all nodes it is an underestimate of the cost to any goal.
straight-line distance (SLD) admissible?
56
Admissibi issibility lity of f a he heuristi uristic
Def.: Let c(n) denote the cost of the optimal path from node n to any goal node. A search heuristic h(n) is called admissible if h(n) ≤ c(n) for all nodes n, i.e. if for all nodes it is an underestimate of the cost to any goal.
straight-line distance admissible?
distance between two points is a line. YES YES
57
Admissibi issibility lity of f a he heuristi uristic
Def.: Let c(n) denote the cost of the optimal path from node n to any goal node. A search heuristic h(n) is called admissible if h(n) ≤ c(n) for all nodes n, i.e. if for all nodes it is an underestimate of the cost to any goal.
exampl ple: :
the goal is Urzizeni (red box), but all we know is the straight-line distances (sld) to Bucharest (green box)
58
59
Admissibi issibility lity of f a he heuristi uristic
Def.: Let c(n) denote the cost of the optimal path from node n to any goal node. A search heuristic h(n) is called admissible if h(n) ≤ c(n) for all nodes n, i.e. if for all nodes it is an underestimate of the cost to any goal. exampl ple:
the goal is Urzizeni (red box), but all we know is the straight-line distances to Bucharest (green box)
NO NO
stul ul to Urz rzineni ineni is shorter than this estimate
60
Example mple 2
a grid with obstacles
(x1, y1), (x2, y2):
|x2 – x1| + |y2 - y1| ADMISSIBLE? 1 2 3 4 5 6
G
4 3 2 1
Slide 61
Example mple 2
a grid with obstacles
(x1, y1), (x2, y2):
|x2 – x1| + |y2 - y1| ADMISSIBLE? 1 2 3 4 5 6
G
4 3 2 1
the shortest path between any two tiles of the grid given the actions available and no walls. Including the walls will force the agent to take some extra steps to avoid them
Slide 62
Heuri uristic stic Function ction fo for 8-puzzle puzzle
An admissible heuristics for the 8-puzzle is?
tiles
63
64
Number of Misplaced Tiles: One needs at least that many moves to get the board in the goal state A and C clearly generate overestimates (e.g. when all tiles are in the correct position with respect to the goal above, except for 4 which is in the center)
Slide 65
Sum of number of moves between each tile's current position and its goal position (we can move over other tiles in the grid) Sum ( 1 2 3 4 5 6 7 8
Slide 66
Sum of number of moves between each tile's current position and its goal position
sum ( 2 3 3 2 4 2 0 2) = 18
Admissible?
1 2 3 4 5 6 7 8
Slide 67
tiles can move everywhere and occupy same spot as others
tiles can ………………………..
Why does this lead to an admissible heuristic?
68
How w to to Construct nstruct a He Heuri uristic stic (cont
.)
the problem easy to solve
hard to solve as the original problem!
This was the case in our examples
Robot: allowing the agent to move through walls. Optimal solution to this relaxed problem is Manhattan distance Driver: allowing the agent to move straight. Optimal solution to this relaxed problem is straight-line distance 8puzzle: tiles can move anywhere. Optimal solution to this relaxed problem is number of misplaced tiles
69
Apply basic properties of search algorithms:
Complete Optimal Time Space DFS N (Y if no cycles) N O(bm) O(mb) BFS Y Y O(bm) O(bm) IDS Y Y O(bm) O(mb) LCFS (when arc costs available) Y Costs > ε Y Costs >=0 O(bm) O(bm) Best First (when h available)
Le Lear arni ning ng Goa
for r Sea earch ch
70
Apply basic properties of search algorithms:
Complete Optimal Time Space DFS N (Y if no cycles) N O(bm) O(mb) BFS Y Y O(bm) O(bm) IDS Y Y O(bm) O(mb) LCFS (when arc costs available) Y Costs > ε Y Costs >=0 O(bm) O(bm) Best First (when h available) N N O(bm) O(bm)
Le Lear arni ning ng Goa
for r Sea earch ch
71
problems.
irst t Sear arch ch
Constr truct uct heuristi istic functio ctions s and disc iscuss s their ir admissib issibil ilit ity for r specifi ific search ch problem lems s
Learning Goals for Search (up to today)
72
many of the questions
73