25
1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupar t CSC384: Lecture 10 Last time A* Today complete A*, iterative deepening Announcements: Assignment Solution will be posted later on today. This Friday’s office hours will be moved to Thursday 10:00-12:00 Pratt 398 (my office).

1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10 Last time A* Today complete A*, iterative deepening Announcements:

Embed Size (px)

DESCRIPTION

3 CSC 384 Lecture Slides (c) , C. Boutilier and P. Poupart Properties of A* Recap—Optimality  Will A* always find cheapest path?  If h(n) does not underestimate the true cost of getting to the goal then A* won’t always find the cheapest path.

Citation preview

Page 1: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

1CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

CSC384: Lecture 10Last time

• A* Today

• complete A*, iterative deepeningAnnouncements:

• Assignment Solution will be posted later on today.• This Friday’s office hours will be moved to Thursday 10:00-

12:00 Pratt 398 (my office).

Page 2: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

2CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Midterm. Will cover all material up to the end of Iterative

deepening (which we will finish today or perhaps next time).1. DCL, semantics, interpretations, no questions on

counting number of interpretations!2. Top down, bottom up proofs.3. Search, DFD, BrFS, LCFS, A*, ID search

Page 3: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

3CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Properties of A* Recap—Optimality

Will A* always find cheapest path?If h(n) does not underestimate the true cost of getting to the goal then A* won’t always find the cheapest path.

Page 4: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

4CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Paths Explored by A*: mo to slbmo

alls

ws

ch2 5

2

12/2

3/5

3/4

1/6

Red paths: expanded; h-value/f-valueBlack paths: added to frontier, but not expanded

sec

2ls

1eif

1

0/8

slb rp1

1

1ase bp nyse31

Prune using MPC(to keep slide simple)

Goal

2/4

Page 5: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

5CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Paths Explored by A*: mo to slbmo

alls

ws

ch2 5

2

12/2

17/5

3/4

2/4

1/6

Red paths: expanded; h-value/f-valueBlack paths: added to frontier, but not expanded

sec

ls

eif

0/10

slb rp1

1

1ase bp nyse31

GoalCheapestGoal

2

Page 6: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

6CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Admissible HeuristicsIf h(n) never overestimates the true cost-to-goal from n

(h(n) ≤ mincost(n,g)) then h is called admissible and the following holds.

• A* will find least-cost path (assuming arcs costs > 0)Special case: let h(n) = 0 for all n

• since f(n) = h(n) + g(n) = g(n): reduces to LCFS• an admissible, but uninformative heuristic

In general, the more “informative” h(n) is, the better A* will perform (more “direct” search)

• Exercise: Prove that if h(n) = mincost(n,g) – that is, h(n) is perfect – A* can find optimal path directly (no backtracking). However we must be careful that we don’t alternate between a large number of distinct optimal paths.

Page 7: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

7CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Optimality of A* (Proof)Let h be admissible, and let their exist a path to the goal. Then A* terminates only when it expands a goal node to which it has found an optimal path.

• First, at any time prior to A* terminating the frontier contains a prefix of an optimal path s=n0,n1,…,n* (a goal node): s=n0,n1,…nk

At the start s=n0 is on the frontier (k=0)If at some stage n0,n1,…nk is on the frontier, then at the next step either nk was not expanded, in which case this path is still on the frontier, or nk was expanded in which case one of nk’s neighbors must be nk+1. That is, now the prefix s=n0,n1,…nk,nk+1 is on the frontier.

Page 8: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

8CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Optimality of A* (Proof)Second, for any node ni on this optimal path we must have f(ni) ≤ cost of an optimal solution.

f(ni) = g(ni) + h(ni).

• g(ni) = optimal cost of getting to ni since the path n0,…,ni-1,ni must be an optimal path to ni (it is a prefix of an optimal path to the goal).

• h(ni) ≤ cost of getting to the goal from ni.

Page 9: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

9CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Optimality of A* (Proof)Hence any node expanded by A* must have f-value ≤ cost of an optimal solution, else A* would have chosen nk instead!

