Skip to content

Commit a92fa72

Browse files
authored
Merge branch 'main' into rework_itineraries
2 parents bce731b + 362e2c5 commit a92fa72

22 files changed

+424
-188
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:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ examples/*.csv
3030
# Utils generated folders
3131
__pycache__
3232
images
33+
examples/debug
34+
examples/release

examples/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ Many of these simulations were used as thesis work.
44

55
To compile all simulations, use cmake inside the *examples* folder:
66
```shell
7-
cmake -B build -DCMAKE_BUILD_TYPE=Release && make -C build
7+
cmake -B release -DCMAKE_BUILD_TYPE=Release && make -C release
8+
```
9+
If anything goes wrong, try to build the example in debug mode:
10+
```shell
11+
cmake -B debug -DCMAKE_BUILD_TYPE=Debug && make -C debug
812
```
913

1014
## Simulation files

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

src/dsm/dsm.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
static constexpr uint8_t DSM_VERSION_MAJOR = 2;
88
static constexpr uint8_t DSM_VERSION_MINOR = 1;
9-
static constexpr uint8_t DSM_VERSION_PATCH = 1;
9+
static constexpr uint8_t DSM_VERSION_PATCH = 7;
1010

1111
#define DSM_VERSION \
1212
std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH)

src/dsm/headers/Dynamics.hpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ namespace dsm {
465465
void Dynamics<Delay>::m_evolveStreet(const Id streetId,
466466
const std::unique_ptr<Street>& pStreet,
467467
bool reinsert_agents) {
468-
for (auto queueIndex = 0; queueIndex < pStreet->nLanes(); ++queueIndex) {
468+
auto const nLanes = pStreet->nLanes();
469+
for (auto queueIndex = 0; queueIndex < nLanes; ++queueIndex) {
469470
if (m_uniformDist(m_generator) > m_maxFlowPercentage ||
470471
pStreet->queue(queueIndex).empty()) {
471472
continue;
@@ -481,18 +482,16 @@ namespace dsm {
481482
}
482483
if (destinationNode->isTrafficLight()) {
483484
auto& tl = dynamic_cast<TrafficLight<Delay>&>(*destinationNode);
484-
if (tl.leftTurnRatio().has_value()) {
485-
auto it = m_agentNextStreetId.find(agentId);
486-
if (it == m_agentNextStreetId.end()) {
487-
if (!tl.isGreen(streetId, 0.)) {
488-
continue;
489-
}
490-
} else {
491-
auto const& nextStreet{m_graph.streetSet()[m_agentNextStreetId[agentId]]};
492-
auto const delta{nextStreet->deltaAngle(pStreet->angle())};
493-
if (!tl.isGreen(streetId, delta)) {
494-
continue;
495-
}
485+
if (tl.leftTurnRatio().has_value() && nLanes > 1 && queueIndex == nLanes - 1) {
486+
if (tl.isGreen(streetId) &&
487+
tl.counter() >
488+
tl.delay().value().first * (1. - tl.leftTurnRatio().value().first)) {
489+
continue;
490+
} else if (!tl.isGreen(streetId) &&
491+
tl.counter() > tl.delay().value().first +
492+
tl.delay().value().second *
493+
(1. - tl.leftTurnRatio().value().second)) {
494+
continue;
496495
}
497496
} else if (!tl.isGreen(streetId)) {
498497
continue;
@@ -1147,10 +1146,7 @@ namespace dsm {
11471146
template <typename Delay>
11481147
requires(is_numeric_v<Delay>)
11491148
void Dynamics<Delay>::removeAgent(Size agentId) {
1150-
assert((void("Trying to remove an agent that does not exist"),
1151-
std::erase_if(m_agents, [agentId](const auto& agent) {
1152-
return agent.first == agentId;
1153-
}) == 1));
1149+
m_agents.erase(agentId);
11541150
}
11551151

11561152
template <typename Delay>
@@ -1232,7 +1228,7 @@ namespace dsm {
12321228
std::vector<double> densities;
12331229
densities.reserve(m_graph.streetSet().size());
12341230
for (const auto& [streetId, street] : m_graph.streetSet()) {
1235-
densities.push_back(normalized ? street->normDensity() : street->density());
1231+
densities.push_back(street->density(normalized));
12361232
}
12371233
return Measurement<double>(densities);
12381234
}
@@ -1255,9 +1251,9 @@ namespace dsm {
12551251
std::vector<double> flows;
12561252
flows.reserve(m_graph.streetSet().size());
12571253
for (const auto& [streetId, street] : m_graph.streetSet()) {
1258-
if (above and (street->normDensity() > threshold)) {
1254+
if (above && (street->density(true) > threshold)) {
12591255
flows.push_back(street->density() * this->streetMeanSpeed(streetId));
1260-
} else if (!above and (street->normDensity() < threshold)) {
1256+
} else if (!above && (street->density(true) < threshold)) {
12611257
flows.push_back(street->density() * this->streetMeanSpeed(streetId));
12621258
}
12631259
}
@@ -1387,7 +1383,7 @@ namespace dsm {
13871383
const auto& agent{this->m_agents[agentId]};
13881384
const auto& street{this->m_graph.streetSet()[agent->streetId().value()]};
13891385
double speed{street->maxSpeed() *
1390-
(1. - this->m_minSpeedRateo * street->normDensity())};
1386+
(1. - this->m_minSpeedRateo * street->density(true))};
13911387
if (this->m_speedFluctuationSTD > 0.) {
13921388
std::normal_distribution<double> speedDist{speed,
13931389
speed * this->m_speedFluctuationSTD};
@@ -1479,11 +1475,11 @@ namespace dsm {
14791475
speeds.reserve(this->m_graph.streetSet().size());
14801476
for (const auto& [streetId, street] : this->m_graph.streetSet()) {
14811477
if (above) {
1482-
if (street->normDensity() > threshold) {
1478+
if (street->density(true) > threshold) {
14831479
speeds.push_back(this->streetMeanSpeed(streetId));
14841480
}
14851481
} else {
1486-
if (street->normDensity() < threshold) {
1482+
if (street->density(true) < threshold) {
14871483
speeds.push_back(this->streetMeanSpeed(streetId));
14881484
}
14891485
}

0 commit comments

Comments
 (0)