Programming Assignment #3 CSE 100 (Spring 2015)

Network Planning

Return to Course Home Page

Page Navigation

Assignment Overview


In this assignment, you will solve several real world network planning problems by mapping them to well-known graph algorithms. These graph algorithms are

  1. finding the shortest path
  2. constructing a minimum spanning tree

Dijkstra's shortest path algorithm in one of many algorithms and is the recommended one to use. Prim's or Kruskal's minimum spanning tree algorithms are the suggested MST solutions to use. If you prefer a different algorithm, however, you are welcome to use it -- so long as it solves the same problem.

Using the network planning problem gives you the opportunity to implement new data structures, such as union-find, and apply previously used data structures, such as heaps/priority queues, on real-world problems. Additionally, this assignment comes with more freedom than previous ones, meaning you can choose whichever data-structures you feel appropriate for solving the problem presented.

Additional links to supplement the textbook.

Return to Top of Page

Due Dates


Checkpoint Submission: Tuesday May 5 @ 10:00 PM

Final Submission: Thursday May 14 @ 10:00 PM

For both the checkpoint and final submissions, all your files must be submitted with a working Makefile that generates a binary executable from your source called netplan by typing make at the command-line.

Return to Top of Page

Acquiring the Starter Files


You can develop your code anywhere but you must test it on the ieng6 servers. If you plan to develop your code on ieng6 DO NOT log into ieng6.ucsd.edu instead log into one of ieng6's dedicated servers. You must follow these steps to acquire the starter code and prepare for the assignment. Do not directly copy files from any directory that you find on ieng6, as may have been the procedure in previous offerings of this course!

Instead, see Using Gitlab for the proper steps to setup your ssh key and cloning your git repo over SSH. Also, make sure your repository is created in the cse100-sp15 namespace. If not, our grading scripts will not be able to access your code and you will receive a zero on the assignment.

After having followed the instructions for cloning the Git repositoryover SSH, you will see the following files:

Vertex.hpp
Vertex.cpp
Defines a single vertex in the graph.
Edge.hpp
Edge.cpp
Defines a single weighted edge in the graph in terms of cost and speed.
UndirectedGraph.hpp
UndirectedGraph.cpp
Defines an undirected graph made up of a set of vertices and edges.
netplan.cpp Handle parsing the input, and solving the set of problems.
Makefile GNU Make input file for automating compilation.
refnetplan Reference binary for verifying your program's correctness.
generator.py Python program for generating random graphs to assist with unit testing.

Return to Top of Page

Essence of the Assignment


You will write a program netplan that will be invoked from the command-line as follows:

./netplan infile

where infile will contain a set of line-delimited data about a network connection.

Each line will contain four columns: two strings followed by two integers, all separated by whitespace. Use formatted read from file because there maybe whitespaces before the first column as well. The strings represent a company or organization; the first integer is the cost (in millions of dollars) of laying a fiber link between the two companies, thereby connecting them; the second integer is the time (in milliseconds) needed to send a packet between the two companies over the fiber link.

Here is a sample input file:

Network Point A Network Point B Cost
(millions of dollars)
Latency
(milliseconds)
ibm.com yahoo.com 20 33
yahoo.com ucsd.edu 19 40
ucsd.edu ibm.com 10 17
yahoo.com fsf.org 5 10

NOTE: The header row will not be present in the input file, it is displayed here to assist with the explanation.

Your program will read the input file, creating a graph of the data, and use the various algorithms discussed to calculate six pieces of information, which will then be output (to stdout), one answer per line, in the form of an integer.

Requirement for final submission

For the final submission, the information to be output is the following:

  1. The total cost of building all of the possible network links. This is the sum of all the values in column three of your input data.
  2. The total cost of building the cheapest network that will permit packets to travel from any computer to any other. This is generated by first creating a minimum spanning tree where the edges connecting links are chosen based on the cheapest edge. Then summing all the edge costs of the tree.
  3. The amount of money saved by building the minimum-cost network instead of the all-possible-links network. This is the difference between your output from line two and line one.
  4. The total transit time to send a packet between all pairs of computers if all possible network links were built. This requires running Dijkstra's algorithm to find the shortest path from every node in the graph to every other node. For example, ibm.com to yahoo.com, ibm.com to ucsd.edu, ibm.com to fsf.org, yahoo.com to ibm.com, yahoo.com to ucsd.edu, etc. Note, this is solved using the all-possible-links graph, not the MST from line two.
  5. The total transit time it would take to send a packet between all pairs of computers in the minimum-cost network. This is the same as above, except on the graph generated from the MST from line two.
  6. The increase in the "total time" required for packet travel in the cheap network (compared to having built all possible links). This is the difference between your solution to line five and line four.

For example, with the above input file, a correct program will output:

54
34
20
386
482
96

This indicates that cost of the all links network is $54 million; the cost of the cheapest network is $34 million; the cheapest network saves $20 million ($54 - $34); the total transit time if all network links were used would be the sum of sending a packet from one location to every other location, totaling 386 milliseconds; the total transit time for the cheapest network would be 482 milliseconds; and that the cheaper network would be 96 milliseconds slower than the all-links network.

Requirement for the checkpoint submission

