Skip to content

Conversation

@Grufoony
Copy link
Collaborator

@Grufoony Grufoony commented Dec 13, 2024

  • Template Dynamics on agent_t agent type
  • Template RoadDynamics on delay_t delay type
  • Remove template from FirstOrderDynamics: it uses Typedef's Delay

@Grufoony Grufoony requested a review from sbaldu December 13, 2024 10:45
double FirstOrderDynamics::streetMeanSpeed(Id streetId) const {
const auto& street{this->m_graph.streetSet().at(streetId)};
if (street->nAgents() == 0) {
return street->maxSpeed();

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
}
std::vector<double> speeds;
speeds.reserve(this->m_graph.streetSet().size());
for (const auto& [streetId, street] : this->m_graph.streetSet()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
Measurement<double> FirstOrderDynamics::streetMeanSpeed(double threshold,
bool above) const {
if (this->m_agents.size() == 0) {
return Measurement(0., 0.);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 15.5 rule Note

MISRA 15.5 rule
}
std::vector<double> speeds;
speeds.reserve(this->m_graph.streetSet().size());
for (const auto& [streetId, street] : this->m_graph.streetSet()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
requires(is_numeric_v<delay_t>)
RoadDynamics<delay_t>::RoadDynamics(Graph& graph, std::optional<unsigned int> seed)
: Dynamics<delay_t>(graph, seed),
: Dynamics<Agent<delay_t>>(graph, seed),

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
@Grufoony Grufoony marked this pull request as draft December 13, 2024 11:06
@Grufoony Grufoony marked this pull request as ready for review December 13, 2024 12:22
FirstOrderDynamics::FirstOrderDynamics(Graph& graph,
std::optional<unsigned int> seed,
double alpha)
: RoadDynamics<Delay>(graph, seed), m_alpha{0.}, m_speedFluctuationSTD{0.} {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
std::optional<unsigned int> seed,
double alpha)
: RoadDynamics<Delay>(graph, seed), m_alpha{0.}, m_speedFluctuationSTD{0.} {
if (alpha < 0. || alpha > 1.) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
m_alpha = alpha;
}
double globMaxTimePenalty{0.};
for (const auto& [streetId, street] : this->m_graph.streetSet()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
void FirstOrderDynamics::setAgentSpeed(Size agentId) {
const auto& agent{this->m_agents[agentId]};
const auto& street{this->m_graph.streetSet()[agent->streetId().value()]};
double speed{street->maxSpeed() * (1. - m_alpha * street->density(true))};

Check warning

Code scanning / Cppcheck (reported by Codacy)

Local variable 'speed' shadows outer function Warning

Local variable 'speed' shadows outer function
void FirstOrderDynamics::setAgentSpeed(Size agentId) {
const auto& agent{this->m_agents[agentId]};
const auto& street{this->m_graph.streetSet()[agent->streetId().value()]};
double speed{street->maxSpeed() * (1. - m_alpha * street->density(true))};

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
std::normal_distribution<double> speedDist{speed, speed * m_speedFluctuationSTD};
speed = speedDist(this->m_generator);
}
speed < 0. ? agent->setSpeed(street->maxSpeed() * (1. - m_alpha))

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
double minSpeedRateo = 0.);
explicit FirstOrderDynamics(Graph& graph,
std::optional<unsigned int> seed = std::nullopt,
double alpha = 0.);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 17.8 rule Note

MISRA 17.8 rule
@Grufoony Grufoony merged commit c15b830 into main Dec 13, 2024
15 checks passed
@Grufoony Grufoony deleted the enhance_templates branch December 13, 2024 16:53
@Grufoony Grufoony restored the enhance_templates branch December 14, 2024 08:59
@Grufoony Grufoony deleted the enhance_templates branch December 14, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants