Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/dsf/mobility/Road.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ namespace dsf::mobility {
}
m_transportCapacity = transportCapacity;
}

double Road::density(bool normalized) const noexcept {
return normalized ? this->nAgents() / static_cast<double>(this->capacity())
: this->nAgents() / (this->length() * this->nLanes());
}
Direction Road::turnDirection(double const& previousStreetAngle) const {
auto const deltaAngle{this->deltaAngle(previousStreetAngle)};
if (std::abs(deltaAngle) >= std::numbers::pi) {
Expand Down
14 changes: 9 additions & 5 deletions src/dsf/mobility/Road.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace dsf::mobility {
double m_length;
double m_maxSpeed;
int m_nLanes;
int m_capacity;
std::size_t m_capacity;
double m_transportCapacity;
std::string m_name;
bool m_hasPriority = false;
Expand Down Expand Up @@ -103,6 +103,13 @@ namespace dsf::mobility {
/// @brief Get the road's capacity, in number of agents
/// @return int The road's capacity, in number of agents
inline auto capacity() const noexcept { return m_capacity; }
/// @brief Get the road's density in \f$m^{-1}\f$ or in \f$a.u.\f$, if normalized
/// @param normalized If true, the road's density is normalized by the road's capacity
/// @return double, The road's density
double density(bool normalized = false) const noexcept;
/// @brief Check if the road is full
/// @return bool, True if the road is full, false otherwise
inline bool isFull() const final { return this->nAgents() == this->capacity(); }
/// @brief Get the road's transport capacity, in number of agents
/// @return double The road's transport capacity, in number of agents
inline auto transportCapacity() const noexcept { return m_transportCapacity; }
Expand Down Expand Up @@ -134,10 +141,7 @@ namespace dsf::mobility {
/// - LEFT (delta is positive and not covered by the above conditions)
Direction turnDirection(double const& previousStreetAngle) const;

virtual int nAgents() const = 0;
virtual int nMovingAgents() const = 0;
virtual double nExitingAgents(Direction direction, bool normalizeOnNLanes) const = 0;
virtual double density(bool normalized = false) const = 0;
virtual std::size_t nAgents() const = 0;
};
} // namespace dsf::mobility

Expand Down
13 changes: 4 additions & 9 deletions src/dsf/mobility/Street.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,18 @@ namespace dsf::mobility {
return pAgent;
}

int Street::nAgents() const {
auto nAgents{static_cast<int>(m_movingAgents.size())};
std::size_t Street::nAgents() const {
auto nAgents{m_movingAgents.size()};
for (const auto& queue : m_exitQueues) {
nAgents += queue.size();
}
return nAgents;
}

double Street::density(bool normalized) const {
return normalized ? nAgents() / static_cast<double>(m_capacity)
: nAgents() / (m_length * m_nLanes);
}

int Street::nMovingAgents() const { return m_movingAgents.size(); }
std::size_t Street::nMovingAgents() const { return m_movingAgents.size(); }
double Street::nExitingAgents(Direction direction, bool normalizeOnNLanes) const {
double nAgents{0.};
int n{0};
std::size_t n{0};
for (auto i{0}; i < m_nLanes; ++i) {
if (direction == Direction::ANY) {
nAgents += m_exitQueues[i].size();
Expand Down
17 changes: 5 additions & 12 deletions src/dsf/mobility/Street.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,8 @@ namespace dsf::mobility {
return m_exitQueues;
}
/// @brief Get the number of agents on the street
/// @return Size, The number of agents on the street
int nAgents() const final;
/// @brief Get the street's density in \f$m^{-1}\f$ or in \f$a.u.\f$, if normalized
/// @param normalized If true, the street's density is normalized by the street's capacity
/// @return double, The street's density
double density(bool normalized = false) const final;
/// @brief Check if the street is full
/// @return bool, True if the street is full, false otherwise
inline bool isFull() const final { return this->nAgents() == this->m_capacity; }
/// @return std::size_t, The number of agents on the street
std::size_t nAgents() const final;
/// @brief Get the street's stationary weight
/// @return double The street's stationary weight
inline auto stationaryWeight() const noexcept { return m_stationaryWeight; }
Expand All @@ -162,14 +155,14 @@ namespace dsf::mobility {
return m_movingAgents;
}
/// @brief Get the number of of moving agents, i.e. agents not yet enqueued
/// @return int The number of moving agents
int nMovingAgents() const final;
/// @return std::size_t The number of moving agents
std::size_t nMovingAgents() const;
/// @brief Get the number of agents on all queues for a given direction
/// @param direction The direction of the agents (default is ANY)
/// @param normalizeOnNLanes If true, the number of agents is normalized by the number of lanes
/// @return double The number of agents on all queues for a given direction
double nExitingAgents(Direction direction = Direction::ANY,
bool normalizeOnNLanes = false) const final;
bool normalizeOnNLanes = false) const;
/// @brief Get the mean speed of the agents that have passed through the street
/// @param bReset If true, the average speed data is reset after the computation
/// @return Measurement<double> The (mean, std) speed of the agents that have passed through the street
Expand Down
Loading