0% found this document useful (0 votes)
24 views2 pages

Assignment 2

The document describes finding an "almost shortest path" between two points in a graph. It first finds the actual shortest path, then removes all edges on that path from the graph. It then runs the shortest path algorithm again on the modified graph to find a path that avoids the original shortest path edges, in order to avoid traffic along the most popular route. The input format provides the number of vertices, source and target vertices, and edge weights. The output should list the vertices of the alternative shortest path from source to target.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views2 pages

Assignment 2

The document describes finding an "almost shortest path" between two points in a graph. It first finds the actual shortest path, then removes all edges on that path from the graph. It then runs the shortest path algorithm again on the modified graph to find a path that avoids the original shortest path edges, in order to avoid traffic along the most popular route. The input format provides the number of vertices, source and target vertices, and edge weights. The output should list the vertices of the alternative shortest path from source to target.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

U NIVERSITY OF THE W ITWATERSRAND , J OHANNESBURG

COMS2003: Application and Analysis of Algorithms II


A3 Assignment September 25, 2012

Question 2: Almost shortest path

One task that GPSs perform a lot is nding the shortest path between two points. The problem with this is that lots of people are using the same GPS, meaning that many people nd the same route, causing a lot of trafc on this route. You would like to nd the shortest path between two points that does not use any edges from the actual shortest path, because you would like to avoid the trafc but still use a short path. The easiest way to accomplish this is to nd the shortest path rst, and then remove all the edges that are on the shortest path. Then, in the new graph that has had some of its edges removed, perform the shortest path algorithm again, yielding the shortest path that does not use any edges from the original shortest path.

Input

You will be given input in the same form as Lab 17, except that the rst line will have three parameters - the number of vertices in the graph, the vertex we want to nd the shortest path from, and the vertex we want to nd the shortest path to. 11,0,7 0,1,20 0,5,10 1,2,5 1,5,11 1,6,5 6,2,5 2,7,10 2,3,50 3,8,9 4,5,12 5,6,30 6,7,4 7,8,4 5,9,16

5,10,12 10,6,1 10,7,8 -1

Output

You must output a list of vertices dening the path from the source vertex to the target vertex. In the input given above, we are trying to nd the almost shortest path from vertex 0 to vertex 7. The algorithm should rst nd the path 0,5,10,6,7 as this is the shortest path in that graph (try to conrm this by hand). Then, it should remove all the edges on this path and rerun the shortest path algorithm, so that it ends up with the following output: 0 1 2 7

You might also like