CS 1501

Data Structures and Algorithms

Programming Project 5

 

Graphs can be used to model a lot of real-life situations, including computer networks.  Large computer networks contain many nodes and can become disconnected if some nodes within the network fail.  In this assignment you will use a graph to represent a simple computer network, and you will use a graph traversal algorithm to determine if the network is connected.  As nodes fail you will remove them from the network, and as they are repaired you will return them to the network.  Along the way you will report the status of the network, specifically whether or not it remains connected.

 

Details:

 

Initially you will read in a graph, formatted in the way indicated in your textbook.  The first line will contain an integer representing V, the number of vertices in the graph.  The second line will contain an integer representing E, the number of edges in the graph.  The remaining E lines will contain vertex pairs to represent the actual edges in the graph.  For example, the simple graph shown below will be represented by the file shown in the box immediately to the right of it.

6

8

1 2

1 3

1 5

2 6

3 5

4 5

4 6

5 6

 

D 4

D 2

D 5

U 4

U 2

D 1

U 5

 

 
 

 

 

 

 

 

 

 

 

 

 

 

 

 


You may represent your graph by either an adjacency list or an adjacency matrix – whichever you prefer.  However, you must incorporate into your representation the ability to remove and then add back vertices as they "go down" and are brought back up.  When a vertex goes down all edges connected to it are no longer valid.  When a vertex comes back up, all of its edges are restored (unless they are incident on another vertex that is currently down).  Think about how to incorporate this ability into your graph representation.

 

Once you have read in your graph, you read in a series of commands from a second input file.  Each command will be the letter D or the letter U followed by an integer.  D represents that a node has gone down and U represents that a node has come back up.  For example, the second box in the example above shows the commands for the graph above.  After reading each command your program should test to see if the graph is still connected, and output the following (to an output file):

        NODE <ID> JUST WENT [UP, DOWN]

NETWORK IS CURRENTLY [CONNECTED, DISCONNECTED]

NODES <LIST OF UP NODES> ARE UP

NODES <LIST OF DOWN NODES> ARE DOWN

For example, below is the output that should be produced for each of the first 3 commands in the example above:

NODE <4> JUST WENT DOWN

NETWORK IS CURRENTLY CONNECTED

NODES <1, 2, 3, 5, 6> ARE UP

NODES <4> ARE DOWN

 

NODE <2> JUST WENT DOWN

NETWORK IS CURRENTLY CONNECTED

NODES <1, 3, 5, 6> ARE UP

NODES <2, 4> ARE DOWN

 

NODE <5> JUST WENT DOWN

NETWORK IS CURRENTLY DISCONNECTED

NODES <1, 3, 6> ARE UP

NODES <2, 4, 5> ARE DOWN

Your program should continue processing the commands and responding in this way until the end of the command file.  To determine if the graph is connected you should use depth-first search or breadth-first search, as we discussed in lecture.

 

For consistency and ease of grading, your program should allow the user to input the graph file name and the command file name.  Make sure the output file name corresponds to the input file names.  For example, the files for the example shown above are: graph1.txt and command1.txt.  Your output file for that file should be output1.txt.  Use the same convention for the remaining test files (check the online site in the next few days for the remaining test files).

 

·         Don't forget to follow the submission guidelines.  Be sure to submit all of your source files, all of the input files and all of your (properly named) output files.

·         If you want to try some extra credit, here are a couple of ideas:

·         Allow an edge to go down separate from a node, and make up a test file that tests a combination of edge and vertex failures.  Note that if you do this you must be careful when bringing nodes and edges back up, since an edge that was down and brought back up still cannot be used if one of its terminating vertices is down (similar idea when bringing a vertex back up).

·         Allow a command that will query the reachable nodes from a given vertex.  For example, if the command R 3 were given, the output would be all of the nodes that can be reached from vertex 3.  Naturally, if the graph is connected this will be all of the vertices in the graph, but if the graph is not connected it will be only a subset of the vertices.  Include a test file that demonstrates that you have done this correctly.