27
OPTIMAL Search OPTIMAL Search When cost of When cost of TRAVERSING TRAVERSING the path should be the path should be minimized (even at expense of more complicated minimized (even at expense of more complicated SEARCHING SEARCHING) : ) : Uniform Cost Uniform Cost Branch and Bound Branch and Bound Introducing Underestimates Introducing Underestimates Path Deletion Path Deletion A* A*

5 Optimal Search Show

Embed Size (px)

Citation preview

Page 1: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 1/27

OPTIMAL Search OPTIMAL Search 

When cost ofWhen cost of TRAVERSINGTRAVERSING the path should bethe path should beminimized (even at expense of more complicatedminimized (even at expense of more complicated

SEARCHINGSEARCHING) :) :

Uniform CostUniform Cost

Branch and BoundBranch and Bound

Introducing UnderestimatesIntroducing UnderestimatesPath DeletionPath Deletion

A*A*

Page 2: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 2/27

Page 3: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 3/27

3

U niform cost algorithm U niform cost algorithm 

= uniformed best = uniformed best- -first first 

SS

 A A DD

BB DD A A EE

EE BB BB FF

BB FF CC EE A A CC GG

GG

GG FFCC

33 44

44 55

55

55 22

55 44

33

33 44

77 88 99 66

10101111

CC EE

DD FF

GG

44 55

1111 1212 1313 1313

1313

44

At eachAt eachstep,step,select theselect thenode withnode withthe lowestthe lowest

accumulaccumul--ated cost.ated cost.

Page 4: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 4/27

4

U niform cost algorithm: U niform cost algorithm: 

(BY ACCUMULATED COST (BY ACCUMULATED COST ))

1.1. QUEUEQUEUE <<---- path only containing the root;path only containing the root;

2.2. WHILEWHILE QUEUEQUEUE is not emptyis not emptyANDAND goal is not reachedgoal is not reached

DODO remove the first path from theremove the first path from the QUEUEQUEUE;;create new paths (to all children);create new paths (to all children);reject the new paths with loops;reject the new paths with loops;

add the new paths and sort the entireadd the new paths and sort the entire QUEUEQUEUE;;

3.3. IFIF goal reachedgoal reachedTHENTHEN success;success;ELSEELSE failure;failure;

Page 5: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 5/27

5

Problem: NOT always optimal! Problem: NOT always optimal! 

GG

100100

55

DD

55

1010

EE

55

1515

FF55

2020

SSAA CC

1155

5511

BB

1122

Uniform costUniform costreturns the pathreturns the pathwith cost 102, whilewith cost 102, whilethere is a path withthere is a path with

cost 25.cost 25.

Page 6: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 6/27

6

The Branch The Branch- -and and- -Bound Bound 

principle principle 

Use any (complete) searchUse any (complete) searchmethod to findmethod to find a patha path..

Remove all partial paths thatRemove all partial paths thathave an accumulated costhave an accumulated costlarger or equal than thelarger or equal than thefound path.found path.

Continue search for the nextContinue search for the nextpath.path.

Iterate.Iterate.

3.53.5

SS

BBDD

CCGG

AA55

55

EE 66

FirstFirstgoalgoalreachedreached

22

33

33

22 33

0.50.5

GGXX

ignoreignore

XX

ignoreignore

Page 7: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 7/27

7

A weak integration of branch A weak integration of branch 

and bound in uniform cost: and bound in uniform cost: 

Change theChange the

termination condition:termination condition: only terminate whenonly terminate when

a path to a goal nodea path to a goal nodeHAS BECOME THEHAS BECOME THEBEST PATH.BEST PATH.

GG

100100

BB

55SS

AA CC

11

11

5511

22

102102

FF55

DD

EE

55

55

55

1010

1515

2020

2525

Page 8: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 8/27

8

Optimal U niform cost version: Optimal U niform cost version: 

(by accumulated cost(by accumulated cost))

1.1. QUEUEQUEUE <<---- path only containing the root;path only containing the root;

2.2. WHILEWHILE QUEUEQUEUE is not emptyis not emptyANDAND first pathfirst path does not reach goaldoes not reach goal

remove the first path from theremove the first path from the QUEUEQUEUE;;create new paths (to all children);create new paths (to all children);reject the new paths with loops;reject the new paths with loops;

add the new paths and sort the entireadd the new paths and sort the entire QUEUEQUEUE;;

3.3. IFIF goal reachedgoal reachedTHENTHEN success;success;ELSEELSE failure;failure;

Page 9: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 9/27

9

Example: Example: 

SS

 A A DD 44

SS

 A A

BB DD77 88

DD

SS

 A A DD

BB DD77 88 A A EE99

 A A DD33 44

SS

 A A

BB DD77 88

DD

 A A EE99 66

EE

BB FF1111 1010

