CS141 Lab 8

Shortest Path With At Least B Bandwidth


In some cases, we want to find a path which is not only the shortest one, but also satisfies certain condition. For example, in the following graph each edge is associated with a distance (the first number) and a bandwidth (the second number) . We need to find the shortest path with at least B bandwidth. This means every edge in the path must have a bandwidth of B or more.

Assignment

Using Dijkstra's shortest path algorithm to find the shortest path from node 1 to the other nodes with certain minimum bandwidth.

Implement Dijkstra's algorithm and find the shortest path.

Pseudo-code of Dijkstra's algorithm

Modify the algorithm to add the bandwidth condition.

 

Input File Format

The input file has the following format: 

The first number is total number of nodes. The second number is total number of edges. Starting from the third line, each line represents a edge. The first two numbers are the pair of nodes that this edge connects. The third number is the distance between the two nodes. The last number is the bandwidth of the edge.

 

9      // total number of nodes
15    // total number of edges
1     2    2    3    //node    node    distance    bandwidth
2     3    4    9
3     4    2    6    
........
........
........
 

Lab Report

Print out the shortest path for the the following pair of nodes without considering the bandwidth.

1 to 3    1-2-3
1 to 4    1-2-3-4   
1 to 5    1-2-3-4-5

Print out the shortest path from node 1 to node 3 with bandwidth at least 5.    1-7-9-5-4-3

Print out the shortest path from node 1 to node 4 with bandwidth at least 6.    1-7-8-4

Print out the shortest path from node 1 to node 5 with bandwidth at least 8.    1- 6-5

 

Test Data

    test.txt      test2.txt