For the checkpoint submission, you should complete the part of the assignment that builds the graph representation from the input file and outputs the first line of analysis—the cost of building all possible links. Submit your files before the deadline with the commit message "CHECKPOINT SUBMISSION". We will grade these submissions for correctness.

Note that this submmission represents the BARE MINIMUM you should have completed by the checkpoint deadline. You should strive to be well beyond this point before the checkpoint deadline (i.e., try to submit your checkpoint code early). If you're done early with the part that you need to submit before the checkpoint deadline, you should move on and try to complete the rest of the project as soon as possible.

Your output will be tested automatically by a script, so make sure you do not output anything but those numbers, each on its own line.

NOTE: The input files used when testing/grading your project will contain only valid input. You can safely assume each network connection will be a single line; that all lines will contain all four pieces of information; and that all company names will not contain whitespace.

Return to Top of Page

Getting Started


Note: For this assignment, you do not need to use the starter files. You are free to create your own classes and come up with your own design. Whichever decision you make, you should not skip over this section.

Decompose the problem! An object-oriented design suggests that you should define the classes UndirectedGraph, Vertex, and Edge. Think about what attributes (member variables) and behavior (member methods) the class should support. Once this step is complete, proceed to write the .hpp header file defining the interface of the class. Then implement the definitions for all methods inside a separate .cpp file. Remember to wrap your .hpp files with header guards. Simple one-line getter/setter type methods can be defined inside the .hpp file if you prefer.

Your executable program will then use an instance of your Graph class to do its work. A procedural decomposition of the program might have these parts:

  1. Create a graph, initially empty. You will no doubt need some supporting data structures as well. Your implementation should not make any assumptions about the maximum number of edges and vertices that can be present.
  2. Open the input file for reading. You can assume that the input file is in the format described above.
  3. Read lines from the input file and add appropriate vertices and edges in the associated graph G. Note that because network links are bidirectional, the input graph is undirected: if there is a link from machine A to machine B, that means there is necessarily also a link from B to A (with the same cost and transit time).
  4. Close the input file.
  5. Output the total cost of edges in G.
  6. Find a minimum cost spanning tree of G, say M. Output the total cost of edges in M, and the difference between the total cost of edges in G and in M. (Note that the difference will never be negative.)
  7. Apply Dijkstra's algorithm repeatedly in both M and G to find the minimum time path between each pair of vertices. (Alternatively, you could use the Floyd-Warshall algorithm, however, it will not be covered in lecture). Output the total time for all such pairs for G, for M, and the difference between them. (Note that the difference will never be negative.)

Return to Top of Page

Unit Testing


You are strongly encouraged to test your data structures BEFORE proceeding to solve the final part of the assignment. Individual test cases should be written to ensure each public class method works as intended. Be especially mindful of edge/corner cases.

If you are working with a partner, one suggestion is for one person to work on the tests and the other to implement the data structure.

A strategy for this is to first define the class, stubbing out all the methods. Stubbing the methods means do not implement them yet. If a method returns void, then create the method with an empty body. If a method needs to return an int, pointer, or something else, place only the appropriate return statement in the method body. For example, return -1, return nullptr, or whatever is appropriate. This allows your code to be compiled.

Having done this, the person working on tests can at least call your methods and compile the tests against them. At this point, all tests should fail since nothing is implemented yet. As you complete various methods in the class, the tester can then test these modules one at at time. As more functionality is introduced, test everything again.

This should also help you understand how each method needs to work.

For generating sample input to help with testing, a python program has been provided as part of the starter code, generator.py. This program generates random networks with a given number of vertices and edges. However, you will still need to construct some careful graphs to test edge cases. For example, an empty graph, a complete graph, graph with all edge weights equal, etc.

Return to Top of Page

Turning in your assignment


When you have completed the assignment, you must submit it. Accomplishing this requires pushing your changes to GitLab by following these steps:

  1. Make sure your repository is created in the right namespace: cse100-sp15

    If you do not create your repository in the right namespace you will lose your checkpoint grade

  2. Run git status to see what files have been changed.
  3. Use git add [files] to stage certain files for a commit
  4. For the checkpoint submission, use git commit -m "CHECKPOINT SUBMISSION" to indicate that this is your checkpoint submission.
  5. For the Final submission, use git commit -m "FINAL SUBMISSION" to commit the changes to your repository and indicate that you are done and this is your final submission.
  6. To push your changes to your repository on GitLab run git push origin master Don't forget this push both for the checkpoint and sinal submissions! You must do this to get credit.
  7. As an added safety check, you should log on to GitLab on the web and verify that your push went through.

Some points to keep in mind:

Return to Top of Page

Grading


There are 25 possible points on the assignment. If your solution files do not compile and link error-free, you will receive 0 points for this assignment. We will compile the files you turn in with the command make netplan.

To get credit for your program, it should compile, and it should spend less than 10 seconds (on ieng6) on any 1000-edge graph (meaning up to 1001 vertices) with a unique minimum-cost spanning tree. Recall that a graph has a unique minimum-cost spanning tree if each edge has a different weight. Your program should also be able to handle (not crash)for graphs with 1000 vertices and 100000 edges, although there are no run time requirements that you need to meet for these larger graphs. To get full credit, style and comments count.

Point Distribution:

Return to Top of Page