-
Notifications
You must be signed in to change notification settings - Fork 4
Refactor coils #364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor coils #364
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #364 +/- ##
==========================================
- Coverage 82.97% 82.91% -0.07%
==========================================
Files 50 50
Lines 5057 4892 -165
Branches 573 559 -14
==========================================
- Hits 4196 4056 -140
+ Misses 853 828 -25
Partials 8 8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
||
| static void BM_SpireStreet_AddAgent(benchmark::State& state) { | ||
| dsf::mobility::Street baseStreet(0, | ||
| static void BM_CoilStreet_AddAgent(benchmark::State& state) { |
Check warning
Code scanning / Cppcheck (reported by Codacy)
Parameter 'state' can be declared with const Warning test
|
|
||
| static void BM_SpireStreet_MeanFlow(benchmark::State& state) { | ||
| dsf::mobility::Street baseStreet(0, | ||
| static void BM_CoilStreet_MeanFlow(benchmark::State& state) { |
Check warning
Code scanning / Cppcheck (reported by Codacy)
Parameter 'state' can be declared with const Warning test
|
|
||
| static void BM_SpireStreet_Dequeue(benchmark::State& state) { | ||
| dsf::mobility::Street baseStreet(0, | ||
| static void BM_CoilStreet_Dequeue(benchmark::State& state) { |
Check warning
Code scanning / Cppcheck (reported by Codacy)
Parameter 'state' can be declared with const Warning test
| if (pStreet->isStochastic()) { | ||
| value = dynamic_cast<StochasticSpireStreet&>(*pStreet).inputCounts(reset); | ||
| } else { | ||
| value = dynamic_cast<SpireStreet&>(*pStreet).inputCounts(reset); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note
src/dsf/mobility/RoadDynamics.hpp
Outdated
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note
| m_exitQueues[index] = std::move(queue); | ||
| } | ||
| void Street::enableCounter(std::string name) { | ||
| if (m_counter.has_value()) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note
| std::format("{} already has a counter named {}", *this, m_counter->name())); | ||
| } | ||
| if (name.empty()) { | ||
| name = std::format("Coil_{}", m_id); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 17.8 rule Note
| m_exitQueues[queueId].push( | ||
| std::move(const_cast<std::unique_ptr<Agent>&>(m_movingAgents.top()))); | ||
| m_movingAgents.pop(); | ||
| if (m_counter.has_value()) { |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 14.4 rule Note
| /// @throw std::invalid_argument If the mean vehicle length is negative | ||
| static void setMeanVehicleLength(double meanVehicleLength); | ||
|
|
||
| void enableCounter(std::string name = std::string()); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 13.4 rule Note
| /// @throw std::invalid_argument If the mean vehicle length is negative | ||
| static void setMeanVehicleLength(double meanVehicleLength); | ||
|
|
||
| void enableCounter(std::string name = std::string()); |
Check notice
Code scanning / Cppcheck (reported by Codacy)
MISRA 17.8 rule Note
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cppcheck (reported by Codacy) found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the traffic counting system by replacing the SpireStreet and StochasticSpireStreet classes with an optional counter feature that can be enabled on any Street. The PR simplifies the counter implementation from tracking separate input/output flows to a single count of vehicles passing through.
- Removes
SpireStreetandStochasticSpireStreetinheritance-based classes - Adds an optional
Countermember to the baseStreetclass - Simplifies
Counterclass to track a single count value instead of separate input/output - Updates all examples, tests, and benchmarks to use the new API
Reviewed Changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/dsf/mobility/Street.hpp | Adds optional counter member, removes SpireStreet classes, adds enableCounter/resetCounter/counterName/counts methods |
| src/dsf/mobility/Street.cpp | Implements counter enabling, resetting, and incrementing on enqueue |
| src/dsf/mobility/Sensors.hpp | Simplifies Counter class to single count value with basic increment/reset |
| src/dsf/mobility/Sensors.cpp | File removed - Counter is now header-only |
| src/dsf/mobility/RoadNetwork.hpp | Renames makeSpireStreet to addCoil |
| src/dsf/mobility/RoadNetwork.cpp | Updates addCoil implementation, changes GeoJSON coilcode from uint64 to string |
| src/dsf/mobility/RoadDynamics.hpp | Removes meanSpireInputFlow/meanSpireOutputFlow, replaces saveInputStreetCounts/saveOutputStreetCounts with saveCoilCounts |
| src/dsf/bindings.cpp | Updates Python bindings to reflect renamed methods |
| test/mobility/Test_street.cpp | Replaces comprehensive SpireStreet tests with basic counter functionality test |
| test/mobility/Test_graph.cpp | Updates test to use addCoil instead of makeSpireStreet |
| test/mobility/Test_dynamics.cpp | Removes meanSpireFlow tests, updates to use hasCoil/addCoil |
| examples/stalingrado.cpp | Updates to use addCoil and counts() instead of SpireStreet |
| examples/slow_charge_tl.cpp | Replaces manual spire tracking with saveCoilCounts, removes PRINT_OUT_SPIRES |
| examples/slow_charge_rb.cpp | Replaces manual spire tracking with saveCoilCounts, removes PRINT_OUT_SPIRES |
| benchmark/Bench_Street.cpp | Renames SpireStreet benchmarks to CoilStreet, updates implementation |
| benchmark/Bench_Network.cpp | Code formatting improvements |
| benchmark/Bench_Dynamics.cpp | Code formatting improvements |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
examples/stalingrado.cpp
Outdated
| } | ||
| coil->resetCounter(); |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic issue: The counter is reset every time progress % 60 == 0 (line 105), but counts are only written when progress % 300 == 0 (line 103). This means the counter gets reset at progress values 60, 120, 180, and 240 without saving those counts, causing data loss. Consider moving the reset inside the if (progress % 300 == 0) block or adjusting the logic to preserve all counts.
| } | |
| coil->resetCounter(); | |
| coil->resetCounter(); | |
| } |
| /// @brief Save the street input counts in csv format | ||
| /// @param filename The name of the file | ||
| /// @param reset If true, the input counts are cleared after the computation |
Copilot
AI
Nov 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation inconsistency: The documentation says "Save the street input counts" but the method name is saveCoilCounts. Consider updating the documentation to match the method name, e.g., "Save the coil counts from streets with coils".
| /// @brief Save the street input counts in csv format | |
| /// @param filename The name of the file | |
| /// @param reset If true, the input counts are cleared after the computation | |
| /// @brief Save the coil counts from streets with coils in csv format | |
| /// @param filename The name of the file | |
| /// @param reset If true, the coil counts are cleared after the computation |
Spire<...>#110Counterclass to have only one counter