Page 10: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 10/27

Page 11: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 11/27

Page 12: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 12/27

12

Properties of extended Properties of extended 

uniform cost : uniform cost : 

Optimal path:Optimal path:

IfIf there exists a numberthere exists a number HH > > 0, such that every arc0, such that every arc

hashas costcost uu HH, and if the branching factor is finite,, and if the branching factor is finite,

ThenThen extended uniform cost finds the optimal pathextended uniform cost finds the optimal path(if one exists).(if one exists).

Memory and speed:Memory and speed:

In the worst case, at least as bad as for breadthIn the worst case, at least as bad as for breadth--first:first:

needs additional sorting step after each pathneeds additional sorting step after each path--expansion !expansion !

How to improve ?How to improve ?

Page 13: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 13/27

13

Extension with Extension with 

heuristic estimates: heuristic estimates: 

Replace the ¶accumulated cost· in the ¶extendedReplace the ¶accumulated cost· in the ¶extendeduniform cost· algorithm by a function:uniform cost· algorithm by a function:

f(f(pathpath)) == cost(cost(pathpath)) ++ h(h(endpoint_pathendpoint_path))

cost(cost(pathpath)) == the accumulated cost of the partial paththe accumulated cost of the partial pathh(h(T T )) == a heuristic estimate of the cost remaininga heuristic estimate of the cost remaining

fromfrom T T to a goal nodeto a goal node

f(f(pathpath)) == an estimate of the cost of a path extendingan estimate of the cost of a path extendingthe current path to reach a goal.the current path to reach a goal.

++

where:where:

Page 14: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 14/27

14

Example: R econsider the Example: R econsider the 

straight straight- -line distance: line distance: 

h(h(T T )) = the straight= the straight--line distance fromline distance from T T to Gto G

DD EE

GGSS

 A A BB CC

FF

44

4444

4433

3322

55 55

DD EE

GGSS

 A A BB CC

FF

446.76.710.410.4

1111

8.98.96.96.9 33

Page 15: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 15/27

15

 A A DD3 + 10.4 = 13.43 + 10.4 = 13.4 4 + 8.9 = 12.94 + 8.9 = 12.9

SS

SS

 A A DD13.413.4

SS

 A A DD A A EE

13.413.419.419.4

SS A A DD

 A A EE

BB FF

13.413.419.419.4

17.717.7

DD

 A A EE9 + 10.4 = 19.49 + 10.4 = 19.4 6 + 6.9 = 12.96 + 6.9 = 12.9

EE

BB FF 10 + 3.0 = 13.010 + 3.0 = 13.011 + 6.7 = 17.711 + 6.7 = 17.7

FF

GG 13 + 0.0 = 13.013 + 0.0 = 13.0

STOP!STOP!

Page 16: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 16/27

16

Estimate Estimate- -extended extended 

U niform cost algorithm: U niform cost algorithm: 

(by f = cost + h(by f = cost + h))

1.1. QUEUEQUEUE <<---- path only containing the root;path only containing the root;

2.2. WHILEWHILE QUEUEQUEUE is not emptyis not emptyANDAND first pathfirst path does not reach goaldoes not reach goal

remove the first path from theremove the first path from the QUEUEQUEUE;;create new paths (to all children);create new paths (to all children);reject the new paths with loops;reject the new paths with loops;

add the new paths and sort the entireadd the new paths and sort the entire QUEUEQUEUE;;

3.3. IFIF goal reachedgoal reachedTHENTHEN success;success;ELSEELSE failure;failure;

Page 17: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 17/27

17

Optimality Optimality With the same condition on the arcsWith the same condition on the arcs--costs and oncosts and on

the branching factor:the branching factor:

SS

 A A DD A A

EEBB FF

13.413.4

19.419.417.717.7

GG 1313

IFIF for allfor all T T :: h(h(T T )) is an UNDERestimate of theis an UNDERestimate of theremaining cost to a goal noderemaining cost to a goal node

THENTHEN estimateestimate--extended uniform cost is optimal.extended uniform cost is optimal.

Intuition:Intuition:

includesincludesunderestimatedunderestimated

remaining costremaining cost

GG

withwith realreal remainingremainingcost, this path mustcost, this path mustat least be 13.4at least be 13.4

Page 18: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 18/27

18

More on underestimates: More on underestimates:  Example:Example:

SS

 A A

DD

FF

BB

EE

HH

CC

GG

II

11

11 11

11

11

11

11

11

11

11

11

RealRealremainingremainingcostscosts

33 22 11

22 11

33 22 11

33 22 11

55

44

44

33 22

OverOver--estimateestimate

IfIf hh is NOT an underestimate:is NOT an underestimate:

SS

 A A

DD

FF

1+31+3

1+51+5

1+41+4

BB

2+22+2 A A BB CC

