Skip to content

Commit e7a46d4

Browse files
committed
Improved evolution algorithm
1 parent 838c51e commit e7a46d4

File tree

3 files changed

+12
-42
lines changed

3 files changed

+12
-42
lines changed

src/dsm/headers/Dynamics.hpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,8 @@ namespace dsm {
459459
void Dynamics<Delay>::m_evolveStreet(const Id streetId,
460460
const std::unique_ptr<Street>& pStreet,
461461
bool reinsert_agents) {
462-
for (auto queueIndex = 0; queueIndex < pStreet->nLanes(); ++queueIndex) {
462+
auto const nLanes = pStreet->nLanes();
463+
for (auto queueIndex = 0; queueIndex < nLanes; ++queueIndex) {
463464
if (m_uniformDist(m_generator) > m_maxFlowPercentage ||
464465
pStreet->queue(queueIndex).empty()) {
465466
continue;
@@ -475,18 +476,16 @@ namespace dsm {
475476
}
476477
if (destinationNode->isTrafficLight()) {
477478
auto& tl = dynamic_cast<TrafficLight<Delay>&>(*destinationNode);
478-
if (tl.leftTurnRatio().has_value()) {
479-
auto it = m_agentNextStreetId.find(agentId);
480-
if (it == m_agentNextStreetId.end()) {
481-
if (!tl.isGreen(streetId, 0.)) {
482-
continue;
483-
}
484-
} else {
485-
auto const& nextStreet{m_graph.streetSet()[m_agentNextStreetId[agentId]]};
486-
auto const delta{nextStreet->deltaAngle(pStreet->angle())};
487-
if (!tl.isGreen(streetId, delta)) {
488-
continue;
489-
}
479+
if (tl.leftTurnRatio().has_value() && nLanes > 1 && queueIndex == nLanes - 1) {
480+
if (tl.isGreen(streetId) &&
481+
tl.counter() >
482+
tl.delay().value().first * (1. - tl.leftTurnRatio().value().first)) {
483+
continue;
484+
} else if (!tl.isGreen(streetId) &&
485+
tl.counter() > tl.delay().value().first +
486+
tl.delay().value().second *
487+
(1. - tl.leftTurnRatio().value().second)) {
488+
continue;
490489
}
491490
} else if (!tl.isGreen(streetId)) {
492491
continue;

src/dsm/headers/Node.hpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ namespace dsm {
237237
/// @return bool True if the traffic light is green
238238
bool isGreen() const;
239239
bool isGreen(Id streetId) const;
240-
bool isGreen(Id streetId, double angle) const;
241240
bool isTrafficLight() const noexcept override { return true; }
242241
};
243242

@@ -351,33 +350,6 @@ namespace dsm {
351350
return !hasPriority;
352351
}
353352

354-
template <typename Delay>
355-
requires(std::unsigned_integral<Delay>)
356-
bool TrafficLight<Delay>::isGreen(Id streetId, double angle) const {
357-
assert((void("TrafficLight's delay has not been set."), m_delay.has_value()));
358-
assert((void("TrafficLight's left turn ratio has not been set."),
359-
m_leftTurnRatio.has_value()));
360-
bool const hasPriority{this->streetPriorities().contains(streetId)};
361-
auto const pair{m_delay.value()};
362-
if (angle > 0.) {
363-
if (hasPriority) {
364-
return m_counter > pair.first * (1. - m_leftTurnRatio.value().first) &&
365-
m_counter < pair.first;
366-
} else {
367-
return m_counter >
368-
pair.first + pair.second * (1. - m_leftTurnRatio.value().second);
369-
}
370-
} else {
371-
if (hasPriority) {
372-
return m_counter < pair.first * (1. - m_leftTurnRatio.value().first);
373-
} else {
374-
return m_counter > pair.first &&
375-
m_counter <
376-
pair.first + pair.second * (1. - m_leftTurnRatio.value().second);
377-
}
378-
}
379-
}
380-
381353
/// @brief The Roundabout class represents a roundabout node in the network.
382354
/// @tparam Id The type of the node's id
383355
/// @tparam Size The type of the node's capacity

test/Test_dynamics.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,6 @@ TEST_CASE("Dynamics") {
686686
}
687687
dynamics.evolve(false);
688688
dynamics.evolve(false);
689-
dynamics.evolve(false);
690689
THEN("The agent 0 passes and agent 1 waits") {
691690
CHECK_EQ(dynamics.agents().at(0)->streetId().value(), 7);
692691
CHECK_EQ(dynamics.agents().at(1)->streetId().value(), 1);

0 commit comments

Comments
 (0)