Skip to content

Commit 838c51e

Browse files
authored
Improve visualization tools (#215)
* Update examples * Add new coordinates.csv in data * Update Python scripts * Improve CLI * Add basemap * Fix mac problem * Improving drawing * Better time labelling * Working multiprocess * Formatting * Adjusting sizes * Improved cli * Improved docs * Update requirements file * Remove versions * Build examples in release to take less time
1 parent 430d94e commit 838c51e

File tree

9 files changed

+266
-79
lines changed

9 files changed

+266
-79
lines changed

.github/workflows/cmake_examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
branches: [ "main" ]
88

99
env:
10-
BUILD_TYPE: Debug
10+
BUILD_TYPE: Release
1111

1212
jobs:
1313
build:

examples/data/coordinates.csv

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
nodeId;lat;lon
2+
119;110;90
3+
118;100;90
4+
117;90;90
5+
116;80;90
6+
115;70;90
7+
114;60;90
8+
113;50;90
9+
112;40;90
10+
111;30;90
11+
110;20;90
12+
109;10;90
13+
108;0;90
14+
107;110;80
15+
106;100;80
16+
105;90;80
17+
104;80;80
18+
103;70;80
19+
102;60;80
20+
101;50;80
21+
100;40;80
22+
99;30;80
23+
98;20;80
24+
97;10;80
25+
96;0;80
26+
95;110;70
27+
94;100;70
28+
93;90;70
29+
92;80;70
30+
91;70;70
31+
90;60;70
32+
89;50;70
33+
88;40;70
34+
87;30;70
35+
86;20;70
36+
85;10;70
37+
84;0;70
38+
83;110;60
39+
82;100;60
40+
81;90;60
41+
80;80;60
42+
79;70;60
43+
78;60;60
44+
77;50;60
45+
76;40;60
46+
75;30;60
47+
74;20;60
48+
73;10;60
49+
72;0;60
50+
71;110;50
51+
70;100;50
52+
69;90;50
53+
68;80;50
54+
67;70;50
55+
66;60;50
56+
65;50;50
57+
64;40;50
58+
63;30;50
59+
62;20;50
60+
61;10;50
61+
60;0;50
62+
59;110;40
63+
28;40;20
64+
27;30;20
65+
26;20;20
66+
25;10;20
67+
24;0;20
68+
23;110;10
69+
22;100;10
70+
11;110;0
71+
21;90;10
72+
10;100;0
73+
20;80;10
74+
9;90;0
75+
19;70;10
76+
8;80;0
77+
18;60;10
78+
7;70;0
79+
0;0;0
80+
13;10;10
81+
1;10;0
82+
14;20;10
83+
12;0;10
84+
2;20;0
85+
15;30;10
86+
3;30;0
87+
16;40;10
88+
4;40;0
89+
17;50;10
90+
5;50;0
91+
6;60;0
92+
29;50;20
93+
30;60;20
94+
31;70;20
95+
32;80;20
96+
33;90;20
97+
34;100;20
98+
35;110;20
99+
36;0;30
100+
37;10;30
101+
38;20;30
102+
39;30;30
103+
40;40;30
104+
41;50;30
105+
42;60;30
106+
43;70;30
107+
44;80;30
108+
45;90;30
109+
46;100;30
110+
47;110;30
111+
48;0;40
112+
49;10;40
113+
50;20;40
114+
51;30;40
115+
52;40;40
116+
53;50;40
117+
54;60;40
118+
55;70;40
119+
56;80;40
120+
57;90;40
121+
58;100;40

examples/slow_charge_rb.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ int main(int argc, char** argv) {
114114
for (const auto& [nodeId, node] : graph.nodeSet()) {
115115
auto& rb = dynamic_cast<Roundabout&>(*node);
116116
rb.setCapacity(degreeVector(nodeId));
117+
rb.setTransportCapacity(degreeVector(nodeId));
117118
}
118119
std::cout << "Done." << std::endl;
119120

@@ -189,7 +190,7 @@ int main(int argc, char** argv) {
189190
// std::vector<int> deltas;
190191

191192
// lauch progress bar
192-
std::thread t([]() {
193+
std::jthread t([]() {
193194
while (progress < MAX_TIME && !bExitFlag) {
194195
printLoadingBar(progress, MAX_TIME);
195196
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
@@ -302,7 +303,6 @@ int main(int argc, char** argv) {
302303
// std::cout << "Probability of turning " << std::quoted(turnNames[i]) << ": " << value * 100 << "%\n";
303304
// ++i;
304305
// }
305-
t.join();
306306
std::cout << '\n';
307307
std::cout << "Done." << std::endl;
308308

examples/slow_charge_tl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ int main(int argc, char** argv) {
174174
for (const auto& [nodeId, node] : graph.nodeSet()) {
175175
auto& tl = dynamic_cast<TrafficLight&>(*node);
176176
tl.setCapacity(degreeVector(nodeId));
177+
tl.setTransportCapacity(degreeVector(nodeId));
177178
double value = -1.;
178179
while (value < 0.) {
179180
value = random();
@@ -292,7 +293,7 @@ int main(int argc, char** argv) {
292293
// std::vector<int> deltas;
293294

294295
// lauch progress bar
295-
std::thread t([]() {
296+
std::jthread t([]() {
296297
while (progress < MAX_TIME && !bExitFlag) {
297298
printLoadingBar(progress, MAX_TIME);
298299
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
@@ -449,7 +450,6 @@ int main(int argc, char** argv) {
449450
// std::cout << "Probability of turning " << std::quoted(turnNames[i]) << ": " << value * 100 << "%\n";
450451
// ++i;
451452
// }
452-
t.join();
453453
std::cout << '\n';
454454
std::cout << "Done." << std::endl;
455455

examples/stalingrado.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int main() {
9494
auto& spire = dynamic_cast<SpireStreet&>(*dynamics.graph().streetSet().at(19));
9595

9696
// lauch progress bar
97-
std::thread t([MAX_TIME]() {
97+
std::jthread t([MAX_TIME]() {
9898
while (progress < MAX_TIME) {
9999
printLoadingBar(progress, MAX_TIME);
100100
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
@@ -118,7 +118,6 @@ int main() {
118118
dynamics.evolve(false);
119119
++progress;
120120
}
121-
t.join();
122121

123122
return 0;
124123
}

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
contextily
2+
geopandas
13
matplotlib
24
networkx
35
numpy

utils/functions.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@
33
"""
44

55
import networkx as nx
6+
import pandas as pd
67

78

8-
def create_graph_from_adj(adj: list, coord: list):
9-
"""Creates a graph given adjacency matrix and a list of coordinates"""
9+
def create_graph_from_adj(adj: list, coord: pd.DataFrame):
10+
"""Creates a graph given adjacency matrix and a dataframe of coordinates"""
1011
n = len(adj)
1112
graph = nx.DiGraph()
1213
graph.add_nodes_from(range(n))
1314
for i in range(n):
14-
for j in range(i + 1, n):
15+
for j in range(n):
1516
if adj[i, j] > 0:
1617
graph.add_edge(i, j, color="g", weight=adj[i, j])
1718
graph.add_edge(j, i, color="g", weight=adj[j, i])
1819
edges = graph.edges()
1920
pos = {}
20-
for i in range(n):
21-
pos[i] = coord[i, :]
21+
# coord has id as index with lat, lon columns
22+
for node in graph.nodes():
23+
pos[node] = (coord.loc[node]["lon"], coord.loc[node]["lat"])
2224

2325
return (graph, edges, pos)

0 commit comments

Comments
 (0)