A network analyser
The problem
Model a small network of towns as a graph and answer questions about it: its degrees, its connected parts, the fewest hops between two towns and whether a route exists that uses every road exactly once.
Requirements
- Store the network as an adjacency list read from a list of roads
- Report the degree of each town and check the handshake lemma
- Use BFS to find the components and the shortest route between two towns
- Decide whether an Euler path or circuit exists from the degrees
Technologies
- Python 3
- Dictionaries and lists
- collections.deque
- Graph theory: degrees, components, Euler paths
Step by step
- Parse the roads and build the adjacency list.
- Compute the degrees and the sum, and compare the sum with twice the number of roads.
- Write BFS for components and for the shortest path with parents.
- Add the Euler test and run the analyser on three networks of your own, including a disconnected one.
Expected result
A report on a small network: degrees, components, shortest routes and the Euler verdict, checked against hand calculations.
How it is evaluated
- The handshake lemma holds on every network tried
- Component sizes add up to the number of towns
- The shortest route has the fewest roads and is rebuilt from the parents
- The Euler verdict matches the number of odd-degree towns
Ways to improve it
- Add road lengths and look for the shortest route by distance
- Colour the towns greedily and compare with the chromatic number of a small network
- Draw the network with a plotting library