Sven O. Krumke 13 October 2005 krumke@mathematik.uni-kl.de Travel info How do I get to Halver? Requirements We want an answer that is correct • • fast • practical. Overview • Shortest Paths • Navigation systems • graphs and networks • Algorithms and Dat a Structures Shortest Paths I Tell: Call me the nearest way to Arth and Küssnacht Fischer: The frank street ru ns over stones, but a secret short cut and you can my boy run over Lowerz. Shortest Paths II Way at all Theseus found his way out of the labyrinth through a thread of Ariadne. Navigation Navigation system Route planning Localization Localization and route planning Localization "is simply" ... During the routing, we have approximately 5,022,028 crossings • • ca • 6169904 r oad about 10 100 potential routes The problem How to #!?*$!} we can find a shortest path in 1 second? Perhaps we should someti mes ask the mathematicians? Historic Sites 1736 people sought in Konigsberg a trail that led over all seven bridges exactly once. Historic Sites 1736 people sought in Konigsberg a trail that led over all seven bridges exactly once. Somehow it will not work! Euler and graph theory C A D B Leonhard Euler Euler and graph theory C There is no trail, since all vertices have odd degrees! D A B Euler's theorem: There is a trail if and only if G consists of all A and zsh. Graph vertex degrees are even. • a lot • lot of corners of edges Leonhard Euler The set of Euler Euler's theorem: There is a trail if and only if G zsh. and all vertex degrees a re even. Show: all vertex degrees even Consider longest cycle C in G. Case 1: K is Eulerian, there are Euler circle The set of Euler Euler's theorem: There is a trail if and only if G zsh. and all vertex degrees a re even. Show: all vertex degrees even Consider longest cycle C in G. Case 1: K is Eulerian Case 2: K is not there Eulerian Euler circle The set of Euler Euler's theorem: There is a trail if and only if G zsh. and all vertex degrees a re even. Show: all vertex degrees even Consider longest cycle C in G. Case 1: K is Eulerian Case 2: K is not Eulerian New Circle W There is a longer cycle than K! There are Euler circle Graph C C A D A D B undirected graph Directed graph B In a directed graph G = (V, E), each edge (u, v) a direction. u v Our problem with a new look Given: Directed graph G = (V, E) s • Start, Target (dd Wanted target) • Edge wei ghts: a shortest st-path s (start) 1 A 2 4 2 8 6 C B D E 3 Mr. Brute Force Hahahaha! With my fast computer, I simply try all ways! I do not ... On the trail of chance St-How many ways there are in a random graph? n vertices for each of the n (n-1) possible edges, we flip a coin? ? ? ? ? ? On the trail of chance St-How many ways there are in a random graph? n vertices for each of the n (n-1) possible edges, we toss a coin # Possible paths with n-1 edges: W'keit that a f ixed path exists: the expected number of ways: Head against force By brute force is not well! Shortest st-path = + zt sz Shortest path Shortest pa th Head against force (II) • s is 0 • away from itself all the direct successors of s are 1 away • all its successors, which are located do not have one, two away • ... 0 1 2 The algorithm of Dijkstra 2 4 6 A B C D 1 2 8 E 3 Wanted: The shortest way from A to C The algorithm of Dijkstra ∞ 0 A 1 Permanent marked corners 4 2 D B 2 6 ∞ C 8 E 3 ∞ ∞ "Infinite" The algorithm of Dijkstra ∞ 0 A 1 Permanent marked corners 4 2 D B 2 6 ∞ C 8 E 3 ∞ ∞ The algorithm of Dijkstra ∞ 4 0 A 1 Permanent corners marked A 0 4 2 6 2 D 1 ∞ B ∞ C 8 E 3 ∞ The algorithm of Dijkstra 4 2 0 A 1 Permanent corners marked A 0 4 2 1 D 6 B 7 C 8 E 4 ∞ ∞ 3 The algorithm of Dijkstra 4 3 4 2 1 Permanent corners marked A 0 D 1 D 1 B 6 2 7 C 8 E 4 ∞ ∞ 0 A 3 The algorithm of Dijkstra 3 4 2 1 Permanent corners marked A 0 D 1 D 1 B 6 2 7 C 8 E 4 ∞ 0 A 3 The algorithm of Dijkstra 3 4 2 1 Permanent corners marked A 0 D 1 D 1 B 3 B 6 2 5 7 C 8 E 4 ∞ 0 A 3 The algorithm of Dijkstra 3 4 2 1 Permanent corners marked A 0 D 1 D 1 B 3 B 6 2 5 C 8 E 4 ∞ 0 A 3 The algorithm of Dijkstra 3 4 2 1 Permanent corners marked A 0 D 1 B 3 E 4 D 1 B 6 2 5 C 8 E 4 ∞ 0 A 3 The Dijkstra's algorithm 3 4 2 1 Permanent corners marked A 0 D 1 B 3 E 4 D 1 B 6 2 5 C 8 E 4 ∞ 0 A 3 The Dijkstra's algorithm 3 4 2 1 Permanent corners marked A 0 D 1 B 3 E 4 C 5 D 1 6 2 B 5 C 8 E 4 ∞ 0 A 3 The Dijkstra's algorithm • In each iteration is not permanently marked corner with very little "key value " permanently • marked for all their successors, the key value adjusted total co sts (n vertices and m edges): 3 4 2 1 D 1 B 6 2 7 C 8 E 4 ∞ 0 A 3 Duration of the algorithm of Dijkstra Corner key value A B C ... 5 3 2 2 Computing Computing 5000 n 20 30 40 50 60 ... 100.0000 4500 4000 1s min 17.9 12.7 days 37.7 years 0.0004 s 0.0009 s 0.0016 s 0.0025 s 3500 3000 2500 2000 1500 1000 500 366 0.0036 s 1.5 h centuries 0 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 That has to go even better! n times the minimum Heaps of pile The problem here! A heap (heap) helps: "Height" log n 5 9 4 10 Minimum: 1 time DOWN: ??????? 14 11 9 9 7 14 2 3 7 smallest element (= minimum) Term "reloaded" Computing 1800 corner Key value 5 3 2 A 1600 B C ... 1200 1000 Reihe2 Reihe1 800 1400 600 400 200 0 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 Advanced Mathematics With even more sophisticated algorithms and data structures can reduce the runni ng time further. Summary • Behind the planner puts a lot of mathematics • thinking is better than brute f orce • Network Optimization: Thank you! http://www.mathematik.uni-kl.de/ ~ Krumke