Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/dsf/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -439,7 +440,7 @@ PYBIND11_MODULE(dsf_cpp, m) {
const std::unordered_map<dsf::Id, double>& originNodes) {
self.setOriginNodes(originNodes);
},
pybind11::arg("originNodes"),
pybind11::arg("originNodes") = std::unordered_map<dsf::Id, double>(),
dsf::g_docstrings.at("dsf::mobility::RoadDynamics::setOriginNodes").c_str())
.def(
"setOriginNodes",
Expand Down
2 changes: 1 addition & 1 deletion src/dsf/dsf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 16 additions & 2 deletions src/dsf/mobility/RoadDynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ 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<Id, double> const& originNodes);
void setOriginNodes(std::unordered_map<Id, double> const& originNodes = {});
/// @brief Set the destination nodes
/// @param destinationNodes The destination nodes
void setDestinationNodes(std::unordered_map<Id, double> const& destinationNodes);
Expand Down Expand Up @@ -1140,6 +1141,19 @@ namespace dsf::mobility {
std::unordered_map<Id, double> 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;
Expand Down
Loading