• Thus when A* terminates by expanding a goal node, ng it must be the case that f(ng) ≤ cost of an optimal solution. But since f(ng) = g(ng) + h(ng) = g(ng) + 0, and g(ng) is the cost of a solution (the one to ng), we must have f(ng) = g(ng) ≤ cost of an optimal solution.

That is, g(ng) = cost of an optimal solution, and A* terminates by finding an optimal solution.

Page 10: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

10CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Optimality of A*

s n1* n2* n3* x

s n1 n2 n3 x

p*

p

nodes on optimal path to goal havef-values bounded by optimal solution cost

eventually f-values of nodes on non-optimalpath must exceed optimal solution cost

Page 11: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

11CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Multiple Path Checking in A*MPC: If you find a path to node n that you’ve already expanded, don’t expand it again

• was OK for BFS and LCFS, since first path expanded to any node n was assured to be shortest/cheapest

• In A*, you can be misled by heuristic that takes you all the way to node n along an “expensive path” (though it can’t take you all the way to goal if admissible)

s n’ n xp*(n)

p(n)c(p*) < c(p), but f(p*) > f(p)

Page 12: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

12CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Multiple Path Checking in A*

In example, p expanded before p*, and MPC ignores cheaper path p* to node n

• MPC can destroy optimality of A*But this can only happen if:

• some n’ on p* is on frontier, with fp*(n’) > fp(n)But gp*(n’) + dist(n’,n) < gp(n) fp*(n’) = gp*(n’) + h(n’) > gp(n) + h(n) = fp(n)

h(n’) > gp(n) - gp*(n’) + h(n) h(n’) > [gp*(n’) + dist(n’,n)] - gp*(n’) + h(n) h(n’) > h(n) + dist(n,n’)

• thus h(n’) makes n’ look worse than n by more than the actual distance it takes to get from n’ to n

• this can happen even if h is admissible: basically it means heuristic is too optimistic about n relative to n’

s n’ n xp*(n)

p(n)

c(p*) < c(p), but f(p*) > f(p)

Page 13: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

13CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

The Monotone RestrictionCan insist h satisfy the monotone restriction:

|h(n’) – h(n)| ≤ d(n’,n) for all nodes n, n’This is enough to ensure that MPC can be performed safely

with A* (i.e., MPC will preserve optimality)• In particular, it ensures that whenever A* expands a node n it

has found an optimal path to n. So A* can then discard any future occurrences of n.

• This can be proved using an argument similar to the argument used to show that A* finds an optimal solution.

• Can still do MPC correctly without the monotone restriction But need to store both old nodes visited and the cost of the

path found to those nodes. If a new cheaper path is found, we keep the node and search below it again. (Can be inefficient).

Page 14: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

14CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Iterative Deepening (IDS)IDS is motivated by the following tension:

• BFS guarantees optimal soln, requires expnt’l space• DFS requires linear space, can’t guarantee optimality• How can we get best of both worlds?

Trick: add a depth bound d to DFS• normal DFS, but never expand path with length > d

How do I ensure I find solution if one exists? • if failure at depth bound d, increase bound and repeat

How do I ensure shortest path is found first?• use the depth bounds: d=1, d=2, d=3, d=4, etc.

Page 15: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

15CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Iterative Deepening Graphically

Full search tree

DFS(1)

If no soln foundusing DFS(1):

run DFS(2)

If no soln foundusing DFS(2):

run DFS(3)

etc.

Page 16: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

16CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Properties of IDSGuaranteed to find shortest solutionWill only use linear space:

• O(db) space with depth bound d, branching factor b• Important: do not “save” results from previous iteration

How do we get this benefit?• we’re repeating computation!• At depth bound d, we repeat all computation done at

all earlier depth bounds. The only “new” steps are the expansion of leafs from previous iteration

Why redo? Why not store previous tree?• requires exponential space

Page 17: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

17CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

What Price do We Pay?IDS seems silly: a lot of wasted effort it seems!

• but how bad is it compared to BFS?• Assume shortest soln has length d

BFS generates: bd + bd-1 + bd-2 +…+ b0 = O(bd) nodesIDS generates:

+ b + b + b2

