A�Dijkstra-Like�Scenario Your�company�owns�a�delivery�truck�that�will�have�to�make�many� trips�in�a�day�to�various�warehouses,�always�starting�at�warehouse�A� and�ending�at�warehouse�B.��However,�it�will�never�repeat�visit�the� Heuristic�Graph�Search:� same�warehouse�twice�in�one�day.��Because�of�demand,�you�cannot� waste�time�refueling�the�truck�until�it�reaches�B.��The�truck�can� Another�Reason�AI�is�Cool travel�at�most�K�miles�on�a�single�tank�of�gas.��You�are�given�a graph�where�the�nodes�represent�the�warehouses�and�the�directed� edges�represent�the�highways�connecting�the�two�warehouses.��Each� edge�is�weighted�according�to�the�length�of�that�highway.� Nick�Deibel As�you�want�your�drivers�to�avoid�taking�paths�of�longer�than�K� Quiz�Section�– 5/31/02 miles,�design�an�algorithm�that�tells�you�if�there�exists�any�simple� path�from�A�to�B�(no�nodes/warehouses�repeated)�whose�length�is� greater�than�K�miles.� Whoops,�That’s� REALLY� Hard Huge�Graphs • Consider�some�really�huge graphs… • Longest�Path�is�an�NP-Complete�problem. – All�cities�and�towns�in�the�World�Atlas • No�known�polynomial-time�algorithm�solves�it. – All�stars�in�the�Galaxy – A�poly-time�algorithm�does�exist�for�DAGS.� – All�ways�10�blocks�can�be�stacked • This�is�a�difficult�problem�for�even�small�graphs. Huh??? Implicitly�Generated�Graphs Blocks�World • A�huge�graph�may�be�implicitly�specified by�rules�for� generating�it�on-the-fly • Source�=�initial�state�of�the�blocks • Blocks�world:� • Goal�=�desired�state�of�the�blocks – vertex�=�relative�positions�of�all�blocks – edge�=�robot�arm�stacks�one�block • Path�source�to�goal�=�sequence�of�actions� stack(blue,table) (program)�for�robot�arm! stack(green,blue) • n�blocks� � n n vertices stack(blue,red) • 10�blocks� � 10�billion�vertices! stack(green,red) stack(green,blue) 1
Problem:�Branching�Factor An�Easier�Case • Cannot�search�such�huge�graphs�exhaustively.�� • Suppose�you�live�in�Manhattan;�what�do�you�do? Suppose�we�know�the�goal�is�only� d steps�away. • Dijkstra’s algorithm�is�basically�breadth-first� search�(modified�to�handle�arc�weights) S 52 nd St • Breadth-first�search�(or�for�weighted�graphs,� G 51 st St Dijkstra’s algorithm)�– If�out-degree�of�each�node� is�10,�potentially�visits�10 d vertices 50 th St – 10�step�plan�=�10�billion�vertices�visited! 10 th Ave 9 th Ave 8 th Ave 7 th Ave 6 th Ave 5 th Ave 4 th Ave 3 rd Ave 2 nd Ave Best-First�Search Best�First�in�Action • The� Manhattan�distance ( � x+� � y)�is�an�estimate� • Suppose�you�live�in�Manhattan;�what�do�you�do? of�the�distance�to�the�goal – a�heuristic�value • Best-First�Search S 52 nd St – Order�nodes�in�priority�to�minimize�estimated�distance� G 51 st St to�the�goal�h(n) • Compare:�BFS�/�Dijkstra 50 th St – Order�nodes�in�priority�to�minimize�distance�from�the� start 10 th Ave 9 th Ave 8 th Ave 7 th Ave 6 th Ave 5 th Ave 4 th Ave 3 rd Ave 2 nd Ave Problem�1:�Led�Astray Problem�2:�Optimality • Eventually�will�expand�vertex�to�get�back�on�the� • With�Best-First�Search,�are�you� guaranteed a� right�track shortest�path�is�found�when – goal�is�first�seen? S – when�goal�is�removed�from�priority�queue�(as�with� 52 nd St G Dijkstra?) 51 st St 50 th St 10 th Ave 9 th Ave 8 th Ave 7 th Ave 6 th Ave 4 th Ave 3 rd Ave 2 nd Ave 5 th Ave 2
Sub-Optimal�Solution Synergy? • No!��Goal�is�by�definition�at�distance�0:�will�be� • Dijkstra�/�Breadth�First�guaranteed�to�find� optimal removed�from�priority�queue�immediately,�even�if� solution a�shorter�path�exists! • Best�First�often�visits� far�fewer vertices,�but�may� (5�blocks) not�provide�optimal�solution S 52 nd St h=2 h=5 G 51 st St h=4 h=1 – Can�we�get�the�best�of�both? 9 th Ave 8 th Ave 7 th Ave 6 th Ave 5 th Ave 4 th Ave Heuristics A*�(“A�star”) • A�rule�of�thumb,�simplification,�or�educated�guess.� • Order�vertices�in�priority�queue�to�minimize • Reduces�the�search�for�solutions�in�large�solution� (distance�from�start)�+�(estimated�distance�to�goal) spaces • Unlike�algorithms,�heuristics�do�not�guarantee� f(n)��=���g(n) +���h(n) optimal,�or�even�feasible,�solutions.� f(n)�=�priority�of�a�node g(n) =�true�distance�from�start h(n) =�heuristic�distance�to�goal Optimality Problem�2�Revisited • Suppose�the�estimated�distance�(h)�is� always less�than�or�equal�to the�true distance�to�the� vertex g(n) h(n) f(n) (5�blocks) S 52 nd St goal 52 nd &�9 th 0 5 5 – heuristic�is�a� lower�bound�on�true�distance G 51 st St 50 th St • Then:��when�the�goal�is�removed from�the�priority� queue,�we�are�guaranteed to�have�found�a�shortest� 9 th Ave 8 th Ave 7 th Ave 6 th Ave 5 th Ave 4 th Ave path! 3
Problem�2�Revisited Problem�2�Revisited vertex g(n) h(n) f(n) vertex g(n) h(n) f(n) (5�blocks) (5�blocks) S S 52 nd St 52 nd St 52 nd &�4 th 52 nd &�4 th 5 2 7 5 2 7 G 51 st &�9 th G 51 st &�8 th 51 st St 1 4 5 51 st St 2 3 5 50 th &�9 th 2 5 7 50 th St 50 th St 9 th Ave 9 th Ave 8 th Ave 7 th Ave 6 th Ave 5 th Ave 4 th Ave 8 th Ave 7 th Ave 6 th Ave 5 th Ave 4 th Ave Problem�2�Revisited Problem�2�Revisited vertex g(n) h(n) f(n) vertex g(n) h(n) f(n) S (5�blocks) S (5�blocks) 52 nd St 52 nd St 52 nd &�4 th 52 nd &�4 th 5 2 7 5 2 7 G 51 st &�7 th G 51 st &�6 th 51 st St 3 2 5 51 st St 4 1 5 50 th &�9 th 50 th &�9 th 2 5 7 2 5 7 50 th St 50 th St 50 th &�8 th 50 th &�8 th 3 4 7 3 4 7 50 th &�7 th 4 3 7 9 th Ave 9 th Ave 8 th Ave 7 th Ave 6 th Ave 5 th Ave 4 th Ave 8 th Ave 7 th Ave 6 th Ave 5 th Ave 4 th Ave Problem�2�Revisited Problem�2�Revisited vertex g(n) h(n) f(n) vertex g(n) h(n) f(n) (5�blocks) (5�blocks) S S 52 nd St 52 nd St 52 nd &�4 th 52 nd &�4 th 5 2 7 5 2 7 G 51 st &�5 th G 50 th &�9 th 51 st St 5 0 5 51 st St 2 5 7 50 th &�9 th 50 th &�8 th 2 5 7 3 4 7 50 th St 50 th St 50 th &�8 th 50 th &�7 th 3 4 7 4 3 7 50 th &�7 th 4 3 7 9 th Ave 9 th Ave 8 th Ave 8 th Ave 7 th Ave 6 th Ave 5 th Ave 4 th Ave 7 th Ave 6 th Ave 5 th Ave 4 th Ave DONE! 4
Proof�of�A*�Optimality What�Would�Dijkstra�Have� Done? • A*�terminates�when�G�is�popped�from�the�heap. • Suppose�G�is�popped�but�the�path�found�isn’t�optimal: priority(G)�>�optimal�path�length�c (5�blocks) S • Let�P�be�an�optimal�path�from�S�to�G,�and�let�N�be�the�last� 52 nd St vertex�on�that�path�that�has�been� visited�but�not�yet�popped . G 51 st St There�must�be�such�an�N,�otherwise�the�optimal�path�would�have�been� found. priority(N)�=�g(N)�+�h(N)� � c 50 th St • So�N�should�have�popped�before�G�can�pop.��Contradiction. 49 th St non-optimal�path�to�G S G 48 th St 47 th St 9 th Ave undiscovered�portion� 8 th Ave 7 th Ave 6 th Ave 5 th Ave 4 th Ave portion�of�optimal� N of�shortest�path path�found�so�far What�About�Those�Blocks? Other�Real-World�Applications • Routing�finding�– computer�networks,�airline� • “Distance�to�goal”�is�not�always�physical�distance route�planning • Blocks�world:� • VLSI�layout�– cell�layout�and�channel�routing – distance�=�number�of�stacks�to�perform • Production�planning�– “just�in�time”�optimization – heuristic�lower�bound�=�number�of�blocks�out�of�place • Protein�sequence�alignment • Many�other�“NP-Hard”�problems – A�class�of�problems�for�which�no�exact�polynomial� time�algorithms�exist�– so�heuristic�search�is�the�best� we�can�hope�for #�out�of�place�=�1,���true�distance�to�goal�=�3 5
Recommend
More recommend