CSE100
Project #3
Due: 2008-11-13 THURSDAY 11:59:00PM PDT.



Update 11/5/08 by Cynthia Lee:


Social Networking


We have gathered a small fragment of a social network from the popular service, NerdBook.  In addition to the usual "X and Y are friends" functionality, NerdBook allows its users to specify how well they get along with each-other.  This works by having each pair of friends to set a disagreement score. The disagreement score is a non-negative number, where 0 indicates total agreement, and larger values indicate more disagreement between the two friends.

This information is encoded in the form of a weighted, undirected graph over the users of the service.  We provide this information to you in the form of two text files in the public directory:
  1. nodes.txt contains the names of the users, one per line
  2. edges.txt contains the edges of the graph, one per line, e.g.
0 21 4.973
4 9 0.55
indicates that the first user (index 0, the first row in nodes.txt) shares an edge with user 21 (22nd row in nodes.txt), and their disagreement score is 4.973.  Similarly, user index 4 shares an edge with user index 9, with disagreement score 0.55. 

Note that these indices are only there to help with reading the file, and should not appear anywhere in your graph implementation!

Your program will use this information to construct a graph and solve a few socially-oriented problems.


Graph Data Structure

The first step is to implement a generic-typed graph class: Graph<E>, where E is the type of data stored in the vertices.  Your Graph class should contain the following:

Your Graph class must also support the following operations:


Graph Algorithms

In addition to the basic graph operations described above, your Graph structure must also implement the following graph algorithms:


Application

Having implemented the algorithms described above, you must write a program which solves the following problems:
  1. To prevent spam, NerdBook only allows you to send messages to your friends. You will design a way to work around this limitation by sending messages from friend to friend to reach people who are not directly the sender's friends. You would like to do this in as few steps as possible, so that the fewest people will be bothered with having to forward the message. So person X wants to send a message to a person Y using the smallest number of intermediate people possible. Determine the shortest sequence of people to transmit the message from X to Y.

    For each person X in the graph, print out their shortest sequence to each other person Y.  Your output should look something like:
    Samuel Baden -> Alin Bafna
    Samuel Baden -> Alin Bafna -> Jim Bellare
    Samuel Baden -> Alin Bafna -> Dana Cottrell
    ...
    (the exact edges may be different in the actual graph).

  2. A person X wants to interview for a job with person Y.  X wants to get her foot in the door with a personal recommendation, but may not directly know person Y, and thus wants to find a chain of recommendations to Y.  Find the chain from X to Y with the minimal cumulative disagreement score. Cumulative disagreement means the sum of the disagreements scores along the path from X to Y.

    Again, for each person X in the graph, print out their minimal cumulative disagreement score path to each other person Y.

  3. NerdBook provides a "People you may know" feature. For a given person X, return the top five (or up to five, if fewer than five exist) people in NerdBook who have the smallest cumulative disagreement, but are not currently friends with X. Order the top five people according to cumulative disagreement, smallest first (use sorted list or priority queue).

    Print out each person X along with their top five recommended friends.

  4. You want to measure the amount of group cohesion within the network.  Do this by finding a subset of the edges in which all nodes are connected, and the total amount of disagreement is minimized. Report the total amount of disagreement. 


Your program should operate as follows:
    java NerdBook <message|interview|recommender|cohesion>

where the parameter indicates which of the four problems described above is to be solved.

Guidelines



Turning in

When your program is finished, create a tar file including your source code and class files by running:

    tar czvf LASTNAME1.LASTNAME2.tar.gz *.java *.class README

Then, submit your tar file by running:

    turnin -c cs100f -p p3 LASTNAME1.LASTNAME2.tar.gz