First, download and unzip the starter code for this assignment homework5.zip.

As in past assignments, your program will read a file as input and produce some output. The format of this input file is described in Part 2, Problem 5. The output format is further described in the next section.

Output Format

By the end of the assignment, running social_network.py must produce output following this exact format:

Problem 4:

Unchanged Recommendations: ['____', '____', ...]
Changed Recommendations: ['____', '____', ...]

Problem 6:

...
____ (by num_common_friends): [____, ____, ...]
____ (by num_common_friends): [____, ____, ...]
____ (by num_common_friends): [____, ____, ...]
...

Problem 7:

...
____ (by influence): [____, ____, ...]
____ (by influence): [____, ____, ...]
____ (by influence): [____, ____, ...]
...

Problem 8:

Same: ____
Different: ____

Example output that your program should produce, with ... and ____ used as placeholders for actual numbers.

Ellipses (...) indicate that there may be more of these lines, and underscores (____) should be replaced by values that you will calculate. For Problems 6 and 7, each line may have a different number of values than what is shown above, and you will be printing more than 3 lines of output - these are just examples. Of course, the exact values in each category will vary depending on the input data that you are using.

Important

We expect the formatting of your program output to exactly match this.

NetworkX

The NetworkX library helps us represent graphs in Python. Make sure you understand the examples from the lecture slides on graphs. Skim through the NetworkX tutorial, up to and including the What to use as nodes and edges section. Be sure you understand add_edge(), add_node(), edges(), nodes(), and neighbors(). The tutorial discusses more operations than you need to know. Do not worry if you do not understand all the details in the tutorial (e.g., you can ignore “nbunches” and “ebunches”). You may also want to browse the Drawing graphs section.

As seen on the lecture slides on graphs, to use the NetworkX library in a program, you mus write import networkx or import networkx as nx near the top of your program. The latter has already been done for you in the supplied social_network.py, so you can use shorter commands like nx.draw_networkx(...) instead of the (slightly longer) networkx.draw_networkx(...). There is nothing to turn in for this step. In Problem 1, you will verify that NetworkX is working properly by drawing a simple graph.

Troubleshooting NetworkX

If you get the error:

ImportError: No module named networkx

you may not be running the correct version of Python or you may not have activated the cse160 Anaconda environment. Other distributions of Python do not necessarily include the NetworkX library, which means they cannot be used for this assignment. Please post on the discussion board or email the course staff if you need help debugging this problem.