diff --git a/src/dsm/headers/Dynamics.hpp b/src/dsm/headers/Dynamics.hpp index 4d42b1871..29ee8081c 100644 --- a/src/dsm/headers/Dynamics.hpp +++ b/src/dsm/headers/Dynamics.hpp @@ -249,9 +249,9 @@ namespace dsm { // TODO: implement the following functions // We can implement the base version of these functions by cycling over agents... I won't do it for now. // Grufoony - 19/02/2024 - virtual double streetMeanSpeed(Id) const = 0; - virtual Measurement streetMeanSpeed() const = 0; - virtual Measurement streetMeanSpeed(double, bool) const = 0; + virtual double streetMeanSpeed(Id streetId) const; + virtual Measurement streetMeanSpeed() const; + virtual Measurement streetMeanSpeed(double, bool) const; /// @brief Get the mean density of the streets in \f$m^{-1}\f$ /// @return Measurement The mean density of the streets and the standard deviation Measurement streetMeanDensity(bool normalized = false) const; @@ -610,6 +610,45 @@ namespace dsm { return Measurement(speeds); } + template + double Dynamics::streetMeanSpeed(Id streetId) const { + auto const& pStreet{m_graph.streetSet().at(streetId)}; + auto const nAgents{pStreet->nAgents()}; + if (nAgents == 0) { + return 0.; + } + double speed{0.}; + for (auto const& agentId : pStreet->waitingAgents()) { + speed += m_agents.at(agentId)->speed(); + } + return speed / nAgents; + } + + template + Measurement Dynamics::streetMeanSpeed() const { + std::vector speeds; + speeds.reserve(m_graph.streetSet().size()); + for (const auto& [streetId, street] : m_graph.streetSet()) { + speeds.push_back(streetMeanSpeed(streetId)); + } + return Measurement(speeds); + } + + template + Measurement Dynamics::streetMeanSpeed(double threshold, + bool above) const { + std::vector speeds; + speeds.reserve(m_graph.streetSet().size()); + for (const auto& [streetId, street] : m_graph.streetSet()) { + if (above && (street->density(true) > threshold)) { + speeds.push_back(streetMeanSpeed(streetId)); + } else if (!above && (street->density(true) < threshold)) { + speeds.push_back(streetMeanSpeed(streetId)); + } + } + return Measurement(speeds); + } + template Measurement Dynamics::streetMeanDensity(bool normalized) const { if (m_graph.streetSet().size() == 0) {