… + b + b2 ... + bd-2

+ b + b2 ... + bd-2 + bd-1

+ b + b2 ... + bd-2 + bd-1 + bd

d b0 + …+ 3 bd-2 + 2 bd-1 + bd nodes = O(bd) nodes

Page 18: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

18CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

What Price do We Pay? Intuitively, most of the time is spend searching the last level. So

multiple searches of the previous levels does not matter much.For branching factor b, a tree with d levels will have nodes

of which bd are at level d.

So the proportion of nodes in the whole tree that are level d is

I.e., for b = 2, about 1/2 of the nodes are at the last level. for b = 3, about 2/3 of the nodes are at the last level. for b = 4, about 3/4 of the nodes are at the last level.

Hence, iterative deeping is worst for binary trees and gets better as the branching factor increases.

111

bbd

bbbb

bbb

d

dd

d

d 1111

)1(1

1

1

Page 19: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

19CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Benefit of IDS We pay a time overhead (compared to BFS) for

exponential space savings!More analysis can show that the overhead factor for IDS

vs BFS is about b/(b-1)• if b = 2, overhead factor is about 2 (2 times as long as BFS)• if b = 4, overhead factor is 4/3 = 1.3• overhead factor decreases with b!

Iterative Deepening can be used with A*: IDA*• basically, do DFS, but let “depth bound” be maximum f-value

you consider, and increase f-value-bound gradually (there are subtle issues wrt how fast one can increase the f-bound and retain optimality).

Also analysis is wrt search trees. If graph has many multiple paths and BrFS does MPC, IDS can behave much worse in comparison.

Page 20: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

20CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Implicit Search GraphsMost search problems are not specified with explicit search graphs; nbr predicate “creates” neighboring states on the fly

• chess, SLD-derivations, planning robot activity, etc.Example: 8-puzzle

• Each board position a state• 9! = 362880 states• each state has 2, 3, or 4 nbrs• nbrs correspond to possible moves• nbr predicate: returns list of states reachable

State Representation? Neighbor implementation? Possible Heuristics?

1 2 3

54

7 68

Page 21: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

21CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Other Issues

Suppose list of neighbors is too large:• to add to frontier? to calculate all heuristic values?• What might one do? How could you use heuristic info

to limit your attention?• One possibility: generate neighbors in heuristic order

(only a subset of nbrs ever put on frontier)• can destroy optimality unless more nbrs added when

backtrackingOther things we can do to increase efficiency?

• control the direction of search

Page 22: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

22CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Backward Search

Backward branching factor is the (avg) set of moves that can be made to a specific node

• if I have the inverse nbr relation available, I can search in the graph backwards from the goal to the start state

Advantage: if backward BF b- less than forward BF b+, then search algth’m (any type) benefits

• lower time and space complexity since optimal path length still the same

• however, heuristic methods need a backwards heuristic

Page 23: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

23CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Bidirectional SearchSearch simultaneously in both directions

• if two frontiers intersect, you can “join” forward and backward paths to node in intersection to get a sol’n

• contrast # expansions for b-d BrFS vs. normal BrFS

s

g g

s

Page 24: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

24CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Bidirectional Search

Suppose we do BrFS• length of sol’n (shortest path) is k• branching factor (frwd/bkwd) is b

Each component of the bidirectional search expands O(bk/2) nodes

Normal BrFS expands O(bk) nodesBidirectional is exponential, but offers exponential savings

Issues: need bkwd dynamics, need to test intersection, must choose search alg. carefully

Page 25: 1 CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart CSC384: Lecture 10  Last time A*  Today complete A*, iterative deepening  Announcements:

25CSC 384 Lecture Slides (c) 2002-2003, C. Boutilier and P. Poupart

Island Search

Suppose you know that any (good) path to goal must pass through island states i1, i2, … ik

• e.g., must pass through specific tunnels to deliver pkg

Complexity can be cut significantly by searching for path from s to i1, i1 to i2, …, ik-1 to ik, ik to g

• what is potential savings (say) for BrFS using this strategy if avg subpath between islands has length m?

s

i1

i2

g