Skip to content

Commit 0f74c33

Browse files
committed
Init
1 parent b69b859 commit 0f74c33

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

src/dsf/mobility/RoadDynamics.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,13 @@ namespace dsf::mobility {
501501
std::optional<Id> previousNodeId = std::nullopt;
502502
std::set<Id> forbiddenTurns;
503503
double speedCurrent = 1.0;
504+
double stationaryWeightCurrent = 1.0;
504505
if (pAgent->streetId().has_value()) {
505506
auto const& pStreetCurrent{this->graph().edge(pAgent->streetId().value())};
506507
previousNodeId = pStreetCurrent->source();
507508
forbiddenTurns = pStreetCurrent->forbiddenTurns();
508509
speedCurrent = pStreetCurrent->maxSpeed();
510+
stationaryWeightCurrent = pStreetCurrent->stationaryWeight();
509511
}
510512
511513
// Get path targets for non-random agents
@@ -551,7 +553,9 @@ namespace dsf::mobility {
551553
552554
// Calculate base probability
553555
auto const speedNext{pStreetOut->maxSpeed()};
554-
double probability = speedCurrent * speedNext;
556+
double const stationaryWeightNext = pStreetOut->stationaryWeight();
557+
auto const weightRatio{stationaryWeightNext / stationaryWeightCurrent}; // SQRT (p_i / p_j)
558+
double probability = speedCurrent * speedNext * std::sqrt(weightRatio);
555559
556560
// Apply error probability for non-random agents
557561
if (this->m_errorProbability.has_value() && !pathTargets.empty()) {

src/dsf/mobility/RoadNetwork.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,21 @@ namespace dsf::mobility {
841841
addEdge<Street>(std::move(street));
842842
}
843843

844+
void RoadNetwork::setStreetStationaryWeights(std::unordered_map<Id, double> const& weights) {
845+
std::for_each(DSF_EXECUTION m_edges.cbegin(),
846+
m_edges.cend(),
847+
[this](auto const& pair) {
848+
auto const streetId = pair.first;
849+
auto& pStreet = edge(pair.second);
850+
auto it = weights.find(streetId);
851+
if (it != weights.end()) {
852+
pStreet->setStationaryWeight(it->second);
853+
} else {
854+
pStreet->setStationaryWeight(1.0);
855+
}
856+
});
857+
}
858+
844859
const std::unique_ptr<Street>* RoadNetwork::street(Id source, Id destination) const {
845860
// Get the iterator at id m_cantorPairingHashing(source, destination)
846861
try {

src/dsf/mobility/RoadNetwork.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ namespace dsf::mobility {
185185
(is_street_v<std::remove_reference_t<Tn>> && ...)
186186
void addStreets(T1&& street, Tn&&... streets);
187187

188+
void setStreetStationaryWeights(std::unordered_map<Id, double> const& streetWeights);
189+
188190
/// @brief Get a street from the graph
189191
/// @param source The source node
190192
/// @param destination The destination node

src/dsf/mobility/Street.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ namespace dsf::mobility {
5050
std::vector<Direction> m_laneMapping;
5151
// std::unordered_map<Id, double> m_transitionProbabilities;
5252
std::optional<Counter> m_counter;
53+
double m_stationaryWeight{1.0};
5354

5455
public:
5556
/// @brief Construct a new Street object
@@ -90,6 +91,11 @@ namespace dsf::mobility {
9091
// std::unordered_map<Id, double> const& transitionProbabilities) {
9192
// m_transitionProbabilities = transitionProbabilities;
9293
// };
94+
/// @brief Set the street's stationary weight
95+
/// @param weight The street's stationary weight
96+
inline void setStationaryWeight(double const weight) {
97+
m_stationaryWeight = weight;
98+
}
9399
/// @brief Enable a coil (dsf::Counter sensor) on the street
94100
/// @param name The name of the counter (default is "Coil_<street_id>")
95101
void enableCounter(std::string name = std::string());
@@ -117,7 +123,9 @@ namespace dsf::mobility {
117123
/// @brief Check if the street is full
118124
/// @return bool, True if the street is full, false otherwise
119125
inline bool isFull() const final { return this->nAgents() == this->m_capacity; }
120-
126+
/// @brief Get the street's stationary weight
127+
/// @return double The street's stationary weight
128+
inline auto stationaryWeight() const noexcept { return m_stationaryWeight; }
121129
// inline auto const& transitionProbabilities() const {
122130
// return m_transitionProbabilities;
123131
// }

0 commit comments

Comments
 (0)