There are many situations when you'll have to use your knowledge about graphs to solve real-life problems. The problem described here is one people in certain businesses (road-construction, communications, etc.) face all the time. A complete description of the problem is included in a memo from your instructor. What you'll turn in
Grading
For each business day you turn in your project earlier you receive a
5% bonus. However, penalties increase by 5% as well. You can turn in your
assignment up to ten business days ahead of the deadline.
You may be asked to do a code review with your instructor.
A computer business in Chicago -- they do networking -- has asked me to find a solution to their problem. I pass the problem on to you and I just add some details about input and output formats. The problem can be modelled as a graph problem. What you have to do is to write a general program that takes a description of a connected graph from standard input, finds the shortest path between two vertices specified in the command line, and prints the result out to standard output. Here is a description for the input and the output of your program. Input Each line in the input will give the names of two vertices in the graph and the weight of the edge connecting them. For simplicity vertex names are non-negative integers. Weights are non-negative integers as well. There must be at least two vertices, the graph must be connected and each edge may be listed only once. Your program must enforce these rules. Here is an example of input for a graph with four vertices: 0 1 10 1 2 9 0 3 8 2 3 12Output There are two output lines: the first contains the names of the vertices in the shortest path, the second is the actual length of the shortest path. Using the graph described by the sample above, let's assume the program is run as assign1 0 2Then the output will be: Path: (0,1,2) Length: 19Varia Please note that if your program reads input from standard input then it can get input from a file by using input redirection. Similarly, if the program writes to standard output, then the output can be easily written to a file by using output redirection. For example, assign1 0 2 < test1.din will get the graph description from the file named test1.din (< indicates input redirection), and the output will be written to standard output (typically the monitor). On the other hand, if you do assign1 0 2 > myOutputFile.out then the graph description will come from standard input (typically your keyboard) and the output will be written to myOutputFile.out (> indicates output redirection). Finally, you can do both input and output redirection at the same time: assign1 0 2 < test1.din > test1.out Have fun, Virgil
|