3+13+1CC

GG44

Not the optimal pathNot the optimal path!!

Page 19: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 19/27

Page 20: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 20/27

20

Speed and memory Speed and memory 

In the worst case: no improvement over ¶branch andIn the worst case: no improvement over ¶branch andbounded extended uniform cost·bounded extended uniform cost· Just take h = 0 everywhere.Just take h = 0 everywhere.

For good heuristic functions: search may expandFor good heuristic functions: search may expandmuch less nodes !much less nodes ! See our running example.See our running example.

BUT:BUT: the cost of computing such functions may bethe cost of computing such functions may behighhigh TradeTrade--offoff

Page 21: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 21/27

21

An orthogonal extension: An orthogonal extension: 

path deletion path deletion 

Discard redundant paths:Discard redundant paths: in the ¶branch and bound extended uniform cost· :in the ¶branch and bound extended uniform cost· :

Principle:Principle: the minimum distance fromthe minimum distance from SS toto GG via Ivia I ==

(min. dist. from(min. dist. from SS toto II) + (min. dist. from) + (min. dist. from II toto GG))

SS

 A A DD 4433  A A

BB DD77 88Accumulated distanceAccumulated distanceXX

discard !discard !

Page 22: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 22/27

22

More precisely: More precisely: 

IFIF the QUEUE contains:the QUEUE contains:a patha path PP terminating interminating in II, with cost, with cost cost_Pcost_P

a patha path QQ containingcontaining II, with cost, with cost cost_Qcost_Q

cost_Pcost_P uu cost_Qcost_Q

THENTHENdeletedelete PP

SS

AA DD

BB DD77 88 AA EE99 66XX

QQ PP

Page 23: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 23/27

23

 A A DD33 44SS

SS

 A A DD 44

BB DD77 88XX

SSAA DD

BB DD77 AA EE99 66XX XX

SS

 A A DD

BB DD77 A A EE

BB FF1111 1010

XX

XX XX

Page 24: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 24/27

24

SS

 A A DD

BB DD A A EEBB FF

1010CC EE1111 1212XX XX

XXXX

SS

 A A DDBB DD A A EE

BB FFCC EE1111

GG 1313

XX XX

XXXX

Note how this optimization reduces the number ofNote how this optimization reduces the number ofexpansions VERY much, compared to ¶branch and boundexpansions VERY much, compared to ¶branch and boundextended uniform cost·.extended uniform cost·.

5 expansions less !5 expansions less !

Page 25: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 25/27

25

A* search A* search 

IS:IS:Branch and bound extended,Branch and bound extended,

Heuristic Underestimate extended,Heuristic Underestimate extended,

Redundant path deletion extended,Redundant path deletion extended,

Uniform Cost Search.Uniform Cost Search.

Note that redundant path deletion is based on theNote that redundant path deletion is based on the

accumulated costsaccumulated costs only, so that there is no problemonly, so that there is no problemcombining it with heuristic underestimates.combining it with heuristic underestimates.

Page 26: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 26/27

26

A* algorithm: A* algorithm: 1.1. QUEUEQUEUE <<---- path only containing the root;path only containing the root;

2.2. WHILEWHILE QUEUEQUEUE is not emptyis not emptyANDAND first pathfirst path does not reach goaldoes not reach goal

remove the first path from theremove the first path from the QUEUEQUEUE;;create new paths (to all children);create new paths (to all children);

reject the new paths with loops;reject the new paths with loops;add the new paths and sort the entireadd the new paths and sort the entire QUEUEQUEUE;;

IFIF QUEUEQUEUE containscontains path P terminating in I,

with cost cost_P, and path Q containing I,with cost cost_Q ANDAND cost_P u cost_Q

THENTHEN delete P3.3. IFIF goal reachedgoal reached THENTHEN success;success;

ELSEELSE failure;failure;

(by f = cost + h(by f = cost + h))

Page 27: 5 Optimal Search Show

8/8/2019 5 Optimal Search Show

http://slidepdf.com/reader/full/5-optimal-search-show 27/27

27

 A A DD3 + 10.4 = 13.43 + 10.4 = 13.4 4 + 8.9 = 12.94 + 8.9 = 12.9

SS

SS

 A A DD

 A A EE

13.413.4

9 + 10.4 = 19.49 + 10.4 = 19.4 6 + 6.9 = 12.96 + 6.9 = 12.9XX

SS

 A A DD A A EE

BB FF

13.413.4

11 + 6.7 = 17.711 + 6.7 = 17.7 10 + 3.0 = 13.010 + 3.0 = 13.0XX

SS

 A A DD A A EE

BB FF

13.413.4

17.717.7

GG 13 + 0.0 = 13.013 + 0.0 = 13.0

STOP!STOP!XX

Only difference is here.Only difference is here.