From c8afbee7da7455d90799ff4c767d40f78b33a409 Mon Sep 17 00:00:00 2001 From: grufoony Date: Fri, 12 Dec 2025 11:08:56 +0100 Subject: [PATCH 1/5] Default behavior for empty origins --- src/dsf/mobility/RoadDynamics.hpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/dsf/mobility/RoadDynamics.hpp b/src/dsf/mobility/RoadDynamics.hpp index 4f95bc93..6a205753 100644 --- a/src/dsf/mobility/RoadDynamics.hpp +++ b/src/dsf/mobility/RoadDynamics.hpp @@ -167,7 +167,7 @@ namespace dsf::mobility { }; /// @brief Set the origin nodes /// @param originNodes The origin nodes - void setOriginNodes(std::unordered_map const& originNodes); + void setOriginNodes(std::unordered_map const& originNodes = {}); /// @brief Set the destination nodes /// @param destinationNodes The destination nodes void setDestinationNodes(std::unordered_map const& destinationNodes); @@ -1140,6 +1140,19 @@ namespace dsf::mobility { std::unordered_map const& originNodes) { m_originNodes.clear(); m_originNodes.reserve(originNodes.size()); + if (originNodes.empty()) { + // If no origin nodes are provided, try to set origin nodes basing on streets' stationary weights + double totalStationaryWeight = 0.0; + for (auto const& [edgeId, pEdge] : this->graph().edges()) { + auto const& weight = pEdge->stationaryWeight(); + m_originNodes[pEdge->source()] = weight; + totalStationaryWeight += weight; + } + for (auto& [nodeId, weight] : m_originNodes) { + weight /= totalStationaryWeight; + } + return; + } auto const sumWeights = std::accumulate( originNodes.begin(), originNodes.end(), 0., [](double sum, auto const& pair) { return sum + pair.second; From 1423cf45f3a78bc8121ccd808aa665dae579183f Mon Sep 17 00:00:00 2001 From: grufoony Date: Fri, 12 Dec 2025 11:16:23 +0100 Subject: [PATCH 2/5] Bindings --- src/dsf/bindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dsf/bindings.cpp b/src/dsf/bindings.cpp index f42025c1..e31844dc 100644 --- a/src/dsf/bindings.cpp +++ b/src/dsf/bindings.cpp @@ -439,7 +439,7 @@ PYBIND11_MODULE(dsf_cpp, m) { const std::unordered_map& originNodes) { self.setOriginNodes(originNodes); }, - pybind11::arg("originNodes"), + pybind11::arg("originNodes") = std::unordered_map(), dsf::g_docstrings.at("dsf::mobility::RoadDynamics::setOriginNodes").c_str()) .def( "setOriginNodes", From 44ea0bafd5569a71c71eeb149689f57ff3709108 Mon Sep 17 00:00:00 2001 From: grufoony Date: Fri, 12 Dec 2025 11:25:10 +0100 Subject: [PATCH 3/5] Fix? --- src/dsf/bindings.cpp | 1 + src/dsf/mobility/RoadDynamics.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dsf/bindings.cpp b/src/dsf/bindings.cpp index e31844dc..3ec5a4f5 100644 --- a/src/dsf/bindings.cpp +++ b/src/dsf/bindings.cpp @@ -367,6 +367,7 @@ PYBIND11_MODULE(dsf_cpp, m) { pybind11::arg("alpha") = 0., pybind11::arg("weightFunction") = dsf::PathWeight::TRAVELTIME, pybind11::arg("weightThreshold") = std::nullopt, + pybind11::keep_alive<1, 2>(), dsf::g_docstrings.at("dsf::mobility::FirstOrderDynamics::FirstOrderDynamics") .c_str()) // Note: Constructors with std::function parameters are not exposed to avoid stub generation issues diff --git a/src/dsf/mobility/RoadDynamics.hpp b/src/dsf/mobility/RoadDynamics.hpp index 6a205753..3d5a47ed 100644 --- a/src/dsf/mobility/RoadDynamics.hpp +++ b/src/dsf/mobility/RoadDynamics.hpp @@ -1145,7 +1145,7 @@ namespace dsf::mobility { double totalStationaryWeight = 0.0; for (auto const& [edgeId, pEdge] : this->graph().edges()) { auto const& weight = pEdge->stationaryWeight(); - m_originNodes[pEdge->source()] = weight; + m_originNodes[pEdge->source()] += weight; totalStationaryWeight += weight; } for (auto& [nodeId, weight] : m_originNodes) { From 39aba54fd4c503645d683ffec1ed2fd1f56e5daa Mon Sep 17 00:00:00 2001 From: grufoony Date: Fri, 12 Dec 2025 18:06:44 +0100 Subject: [PATCH 4/5] Bump version --- src/dsf/dsf.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dsf/dsf.hpp b/src/dsf/dsf.hpp index 5395674a..a6d056df 100644 --- a/src/dsf/dsf.hpp +++ b/src/dsf/dsf.hpp @@ -6,7 +6,7 @@ static constexpr uint8_t DSF_VERSION_MAJOR = 4; static constexpr uint8_t DSF_VERSION_MINOR = 5; -static constexpr uint8_t DSF_VERSION_PATCH = 1; +static constexpr uint8_t DSF_VERSION_PATCH = 2; static auto const DSF_VERSION = std::format("{}.{}.{}", DSF_VERSION_MAJOR, DSF_VERSION_MINOR, DSF_VERSION_PATCH); From e70df5c15d9e6b3707be1d17360044400aebfe76 Mon Sep 17 00:00:00 2001 From: grufoony Date: Fri, 12 Dec 2025 20:10:56 +0100 Subject: [PATCH 5/5] Docs --- src/dsf/mobility/RoadDynamics.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dsf/mobility/RoadDynamics.hpp b/src/dsf/mobility/RoadDynamics.hpp index 3d5a47ed..4f1d2af0 100644 --- a/src/dsf/mobility/RoadDynamics.hpp +++ b/src/dsf/mobility/RoadDynamics.hpp @@ -165,7 +165,8 @@ namespace dsf::mobility { inline void setMeanTravelTime(std::time_t const meanTravelTime) noexcept { m_meanTravelTime = meanTravelTime; }; - /// @brief Set the origin nodes + /// @brief Set the origin nodes. If the provided map is empty, the origin nodes are set using the streets' stationary weights. + /// NOTE: the default stationary weights are 1.0 so, if not set, this is equivalent to setting uniform weights. /// @param originNodes The origin nodes void setOriginNodes(std::unordered_map const& originNodes = {}); /// @brief Set the destination nodes