THINK FIRST·CODE LATER

← All labs

Network metrics for bike flows

Problem

Input: a CSV start,end with one row per trip. Aggregate trips into directed links (weight = number of trips), ignoring round trips (start = end) for the graph. Using networkx, print:

stations: 5, links: 9, density: 0.45
busiest stations (trips in + out): C 7, A 6, B 5
highest betweenness: C (0.83)
top flows: A->B 3, A->C 1, B->A 1
round trips (same station): 1
suggested idiom: adjacency matrix (dense network)

Strength = weighted in-degree + out-degree (top 3, ties alphabetical); betweenness on the undirected version (nx.betweenness_centrality, ties → alphabetically first); top 3 flows by weight, ties by start then end; suggest an adjacency matrix if density > 0.3, otherwise a node-link diagram (our rule of thumb).

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

v10-3-data-1.csv

start,end
A,B
A,B
A,B
B,A
B,C
C,D
D,C
C,A
A,C
E,C
C,E
B,B
What your program must print for v10-3-data-1.csv
stations: 5, links: 9, density: 0.45
busiest stations (trips in + out): C 7, A 6, B 5
highest betweenness: C (0.83)
top flows: A->B 3, A->C 1, B->A 1
round trips (same station): 1
suggested idiom: adjacency matrix (dense network)

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), in the folder that holds both files:

python my_lab.py < v10-3-data-1.csv

Windows PowerShell (the default terminal of VS Code on Windows) does not understand <:

Get-Content v10-3-data-1.csv | python my_lab.py

PyCharm: Run → Edit Configurations → tick Redirect input from and choose the file.

Jupyter: put this at the top of the cell that holds your program:

import sys
sys.stdin = open("v10-3-data-1.csv", encoding="utf-8")

Write it here, in Jupyter or in your IDE, then paste it. Run it on the sample input yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.