Project 1

advertisement
Project 1
Write a C++ program that inputs a graph and executes the following functions:
a) Assuming a network (graph) as input, find the shortest distance between a node s and
every other vertex of the graph (using Dijkstra's shortest path algorithm).
In order to accomplish this task, you must declare a class Graph as defined in class and
implement a function Creates ( ) that updates the link-list of the graph (see lectures notes). The
vertices must be labeled from 0 to n-1 (n is the number of nodes). In the class function Creates,
a pair of nodes is input (example: 0, 1 - representing the edge (0,1)) for each edge and also the
probability of failure of the edge must be recorded (maybe using a two dimensional floating point
array). Even tough for this project we are assuming that the weight of each edge 1, you must also
keep track of another edge weight corresponding to the Euclidian distance between the endpoints
of each edge (perhaps using another two dimensional array to record the distances in meters).
The weights corresponding to the probability of failures and Euclidean distances will be used later
in Project 2 to calculate the reliability of the communication between two vertices s called the
source and another vertex t called the sink (for example the vertex labeled 0 and labeled n-1).
It is recommended to implement the function Creates first.
In the main procedure you must enter a number corresponding to the number of vertices n and
the diameter-bound D, before invoking the constructor for the class Graph. Then you call the
function Creates ( ) to update the linked-list according to the edges of the graph.
Example of the function Creates for a graph with 4 vertices and 4 edges (distances between
vertices maybe a bid disproportional with real networks)
Enter an edge (enter -1, -1 to exit procedure): 0 1
Probability of failure: .5
Distance between vertex 0 and vertex 1: 20
Enter an edge (enter -1, -1 to exit procedure): 1 2
Probability of failure: .5
Distance between vertex 1 and vertex 2: 40
Enter an edge (enter -1, -1 to exit procedure): 2 3
Probability of failure: .5
Distance between vertex 2 and vertex 3: 55
Enter an edge (enter -1, -1 to exit procedure): 0 3
Probability of failure: .75
Distance between vertex 2 and vertex 3: 35
Enter and edge (enter -1, -1 to exit procedure): -1 -1
Exiting procedure Creates.
Download