Top Banner
Lecture 12: Shortest-Path Problems
21

Lecture 12:

Jan 11, 2016

Download

Documents

ben ammar

Lecture 12:. Shortest-Path Problems. Floyd's Algorithm. Another popular graph optimization problem is All-Pairs Shortest Path.  In this problem, you are to compute the minimal path from every node to every other node in a directed weighted graph.  - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 12:

Lecture 12:

Shortest-Path Problems

Page 2: Lecture 12:

Floyd's Algorithm

Another popular graph optimization problem is All-Pairs Shortest Path.  In this problem, you are to compute the minimal path from every node to every other node in a directed weighted graph. 

The array shown below is a representation of the directed weighted graph.  Each row and column represents a particular node in the graph, while each entry in the body of the array is the weight of an arc connected the corresponding nodes.

Page 3: Lecture 12:

Weighted Graphs

Page 4: Lecture 12:

Traveling Salesperson Problem (TSP)

A B

C

D

EF

G

H

- 5 7 6 4 10 8 9

8 - 14 9 3 4 6 2

7 9 - 11 10 9 5 7

16 6 8 - 5 7 7 9

1 3 2 5 - 8 6 7

12 8 5 3 2 - 10 13

9 5 7 9 6 3 - 4

3 9 6 8 5 7 9 -

A

B

C

D

E

F

G

H

A B C D E F G H

Page 5: Lecture 12:

public static int minAvail(int row){ int minval = int.MaxValue; int imin = -1;

for (int j = 0; j < n; j++) { if (row != j && !used[j] && M[row, j] < minval) { minval = M[row, j]; imin = j; } } return imin;}

Finding the Closest Available Next City

ith

ro

w

jth column

M =

Page 6: Lecture 12:

public static void doGreedyTSP(int p){ int k = 0; do { itour[k] = p; tour[k] = L[p]; used[itour[k]] = true; p = minAvail(p); k += 1; } while (k < n);}

Greedy TSP

3 1 0 6

1 1 1 1 0 0 1 0

C B A G

itour

used

tour

A B C D E F G HL

Page 7: Lecture 12:

Single Source Shortest Path

Given a weighted graph G find the minimum weight path from a specified vertex v0 to every other vertex.

2

11

11 3

4

5

3

6

v1

v0

v5

v4

v3

v2

The single source shortest path problem is as follows. We are given a directed graph with nonnegative edge weights G = (V,E) and a distinguished source vertex, . The problem is to determine the distance from the source vertex to every vertex in the graph.

Vs

Page 8: Lecture 12:

v1 v2 v3 v4 v5

node minimum

list path

v1 v2 v3 v4 v5

5 1 4 - 6

v1 v2 v3 v4 v5

5 1 4 - 6

{2} 3 4 2 6

v1 v2 v3 v4 v5

5 1 4 - 6

{2} 3 4 2 6

{24} 3 3 5

v1 v2 v3 v4 v5

5 1 4 - 6

{2} 3 4 2 6

{24} 3 3 5

{241} 3 5

v1 v2 v3 v4 v5

5 1 4 - 6

{2} 3 4 2 6

{24} 3 3 5

{241} 3 5

{2413} 4

v1 v2 v3 v4 v5

5 1 4 - 6

{2} 3 4 2 6

{24} 3 3 5

{241} 3 5

{2413} 4

2

11

11 3

4

5

3

6

v1

v0

v5

v4

v3

v2

Dijkstra's Algorithm for SSSP

Page 9: Lecture 12:

Eulers Formula

Let G be a connected planar simple graph with e edges and v vertices. Let r be the number of regions in a planar representation of G.

Then

r = e - v + 2.

Page 10: Lecture 12:
Page 11: Lecture 12:
Page 12: Lecture 12:
Page 13: Lecture 12:
Page 14: Lecture 12:
Page 15: Lecture 12:
Page 16: Lecture 12:
Page 17: Lecture 12:
Page 18: Lecture 12:
Page 19: Lecture 12:
Page 20: Lecture 12:
Page 21: Lecture 12: