shortest paths

27
Shortest Paths Text Discrete Mathematics and Its Applications (5 th Edition) Kenneth H. Rosen Chapter 9.6 Based on slides from Chuck Allison, Michael T. Goodrich, and Roberto Tamassia By Longin Jan Latecki

Upload: viho

Post on 21-Jan-2016

42 views

Category:

Documents


0 download

DESCRIPTION

Shortest Paths. Text Discrete Mathematics and Its Applications (5 th Edition) Kenneth H. Rosen Chapter 9.6 Based on slides from Chuck Allison, Michael T. Goodrich, and Roberto Tamassia By Longin Jan Latecki. BOS. NY. CHI. SF. DEN. ATL. LA. MIA. Weighted Graphs. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Shortest Paths

Shortest Paths

Text

Discrete Mathematics and Its Applications (5th Edition)

Kenneth H. Rosen

Chapter 9.6

Based on slides from Chuck Allison, Michael T. Goodrich, and Roberto Tamassia

By Longin Jan Latecki

Page 2: Shortest Paths

Weighted Graphs

Graphs that have a number assigned to each edge are called weighted graphs.

SF

LA

DENCHI

ATL

MIA

BOS

NY

Page 3: Shortest Paths

Weighted Graphs

SF

LA

DENCHI

ATL

MIA

BOS

NY

MILES

2534

1855

957

834349 2451

908

722

860

606 760

191

1090

595

Page 4: Shortest Paths

Weighted Graphs

SF

LA

DENCHI

ATL

MIA

BOS

NY

FARES

$129

$99

$79

$59

$89$69

$129$89$39 $99$7

9

$69

$39

Page 5: Shortest Paths

Weighted Graphs

SF

LA

DENCHI

ATL

MIA

BOS

NY

FLIGHT TIMES

4:05

2:55

2:202:10

3:502:001:15

2:10

1:40

1:30

1:55 2:45

0:50

1:50

Page 6: Shortest Paths

Weighted Graphs

A weighted graph is a graph in which each edge (u, v) has a weight w(u, v). Each weight is a real number.

Weights can represent distance, cost, time, capacity, etc.

The length of a path in a weighted graph is the sum of the weights on the edges.

Dijkstra’s Algorithm finds the shortest path between two vertices.

Page 7: Shortest Paths
Page 8: Shortest Paths
Page 9: Shortest Paths
Page 10: Shortest Paths
Page 11: Shortest Paths
Page 12: Shortest Paths
Page 13: Shortest Paths
Page 14: Shortest Paths

Dijkstra's Algorithm

Page 15: Shortest Paths

Dijkstra Animation

Demo

Page 16: Shortest Paths

Problem: shortest path from a to z

a

b d f

z

c e g

45 5

7

4

21

553

34

a b c d e f g z S

0 ∞ ∞ ∞ ∞ ∞ ∞ ∞ a

x 4(a) 3(a) ∞ ∞ ∞ ∞ ∞ a,c

x x

Page 17: Shortest Paths

1

5

7

23

46

20

40

1535

35

10

15

10

50

75

1 2 3 4 5 6 7 S

0 ∞ ∞ ∞ ∞ ∞ ∞ 1

x 15(1) 35(1) ∞ 20(1) ∞ ∞ 1,2

x x

Page 18: Shortest Paths

Theorems

Dijkstra’s algorithm finds the length of a shortest path between two vertices in a connected simple undirected weighted graph G=(V,E).

The time required by Dijkstra's algorithm is O(|V|2).

It will be reduced to O(|E|log|V|) if heap is used to keep {vV\Si : L(v) < }, where Si is the set S after iteration i.

Page 19: Shortest Paths

The Traveling Salesman Problem

The traveling salesman problem is one of the classical problems in computer science.

A traveling salesman wants to visit a number of cities and then return to his starting point. Of course he wants to save time and energy, so he wants to determine the shortest cycle for his trip.

We can represent the cities and the distances between them by a weighted, complete, undirected graph.

The problem then is to find the shortest cycle (of minimum total weight that visits each vertex exactly one).

Finding the shortest cycle is different than Dijkstra’s shortest path.It is much harder too, no polynomial time algorithm exists!

Page 20: Shortest Paths

The Traveling Salesman Problem

Importance:• Variety of scheduling application can be solved as a

traveling salesmen problem.

• Examples:

• Ordering drill position on a drill press.

• School bus routing.

• The problem has theoretical importance because it represents a class of difficult problems known as NP-hard problems.

Page 21: Shortest Paths

THE FEDERAL EMERGENCY MANAGEMENT AGENCY

A visit must be made to four local offices of FEMA, going out from and returning to the same main office in Northridge, Southern California.

Page 22: Shortest Paths

FEMA traveling salesman Network representation

Page 23: Shortest Paths

30

25

40

35

80

6545

50

5040

Home

1

2 3

4

Page 24: Shortest Paths

FEMA - Traveling Salesman

• Solution approaches

– Enumeration of all possible cycles.• This results in (m-1)! cycles to enumerate for a graph with m

nodes. • Only small problems can be solved with this approach.

Page 25: Shortest Paths

Possible cyclesCycle Total Cost

1. H-O1-O2-O3-O4-H 210 2. H-O1-O2-O4-O3-H 195 3. H-O1-O3-O2-O3-H 240 4. H-O1-O3-O4-O2-H 200 5. H-O1-O4-O2-O3-H 225 6. H-O1-O4-O3-O2-H 200 7. H-O2-O3-O1-O4-H 265 8. H-O2-O1-O3-O4-H 235 9. H-O2-O4-O1-O3-H 25010. H-O2-O1-O4-O3-H 22011. H-O3-O1-O2-O4-H 26012. H-O3-O1-O2-O4-H 260

Minimum

For this problem we have

(5-1)! / 2 = 12 cycles. Symmetrical problemsneed to enumerate only (m-1)! / 2 cycles.

FEMA – full enumeration

Page 26: Shortest Paths

30

25

40

35

806545

5050

40

Home

1

2 3

4

FEMA – optimal solution

Page 27: Shortest Paths

The Traveling Salesman Problem

Unfortunately, no algorithm solving the traveling salesman problem with polynomial worst-case time complexity has been devised yet.

This means that for large numbers of vertices, solving the traveling salesman problem is impractical.

In these cases, we can use efficient approximation algorithms that determine a path whose length may be slightly larger than the traveling salesman’s path, but