@@ -165,9 +165,10 @@ namespace dsf::mobility {
165165 inline void setMeanTravelTime (std::time_t const meanTravelTime) noexcept {
166166 m_meanTravelTime = meanTravelTime;
167167 };
168- // / @brief Set the origin nodes
168+ // / @brief Set the origin nodes. If the provided map is empty, the origin nodes are set using the streets' stationary weights.
169+ // / NOTE: the default stationary weights are 1.0 so, if not set, this is equivalent to setting uniform weights.
169170 // / @param originNodes The origin nodes
170- void setOriginNodes (std::unordered_map<Id, double > const & originNodes);
171+ void setOriginNodes (std::unordered_map<Id, double > const & originNodes = {} );
171172 // / @brief Set the destination nodes
172173 // / @param destinationNodes The destination nodes
173174 void setDestinationNodes (std::unordered_map<Id, double > const & destinationNodes);
@@ -1140,6 +1141,19 @@ namespace dsf::mobility {
11401141 std::unordered_map<Id, double > const & originNodes) {
11411142 m_originNodes.clear ();
11421143 m_originNodes.reserve (originNodes.size ());
1144+ if (originNodes.empty ()) {
1145+ // If no origin nodes are provided, try to set origin nodes basing on streets' stationary weights
1146+ double totalStationaryWeight = 0.0 ;
1147+ for (auto const & [edgeId, pEdge] : this ->graph ().edges ()) {
1148+ auto const & weight = pEdge->stationaryWeight ();
1149+ m_originNodes[pEdge->source ()] += weight;
1150+ totalStationaryWeight += weight;
1151+ }
1152+ for (auto & [nodeId, weight] : m_originNodes) {
1153+ weight /= totalStationaryWeight;
1154+ }
1155+ return ;
1156+ }
11431157 auto const sumWeights = std::accumulate (
11441158 originNodes.begin (), originNodes.end (), 0 ., [](double sum, auto const & pair) {
11451159 return sum + pair.second ;
0 commit comments