Skip to content

Commit 4fd49d4

Browse files
committed
Add possibility to normalize nExitingAgents on nLanes
1 parent 1274b54 commit 4fd49d4

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

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 = 6;
9-
static constexpr uint8_t DSM_VERSION_PATCH = 7;
9+
static constexpr uint8_t DSM_VERSION_PATCH = 8;
1010

1111
static auto const DSM_VERSION =
1212
std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH);

src/dsm/headers/Road.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace dsm {
6969

7070
virtual int nAgents() const = 0;
7171
virtual int nMovingAgents() const = 0;
72-
virtual int nExitingAgents(Direction direction) const = 0;
72+
virtual double nExitingAgents(Direction direction, bool normalizeOnNLanes) const = 0;
7373
virtual double density(bool normalized = false) const = 0;
7474
};
7575
} // namespace dsm

src/dsm/headers/Street.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ namespace dsm {
115115
int nMovingAgents() const override;
116116
/// @brief Get the number of agents on all queues for a given direction
117117
/// @param direction The direction of the agents (default is ANY)
118-
/// @return int The number of agents on all queues for a given direction
119-
int nExitingAgents(Direction direction = Direction::ANY) const;
118+
/// @param normalizeOnNLanes If true, the number of agents is normalized by the number of lanes
119+
/// @return double The number of agents on all queues for a given direction
120+
double nExitingAgents(Direction direction = Direction::ANY,
121+
bool normalizeOnNLanes = false) const;
120122

121123
inline std::vector<Direction> const& laneMapping() const { return m_laneMapping; }
122124

src/dsm/sources/Street.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,38 @@ namespace dsm {
105105
}
106106

107107
int Street::nMovingAgents() const { return m_movingAgents.size(); }
108-
int Street::nExitingAgents(Direction direction) const {
109-
int nAgents{0};
108+
double Street::nExitingAgents(Direction direction, bool normalizeOnNLanes) const {
109+
double nAgents{0.};
110+
int n{0};
110111
for (auto i{0}; i < m_nLanes; ++i) {
111112
if (direction == Direction::ANY) {
112113
nAgents += m_exitQueues[i].size();
114+
++n;
113115
} else if (m_laneMapping[i] == direction) {
114116
nAgents += m_exitQueues[i].size();
115117
} else if (m_laneMapping[i] == Direction::RIGHTANDSTRAIGHT &&
116118
(direction == Direction::RIGHT || direction == Direction::STRAIGHT)) {
117119
nAgents += m_exitQueues[i].size();
120+
++n;
118121
} else if (m_laneMapping[i] == Direction::LEFTANDSTRAIGHT &&
119122
(direction == Direction::LEFT || direction == Direction::STRAIGHT)) {
120123
nAgents += m_exitQueues[i].size();
124+
++n;
125+
} else if (direction == Direction::RIGHTANDSTRAIGHT &&
126+
(m_laneMapping[i] == Direction::RIGHT ||
127+
m_laneMapping[i] == Direction::STRAIGHT)) {
128+
nAgents += m_exitQueues[i].size();
129+
++n;
130+
} else if (direction == Direction::LEFTANDSTRAIGHT &&
131+
(m_laneMapping[i] == Direction::LEFT ||
132+
m_laneMapping[i] == Direction::STRAIGHT)) {
133+
nAgents += m_exitQueues[i].size();
134+
++n;
121135
}
122136
}
137+
if (normalizeOnNLanes) {
138+
n > 1 ? nAgents /= n : nAgents;
139+
}
123140
return nAgents;
124141
}
125142

test/Test_dynamics.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ TEST_CASE("FirstOrderDynamics") {
749749
dynamics.evolve(false); // Counter 3
750750
THEN("The agents are still") {
751751
CHECK_EQ(dynamics.graph().edge(1)->nExitingAgents(), 2);
752+
CHECK_EQ(dynamics.graph().edge(1)->nExitingAgents(Direction::ANY, true),
753+
doctest::Approx(0.666667));
752754
CHECK_EQ(dynamics.graph().edge(1)->nExitingAgents(Direction::RIGHT), 0);
753755
CHECK_EQ(dynamics.graph().edge(1)->nExitingAgents(Direction::STRAIGHT), 1);
754756
CHECK_EQ(dynamics.graph().edge(1)->nExitingAgents(Direction::LEFT), 1);

0 commit comments

Comments
 (0)