Created
August 3, 2020 11:53
-
-
Save gplssm/51c1dea3ab98339e859d241f0e082b1e to your computer and use it in GitHub Desktop.
Test of Python skills with an example of graph analysis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node1 | node2 | |
---|---|---|
Source | 1 | |
2 | 3 | |
1 | 2 | |
3 | 10 | |
10 | Target | |
1 | 4 | |
4 | 5 | |
5 | Target | |
1 | 6 | |
6 | 7 | |
5 | 7 | |
4 | 8 | |
6 | 12 | |
12 | 16 | |
16 | 14 | |
16 | 11 | |
11 | Target | |
14 | Target | |
8 | Target | |
7 | 9 | |
9 | 5 | |
1 | 13 | |
13 | 15 | |
15 | 11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
label | x | y | |
---|---|---|---|
Source | 0 | 5 | |
1 | 1 | 5 | |
2 | 2 | 3 | |
3 | 6 | 2 | |
4 | 4 | 5 | |
5 | 8 | 7 | |
6 | 2 | 7 | |
7 | 3 | 8 | |
8 | 5 | 3 | |
9 | 6 | 8 | |
10 | 9 | 3 | |
11 | 7 | 4 | |
12 | 4 | 7 | |
13 | 3 | 4 | |
14 | 8 | 6 | |
15 | 4 | 3 | |
16 | 5 | 6 | |
Target | 10 | 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given is a route network defined by nodes (nodes.csv) and edges (edges.csv) | |
- the nodes have a positions defined by x,y-coordinates | |
- edges describe how nodes are connected | |
- a route is a combination of edges connecting "Source" and "Target" via intermediate nodes | |
Please calculate distances for all possible routes from "Source" to "Target" and sort them in descending order. | |
Save the routes and the total distances (one per line) in a CSV file. Make sure the result is reproducible. | |
Hints: | |
- the length of an edge can be calculated from the node's positions | |
- the length of a route is the sum of distances between each pair of nodes that are part of this route | |
- we recommend to use NetworkX, Pandas and maybe Matplotlib | |
- it's worth to read the NetworkX docs (https://networkx.github.io/documentation/stable/index.html), it provides useful graph algorithms | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment