Fall Semester 2005: September 8, 2005 - December 12, 2005
Out on:
October 13, 2005
Due by:
October 20, 2005 by 5:59 pm for full credit (11:59 pm for 10% off, hard deadline)
Collaboration:
None
Grading:
Packaging 10%, Style 10%, Performance 10%, Design 20%, Functionality 50%
The sixth assignment for
600.226: Data Structures
deals mostly with graphs.
There are no written problems, but of course you're free to
rant about something in your README file anyway.
Your first task is to write an implementation of the graph interfaces given in the archive below. You are free to choose any data structure that does not limit the number of nodes or edges arbitrarily; so you can obviously use adjacancy lists, but you could also use an adjacancy matrix that "grows" as needed (does not impose a maximum size). You should read Problem 2 before you decide on a certain data structure though, depending on how you implement the graph your program for Problem 2 might show different performance characteristics.
As before you are not allowed to change the
interfaces in any way; if you think something is wrong, email
the discussion list and check.
Aside from the basic implementation, please provide a method
toString() that returns a dot
representation of the graph suitable for rendering using the
Graphviz toolset.
Also, please provide a main() method that performs
basic unit testing for your implementation.
Here are the necessary interfaces and exception classes: graphs.tar.gz
Here is a (partial) data set of trade between countries (the original is here but don't use these files for the assignment). Each line lists the exporting country, the importing country, and the volume of trade (in some abstract quantity).
Your second task is to implement a program Balance
that calculates the trade balance of a country.
The program gets the name of the file to read the data set from
as a command line argument.
The program generates two files (the names for both are the name
of the input file with suitable extensions appended):
A .dot file of the graph, suitable for rendering,
and a .bal file that list the trade balance of
each country (the sum of all exports minus the sum of all imports).
The format of each line in the latter file is
country: balance.
Proceed as follows: Build a directed graph from the data set
using your implementation of graphs from Problem 1; countries
are nodes, exports are edges.
You should store a String with the country's
name in each node as well as a Float with the
volume of exports on each edge.
Write the .dot file for the graph.
Then process the graph by iterating over all vertices; for
each vertex, iterate over all incident edges to compute the
total exports and total imports; write the totals to the
.bal file.
Please turn in a
gzip
compressed
tarball
of your assignment (the extension should be .tar.gz).
The tarball should uncompress into a directory
cs226-assignment-6-login
with login replaced by your Unix login name
(so I would use cs226-assignment-6-phf);
uncompressing should not create any other files
in the current directory.
The tarball should contain no derived files whatsoever
(i.e. no .class files, no .html files, etc.),
but allow building all derived files.
Include a README file that briefly explains what your
programs do and contains any other notes you want us to check out
before grading (and of course your answers to "written" problems).
For reference, here is a short explanation of the grading criteria.
Packaging refers to the proper organization of the
stuff you hand in, following the guidelines for Deliverables above.
Style refers to Java programming style, including
things like consistent indentation, appropriate identifiers,
useful comments, suitable javadoc documentation, etc.
Simple, clean, readable code is what you should be aiming for.
Performance refers to how fast your program can
produce the required results compared to other submissions.
Design refers to proper modularization and the
proper choice of algorithms and data structures.
Functionality refers to your programs being
able to do what they should according to the specification
given above; if the specification is ambiguous and you had
to make a certain choice, defend that choice in your
README file.
If your programs cannot be built you will get no points whatsoever.
If your programs cannot be built without warnings using
javac -Xlint
we will take off 10% (except if you document a very good reason).
If your programs fail miserably even once,
i.e. terminate with an exception of any kind,
we will take off 10%.
Write a customized traversal of the graph from Problem 2 that
generates more appropriate dot output.
Use colors to encode trade balance: Countries with a trade
deficit should be red to varying degrees, those with a trade
surplus should be green.
Use thickness to encode volume of exports: Edges with high
trade volume should be thicker than edges with low trade
volume.
Also, if you're interested in historic trends, here are the corresponding data sets for 1980 and 1970; several curious developments here...