Filippo-style simulations#474
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #474 +/- ##
==========================================
- Coverage 84.00% 83.15% -0.86%
==========================================
Files 54 54
Lines 7585 7663 +78
Branches 881 903 +22
==========================================
Hits 6372 6372
- Misses 1201 1279 +78
Partials 12 12
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:
|
| @@ -0,0 +1,22 @@ | |||
| from dsf_cpp import mobility | |||
| @@ -0,0 +1,22 @@ | |||
| from dsf_cpp import mobility | |||
|
|
|||
| sim = mobility.TrafficSimulator() | |||
| 5, 30, 60, 600, std::nullopt, 120, 120, 2, true, "auto_charge_events.csv"); | ||
| } catch (const std::exception& e) { | ||
| std::cerr << "Error: " << e.what() << std::endl; | ||
| return 1; |
| @@ -0,0 +1,22 @@ | |||
| from dsf_cpp import mobility | |||
| @@ -0,0 +1,22 @@ | |||
| from dsf_cpp import mobility | |||
There was a problem hiding this comment.
Pull request overview
Adds a new “auto-charge” simulation mode to dsf::mobility::TrafficSimulator, exposing it to Python via pybind11 and providing C++/Python usage examples. This fits into the mobility simulation workflow as an additional run strategy alongside the existing default and slow-charge modes.
Changes:
- Introduces
TrafficSimulator::runAutoCharge(...)and private implementationm_runAutoCharge(...). - Adds Python binding
TrafficSimulator.runAutoCharge(...)with corresponding docstring/arguments. - Adds C++ and Python example scripts demonstrating the new mode.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/dsf/mobility/TrafficSimulator.hpp | Declares m_runAutoCharge and adds public runAutoCharge wrapper. |
| src/dsf/mobility/TrafficSimulator.cpp | Implements the new auto-charge loop, stability detection, and optional CSV event logging. |
| src/dsf/bindings.cpp | Exposes runAutoCharge to Python and documents parameters. |
| examples/auto_charge.cpp | New C++ example demonstrating auto-charge usage. |
| examples/auto_charge_py_example.py | New Python example demonstrating auto-charge usage via bindings. |
Comments suppressed due to low confidence (1)
src/dsf/mobility/TrafficSimulator.cpp:553
- Immediate injection on charge is also hard-coded to AgentInsertionMethod::ODS, ignoring the configured agent insertion method and potentially throwing when ODs aren’t configured. Use the same insertion method as the regular insertion path (or validate requirements up front).
spdlog::info(
"[auto-charge] New BASE_AGENT_COUNT: {} at step {}.", base, i);
if (injectOnCharge && chargeIncrement > 0) {
m_dynamics->addAgents(chargeIncrement, AgentInsertionMethod::ODS);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "Cannot run the simulation without imported road network dynamics."); | ||
| } | ||
| m_dynamics->prepareNetwork(); | ||
| m_preparePersistence(); |
| m_preparePersistence(); | ||
|
|
| if (i % dtAgent == 0) { | ||
| if (base > 0) { | ||
| m_dynamics->addAgents(base, AgentInsertionMethod::ODS); | ||
| } | ||
| } |
| std::deque<double> densityWindow; | ||
| auto windowSize = std::size_t(1); | ||
| if (saveIntervalSeconds > 0 && stabilityHoldSeconds > 0) { | ||
| windowSize = std::max<std::size_t>(1, stabilityHoldSeconds / saveIntervalSeconds); |
| bool fileExists = std::filesystem::exists(stabilityLogFile); | ||
| stabilityWriter.emplace(stabilityLogFile, ';'); | ||
| if (!fileExists) { | ||
| stabilityWriter->writeHeader("time_step", "base_agent_count", "mean_density"); | ||
| } |
| bool const shouldSave = (saveIntervalSeconds > 0 && i % saveIntervalSeconds == 0); | ||
| auto stepData = m_dynamics->evolve(shouldSave ? StepDataRequest{m_saveAverageStats, | ||
| m_saveStreetData, | ||
| m_saveTravelData, | ||
| m_saveAgentData} | ||
| : StepDataRequest{}); | ||
|
|
||
| if (shouldSave) { | ||
| if (stepData.averageStats.has_value()) { | ||
| double meanDensity = stepData.averageStats->meanDensity; |
| std::size_t baseAgentCount, | ||
| std::size_t dtAgent, | ||
| std::size_t saveIntervalSeconds, | ||
| pybind11::object maxSteps, | ||
| pybind11::object stopMeanDensityVpk, | ||
| std::size_t stabilityHoldSeconds, | ||
| std::size_t stabilityCooldownSeconds, | ||
| std::size_t chargeIncrement, | ||
| bool injectOnCharge, |
| std::string stabilityLogFile) { | ||
| std::optional<std::size_t> optMaxSteps = std::nullopt; | ||
| if (!maxSteps.is_none()) { | ||
| optMaxSteps = static_cast<std::size_t>(pybind11::cast<std::uint64_t>(maxSteps)); |
| void TrafficSimulator::m_runAutoCharge(std::size_t baseAgentCount, | ||
| std::size_t dtAgent, | ||
| std::size_t saveIntervalSeconds, | ||
| std::optional<std::size_t> maxSteps, | ||
| std::optional<double> stopMeanDensityVpk, | ||
| std::size_t stabilityHoldSeconds, | ||
| std::size_t stabilityCooldownSeconds, | ||
| std::size_t chargeIncrement, | ||
| bool injectOnCharge, | ||
| std::string const& stabilityLogFile) { |
| @@ -0,0 +1,21 @@ | |||
| #include <dsf.hpp> | |||
No description provided.