1 / 21

Lecture 12:

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. 

selima
Download Presentation

Lecture 12:

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 12: Shortest-Path Problems

  2. 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.

  3. Weighted Graphs

  4. A B C D E F G H A B C D E F 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 - Traveling Salesperson Problem (TSP) A B H C G D E F

  5. Finding the Closest Available Next City publicstaticint 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; } jth column M = ith row

  6. L A B C D E F G H itour 3 1 0 6 used 1 1 1 1 0 0 1 0 tour C B A G Greedy TSP publicstaticvoid 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); }

  7. 2 v3 v2 v1 v0 v5 v4 5 1 3 1 1 4 1 6 3 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. Single Source Shortest Path Given a weighted graph G find the minimum weight path from a specified vertex v0 to every other vertex.

  8. 2 v3 v4 v5 v0 v1 v2 v1 v2 v3 v4 v5 node minimum list path v1 v2 v3 v4 v5 5 1 4 - 6 {2} 3 42 6 {24} 3 3 5 {241} 35 {2413} 4 5 1 3 1 1 4 1 6 3 Dijkstra's Algorithm for SSSP 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 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 v1 v2 v3 v4 v5 5 1 4 - 6

  9. 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.

More Related