diff --git a/src/dsf/mobility/Road.cpp b/src/dsf/mobility/Road.cpp index 5a850157..d69cf66b 100644 --- a/src/dsf/mobility/Road.cpp +++ b/src/dsf/mobility/Road.cpp @@ -83,6 +83,11 @@ namespace dsf::mobility { } m_transportCapacity = transportCapacity; } + + double Road::density(bool normalized) const noexcept { + return normalized ? this->nAgents() / static_cast(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) { diff --git a/src/dsf/mobility/Road.hpp b/src/dsf/mobility/Road.hpp index 5e9a3c3a..509ba183 100644 --- a/src/dsf/mobility/Road.hpp +++ b/src/dsf/mobility/Road.hpp @@ -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; @@ -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; } @@ -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 diff --git a/src/dsf/mobility/Street.cpp b/src/dsf/mobility/Street.cpp index abe4cc72..1986d76a 100644 --- a/src/dsf/mobility/Street.cpp +++ b/src/dsf/mobility/Street.cpp @@ -161,23 +161,18 @@ namespace dsf::mobility { return pAgent; } - int Street::nAgents() const { - auto nAgents{static_cast(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(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(); diff --git a/src/dsf/mobility/Street.hpp b/src/dsf/mobility/Street.hpp index 768cfaa1..64a87a20 100644 --- a/src/dsf/mobility/Street.hpp +++ b/src/dsf/mobility/Street.hpp @@ -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; } @@ -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 The (mean, std) speed of the agents that have passed through the street