Skip to content
Merged
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
45 changes: 42 additions & 3 deletions src/dsm/headers/Dynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@
// 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<double> streetMeanSpeed() const = 0;
virtual Measurement<double> streetMeanSpeed(double, bool) const = 0;
virtual double streetMeanSpeed(Id streetId) const;
virtual Measurement<double> streetMeanSpeed() const;
virtual Measurement<double> streetMeanSpeed(double, bool) const;
/// @brief Get the mean density of the streets in \f$m^{-1}\f$
/// @return Measurement<double> The mean density of the streets and the standard deviation
Measurement<double> streetMeanDensity(bool normalized = false) const;
Expand Down Expand Up @@ -610,6 +610,45 @@
return Measurement<double>(speeds);
}

template <typename agent_t>
double Dynamics<agent_t>::streetMeanSpeed(Id streetId) const {
auto const& pStreet{m_graph.streetSet().at(streetId)};
auto const nAgents{pStreet->nAgents()};
if (nAgents == 0) {
return 0.;

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
}
double speed{0.};

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule

Check warning

Code scanning / Cppcheck (reported by Codacy)

Local variable 'speed' shadows outer function Warning

Local variable 'speed' shadows outer function
for (auto const& agentId : pStreet->waitingAgents()) {
speed += m_agents.at(agentId)->speed();
}
return speed / nAgents;
}

template <typename agent_t>
Measurement<double> Dynamics<agent_t>::streetMeanSpeed() const {
std::vector<double> speeds;
speeds.reserve(m_graph.streetSet().size());
for (const auto& [streetId, street] : m_graph.streetSet()) {
speeds.push_back(streetMeanSpeed(streetId));
}
return Measurement<double>(speeds);
}

template <typename agent_t>
Measurement<double> Dynamics<agent_t>::streetMeanSpeed(double threshold,
bool above) const {
std::vector<double> 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));
}

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.7 rule Note

MISRA 15.7 rule
}
return Measurement<double>(speeds);
}

template <typename agent_t>
Measurement<double> Dynamics<agent_t>::streetMeanDensity(bool normalized) const {
if (m_graph.streetSet().size() == 0) {
Expand Down
Loading