Skip to content

Commit a09f7ed

Browse files
authored
Refactor Counter class (#364)
1 parent 5a84612 commit a09f7ed

19 files changed

+205
-688
lines changed

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
include README.md
22
include LICENSE
3-
include requirements.txt
43
include CMakeLists.txt
54
include Doxyfile
65
recursive-include src *

benchmark/Bench_Dynamics.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ static const auto DATA_FOLDER =
88
std::filesystem::path(__FILE__).parent_path().parent_path() / "test/data";
99

1010
static void BM_FirstOrderDynamics_Empty_Evolve(benchmark::State& state) {
11-
dsf::mobility::RoadNetwork network;
12-
network.importEdges((DATA_FOLDER / "forlì_edges.csv").string());
13-
network.importNodeProperties((DATA_FOLDER / "forlì_nodes.csv").string());
14-
dsf::mobility::FirstOrderDynamics dynamics(network);
15-
for (auto _ : state) {
16-
dynamics.evolve();
17-
}
11+
dsf::mobility::RoadNetwork network;
12+
network.importEdges((DATA_FOLDER / "forlì_edges.csv").string());
13+
network.importNodeProperties((DATA_FOLDER / "forlì_nodes.csv").string());
14+
dsf::mobility::FirstOrderDynamics dynamics(network);
15+
for (auto _ : state) {
16+
dynamics.evolve();
17+
}
1818
}
1919

2020
BENCHMARK(BM_FirstOrderDynamics_Empty_Evolve);

benchmark/Bench_Network.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,35 @@ static void BM_RoadNetwork_GeoJSONImport(benchmark::State& state) {
3636
}
3737
}
3838
static void BM_RoadNetwork_NodesLooping(benchmark::State& state) {
39-
dsf::mobility::RoadNetwork network;
40-
network.importEdges((DATA_FOLDER / "forlì_edges.csv").string());
41-
network.importNodeProperties((DATA_FOLDER / "forlì_nodes.csv").string());
42-
for (auto _ : state) {
43-
for (auto const& [id, node] : network.nodes()) {
44-
benchmark::DoNotOptimize(id);
45-
benchmark::DoNotOptimize(node);
46-
}
39+
dsf::mobility::RoadNetwork network;
40+
network.importEdges((DATA_FOLDER / "forlì_edges.csv").string());
41+
network.importNodeProperties((DATA_FOLDER / "forlì_nodes.csv").string());
42+
for (auto _ : state) {
43+
for (auto const& [id, node] : network.nodes()) {
44+
benchmark::DoNotOptimize(id);
45+
benchmark::DoNotOptimize(node);
4746
}
47+
}
4848
}
4949
static void BM_RoadNetwork_EdgesLooping(benchmark::State& state) {
50-
dsf::mobility::RoadNetwork network;
51-
network.importEdges((DATA_FOLDER / "forlì_edges.csv").string());
52-
network.importNodeProperties((DATA_FOLDER / "forlì_nodes.csv").string());
53-
for (auto _ : state) {
54-
for (auto const& [id, edge] : network.edges()) {
55-
benchmark::DoNotOptimize(id);
56-
benchmark::DoNotOptimize(edge);
57-
}
50+
dsf::mobility::RoadNetwork network;
51+
network.importEdges((DATA_FOLDER / "forlì_edges.csv").string());
52+
network.importNodeProperties((DATA_FOLDER / "forlì_nodes.csv").string());
53+
for (auto _ : state) {
54+
for (auto const& [id, edge] : network.edges()) {
55+
benchmark::DoNotOptimize(id);
56+
benchmark::DoNotOptimize(edge);
5857
}
58+
}
5959
}
6060
static void BM_RoadNetwork_ShortestPath(benchmark::State& state) {
6161
dsf::mobility::RoadNetwork network;
6262
network.importEdges((DATA_FOLDER / "forlì_edges.csv").string());
6363
network.importNodeProperties((DATA_FOLDER / "forlì_nodes.csv").string());
6464
auto itNode = network.nodes().cbegin();
6565
for (auto _ : state) {
66-
auto paths = network.allPathsTo(itNode->first, [](auto const& pEdge) { return pEdge->length(); });
66+
auto paths = network.allPathsTo(itNode->first,
67+
[](auto const& pEdge) { return pEdge->length(); });
6768
++itNode;
6869
}
6970
}

benchmark/Bench_Street.cpp

Lines changed: 32 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,8 @@
55

66
static void BM_Street_Construction(benchmark::State& state) {
77
for (auto _ : state) {
8-
dsf::mobility::Street street(0,
9-
{0, 1},
10-
100.0,
11-
13.8888888889,
12-
2,
13-
"test",
14-
{},
15-
std::nullopt,
16-
1.0);
8+
dsf::mobility::Street street(
9+
0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, std::nullopt, 1.0);
1710
benchmark::DoNotOptimize(street);
1811
}
1912
}
@@ -36,15 +29,7 @@ static void BM_Street_AddAgent(benchmark::State& state) {
3629
}
3730

3831
static void BM_Street_Enqueue(benchmark::State& state) {
39-
dsf::mobility::Street street(0,
40-
{0, 1},
41-
100.0,
42-
13.8888888889,
43-
2,
44-
"test",
45-
{},
46-
100,
47-
1.0);
32+
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
4833
std::time_t spawnTime = 0;
4934
for (int i = 0; i < 50; ++i) {
5035
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
@@ -60,15 +45,7 @@ static void BM_Street_Enqueue(benchmark::State& state) {
6045
}
6146

6247
static void BM_Street_Dequeue(benchmark::State& state) {
63-
dsf::mobility::Street street(0,
64-
{0, 1},
65-
100.0,
66-
13.8888888889,
67-
2,
68-
"test",
69-
{},
70-
100,
71-
1.0);
48+
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
7249
std::time_t spawnTime = 0;
7350
for (int i = 0; i < 50; ++i) {
7451
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
@@ -85,20 +62,13 @@ static void BM_Street_Dequeue(benchmark::State& state) {
8562
}
8663

8764
static void BM_Street_nAgents(benchmark::State& state) {
88-
dsf::mobility::Street street(0,
89-
{0, 1},
90-
100.0,
91-
13.8888888889,
92-
2,
93-
"test",
94-
{},
95-
100,
96-
1.0);
65+
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
9766
std::time_t spawnTime = 0;
9867
for (int i = 0; i < 50; ++i) {
9968
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
10069
street.addAgent(std::move(agent));
101-
if (i % 2 == 0) street.enqueue(0);
70+
if (i % 2 == 0)
71+
street.enqueue(0);
10272
}
10373
for (auto _ : state) {
10474
int n = street.nAgents();
@@ -107,20 +77,13 @@ static void BM_Street_nAgents(benchmark::State& state) {
10777
}
10878

10979
static void BM_Street_Density(benchmark::State& state) {
110-
dsf::mobility::Street street(0,
111-
{0, 1},
112-
100.0,
113-
13.8888888889,
114-
2,
115-
"test",
116-
{},
117-
100,
118-
1.0);
80+
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
11981
std::time_t spawnTime = 0;
12082
for (int i = 0; i < 50; ++i) {
12183
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
12284
street.addAgent(std::move(agent));
123-
if (i % 2 == 0) street.enqueue(0);
85+
if (i % 2 == 0)
86+
street.enqueue(0);
12487
}
12588
for (auto _ : state) {
12689
double d = street.density(false);
@@ -129,15 +92,7 @@ static void BM_Street_Density(benchmark::State& state) {
12992
}
13093

13194
static void BM_Street_nMovingAgents(benchmark::State& state) {
132-
dsf::mobility::Street street(0,
133-
{0, 1},
134-
100.0,
135-
13.8888888889,
136-
2,
137-
"test",
138-
{},
139-
100,
140-
1.0);
95+
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
14196
std::time_t spawnTime = 0;
14297
for (int i = 0; i < 50; ++i) {
14398
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
@@ -150,15 +105,7 @@ static void BM_Street_nMovingAgents(benchmark::State& state) {
150105
}
151106

152107
static void BM_Street_nExitingAgents(benchmark::State& state) {
153-
dsf::mobility::Street street(0,
154-
{0, 1},
155-
100.0,
156-
13.8888888889,
157-
2,
158-
"test",
159-
{},
160-
100,
161-
1.0);
108+
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
162109
std::time_t spawnTime = 0;
163110
for (int i = 0; i < 50; ++i) {
164111
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
@@ -172,86 +119,47 @@ static void BM_Street_nExitingAgents(benchmark::State& state) {
172119
}
173120

174121
static void BM_Street_SetLaneMapping(benchmark::State& state) {
175-
dsf::mobility::Street street(0,
176-
{0, 1},
177-
100.0,
178-
13.8888888889,
179-
3,
180-
"test",
181-
{},
182-
std::nullopt,
183-
1.0);
122+
dsf::mobility::Street street(
123+
0, {0, 1}, 100.0, 13.8888888889, 3, "test", {}, std::nullopt, 1.0);
184124
std::vector<dsf::Direction> laneMapping = {
185-
dsf::Direction::RIGHTANDSTRAIGHT,
186-
dsf::Direction::STRAIGHT,
187-
dsf::Direction::LEFT};
125+
dsf::Direction::RIGHTANDSTRAIGHT, dsf::Direction::STRAIGHT, dsf::Direction::LEFT};
188126
for (auto _ : state) {
189127
street.setLaneMapping(laneMapping);
190128
}
191129
}
192130

193131
static void BM_StochasticStreet_SetFlowRate(benchmark::State& state) {
194-
dsf::mobility::Street baseStreet(0,
195-
{0, 1},
196-
100.0,
197-
13.8888888889,
198-
2,
199-
"test",
200-
{},
201-
std::nullopt,
202-
1.0);
132+
dsf::mobility::Street baseStreet(
133+
0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, std::nullopt, 1.0);
203134
dsf::mobility::StochasticStreet street(std::move(baseStreet), 0.5);
204135
for (auto _ : state) {
205136
street.setFlowRate(0.8);
206137
}
207138
}
208139

209140
static void BM_StochasticStreet_FlowRate(benchmark::State& state) {
210-
dsf::mobility::Street baseStreet(0,
211-
{0, 1},
212-
100.0,
213-
13.8888888889,
214-
2,
215-
"test",
216-
{},
217-
std::nullopt,
218-
1.0);
141+
dsf::mobility::Street baseStreet(
142+
0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, std::nullopt, 1.0);
219143
dsf::mobility::StochasticStreet street(std::move(baseStreet), 0.5);
220144
for (auto _ : state) {
221145
double fr = street.flowRate();
222146
benchmark::DoNotOptimize(fr);
223147
}
224148
}
225149

226-
static void BM_SpireStreet_AddAgent(benchmark::State& state) {
227-
dsf::mobility::Street baseStreet(0,
228-
{0, 1},
229-
100.0,
230-
13.8888888889,
231-
2,
232-
"test",
233-
{},
234-
100,
235-
1.0);
236-
dsf::mobility::SpireStreet street(std::move(baseStreet));
150+
static void BM_CoilStreet_AddAgent(benchmark::State& state) {
151+
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
152+
street.enableCounter();
237153
std::time_t spawnTime = 0;
238154
for (auto _ : state) {
239155
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
240156
street.addAgent(std::move(agent));
241157
}
242158
}
243159

244-
static void BM_SpireStreet_MeanFlow(benchmark::State& state) {
245-
dsf::mobility::Street baseStreet(0,
246-
{0, 1},
247-
100.0,
248-
13.8888888889,
249-
2,
250-
"test",
251-
{},
252-
100,
253-
1.0);
254-
dsf::mobility::SpireStreet street(std::move(baseStreet));
160+
static void BM_CoilStreet_MeanFlow(benchmark::State& state) {
161+
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
162+
street.enableCounter();
255163
std::time_t spawnTime = 0;
256164
for (int i = 0; i < 50; ++i) {
257165
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
@@ -262,22 +170,14 @@ static void BM_SpireStreet_MeanFlow(benchmark::State& state) {
262170
}
263171
}
264172
for (auto _ : state) {
265-
int flow = street.meanFlow();
173+
auto flow = street.counts();
266174
benchmark::DoNotOptimize(flow);
267175
}
268176
}
269177

270-
static void BM_SpireStreet_Dequeue(benchmark::State& state) {
271-
dsf::mobility::Street baseStreet(0,
272-
{0, 1},
273-
100.0,
274-
13.8888888889,
275-
2,
276-
"test",
277-
{},
278-
100,
279-
1.0);
280-
dsf::mobility::SpireStreet street(std::move(baseStreet));
178+
static void BM_CoilStreet_Dequeue(benchmark::State& state) {
179+
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
180+
street.enableCounter();
281181
std::time_t spawnTime = 0;
282182
for (int i = 0; i < 50; ++i) {
283183
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
@@ -304,8 +204,8 @@ BENCHMARK(BM_Street_nExitingAgents);
304204
BENCHMARK(BM_Street_SetLaneMapping);
305205
BENCHMARK(BM_StochasticStreet_SetFlowRate);
306206
BENCHMARK(BM_StochasticStreet_FlowRate);
307-
BENCHMARK(BM_SpireStreet_AddAgent);
308-
BENCHMARK(BM_SpireStreet_MeanFlow);
309-
BENCHMARK(BM_SpireStreet_Dequeue);
207+
BENCHMARK(BM_CoilStreet_AddAgent);
208+
BENCHMARK(BM_CoilStreet_MeanFlow);
209+
BENCHMARK(BM_CoilStreet_Dequeue);
310210

311211
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)