Skip to content

Filippo-style simulations#474

Open
Grufoony wants to merge 1 commit into
mainfrom
autocharge
Open

Filippo-style simulations#474
Grufoony wants to merge 1 commit into
mainfrom
autocharge

Conversation

@Grufoony
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings May 18, 2026 09:25
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

❌ Patch coverage is 0% with 78 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.15%. Comparing base (96556d1) to head (74ee51a).

Files with missing lines Patch % Lines
src/dsf/mobility/TrafficSimulator.cpp 0.00% 78 Missing ⚠️
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              
Flag Coverage Δ
unittests 83.15% <0.00%> (-0.86%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@@ -0,0 +1,22 @@
from dsf_cpp import mobility
@@ -0,0 +1,22 @@
from dsf_cpp import mobility

sim = mobility.TrafficSimulator()
Comment thread examples/auto_charge.cpp
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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 implementation m_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();
Comment on lines +457 to +458
m_preparePersistence();

Comment on lines +495 to +499
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);
Comment on lines +478 to +482
bool fileExists = std::filesystem::exists(stabilityLogFile);
stabilityWriter.emplace(stabilityLogFile, ';');
if (!fileExists) {
stabilityWriter->writeHeader("time_step", "base_agent_count", "mean_density");
}
Comment on lines +501 to +510
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;
Comment thread src/dsf/bindings.cpp
Comment on lines +1247 to +1255
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,
Comment thread src/dsf/bindings.cpp
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));
Comment on lines +437 to +446
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) {
Comment thread examples/auto_charge.cpp
@@ -0,0 +1,21 @@
#include <dsf.hpp>
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.

3 participants