@@ -43,7 +43,7 @@ namespace dsm {
4343 protected:
4444 Time m_previousOptimizationTime;
4545 double m_errorProbability;
46- double m_maxFlowPercentage ;
46+ double m_passageProbability ;
4747 std::vector<double > m_travelTimes;
4848 std::unordered_map<Id, Id> m_agentNextStreetId;
4949 bool m_forcePriorities;
@@ -88,11 +88,8 @@ namespace dsm {
8888 // / @param errorProbability The error probability
8989 // / @throw std::invalid_argument If the error probability is not between 0 and 1
9090 void setErrorProbability (double errorProbability);
91- // / @brief Set the maximum flow percentage
92- // / @param maxFlowPercentage The maximum flow percentage
93- // / @details The maximum flow percentage is the percentage of the maximum flow that a street can transmit. Default is 1 (100%).
94- // / @throw std::invalid_argument If the maximum flow percentage is not between 0 and 1
95- void setMaxFlowPercentage (double maxFlowPercentage);
91+
92+ void setPassageProbability (double passageProbability);
9693 // / @brief Set the force priorities flag
9794 // / @param forcePriorities The flag
9895 // / @details If true, if an agent cannot move to the next street, the whole node is skipped
@@ -151,7 +148,7 @@ namespace dsm {
151148 : Dynamics<Agent<delay_t >>(graph, seed),
152149 m_previousOptimizationTime{0 },
153150 m_errorProbability{0 .},
154- m_maxFlowPercentage {1 .},
151+ m_passageProbability {1 .},
155152 m_forcePriorities{false } {
156153 for (const auto & [streetId, street] : this ->m_graph .streetSet ()) {
157154 m_streetTails.emplace (streetId, 0 );
@@ -183,13 +180,16 @@ namespace dsm {
183180 Id RoadDynamics<delay_t >::m_nextStreetId(Id agentId,
184181 Id nodeId,
185182 std::optional<Id> streetId) {
183+ auto const & pAgent{this ->m_agents [agentId]};
186184 auto possibleMoves = this ->m_graph .adjMatrix ().getRow (nodeId, true );
187- std::uniform_real_distribution<double > uniformDist{0 ., 1 .};
188- if (this ->m_itineraries .size () > 0 &&
189- uniformDist (this ->m_generator ) > m_errorProbability) {
190- const auto & it = this ->m_itineraries [this ->m_agents [agentId]->itineraryId ()];
191- if (it->destination () != nodeId) {
192- possibleMoves = it->path ().getRow (nodeId, true );
185+ if (!pAgent->isRandom ()) {
186+ std::uniform_real_distribution<double > uniformDist{0 ., 1 .};
187+ if (this ->m_itineraries .size () > 0 &&
188+ uniformDist (this ->m_generator ) > m_errorProbability) {
189+ const auto & it = this ->m_itineraries [pAgent->itineraryId ()];
190+ if (it->destination () != nodeId) {
191+ possibleMoves = it->path ().getRow (nodeId, true );
192+ }
193193 }
194194 }
195195 assert (possibleMoves.size () > 0 );
@@ -233,8 +233,7 @@ namespace dsm {
233233 auto const nLanes = pStreet->nLanes ();
234234 std::uniform_real_distribution<double > uniformDist{0 ., 1 .};
235235 for (auto queueIndex = 0 ; queueIndex < nLanes; ++queueIndex) {
236- if (uniformDist (this ->m_generator ) > m_maxFlowPercentage ||
237- pStreet->queue (queueIndex).empty ()) {
236+ if (pStreet->queue (queueIndex).empty ()) {
238237 continue ;
239238 }
240239 const auto agentId{pStreet->queue (queueIndex).front ()};
@@ -254,8 +253,23 @@ namespace dsm {
254253 continue ;
255254 }
256255 }
257- if (destinationNode->id () ==
258- this ->m_itineraries [pAgent->itineraryId ()]->destination ()) {
256+ auto const bCanPass = uniformDist (this ->m_generator ) < m_passageProbability;
257+ bool bArrived{false };
258+ if (!bCanPass) {
259+ if (pAgent->isRandom ()) {
260+ m_agentNextStreetId.erase (agentId);
261+ bArrived = true ;
262+ } else {
263+ continue ;
264+ }
265+ }
266+ if (!pAgent->isRandom ()) {
267+ if (destinationNode->id () ==
268+ this ->m_itineraries [pAgent->itineraryId ()]->destination ()) {
269+ bArrived = true ;
270+ }
271+ }
272+ if (bArrived) {
259273 pStreet->dequeue (queueIndex);
260274 m_travelTimes.push_back (pAgent->time ());
261275 if (reinsert_agents) {
@@ -345,6 +359,8 @@ namespace dsm {
345359 template <typename delay_t >
346360 requires (is_numeric_v<delay_t >)
347361 void RoadDynamics<delay_t >::m_evolveAgents() {
362+ std::uniform_int_distribution<Id> nodeDist{
363+ 0 , static_cast <Id>(this ->m_graph .nNodes () - 1 )};
348364 for (const auto & [agentId, agent] : this ->m_agents ) {
349365 if (agent->delay () > 0 ) {
350366 const auto & street{this ->m_graph .streetSet ()[agent->streetId ().value ()]};
@@ -361,12 +377,18 @@ namespace dsm {
361377 agent->decrementDelay ();
362378 if (agent->delay () == 0 ) {
363379 auto const nLanes = street->nLanes ();
364- if (this ->m_itineraries [agent->itineraryId ()]->destination () ==
365- street->nodePair ().second ) {
366- agent->updateItinerary ();
380+ bool bArrived{false };
381+ if (!agent->isRandom ()) {
382+ if (this ->m_itineraries [agent->itineraryId ()]->destination () ==
383+ street->nodePair ().second ) {
384+ agent->updateItinerary ();
385+ }
386+ if (this ->m_itineraries [agent->itineraryId ()]->destination () ==
387+ street->nodePair ().second ) {
388+ bArrived = true ;
389+ }
367390 }
368- if (this ->m_itineraries [agent->itineraryId ()]->destination () ==
369- street->nodePair ().second ) {
391+ if (bArrived) {
370392 std::uniform_int_distribution<size_t > laneDist{
371393 0 , static_cast <size_t >(nLanes - 1 )};
372394 street->enqueue (agentId, laneDist (this ->m_generator ));
@@ -398,8 +420,9 @@ namespace dsm {
398420 }
399421 } else if (!agent->streetId ().has_value () &&
400422 !m_agentNextStreetId.contains (agentId)) {
401- assert (agent->srcNodeId ().has_value ());
402- const auto & srcNode{this ->m_graph .nodeSet ()[agent->srcNodeId ().value ()]};
423+ Id srcNodeId = agent->srcNodeId ().has_value () ? agent->srcNodeId ().value ()
424+ : nodeDist (this ->m_generator );
425+ const auto & srcNode{this ->m_graph .nodeSet ()[srcNodeId]};
403426 if (srcNode->isFull ()) {
404427 continue ;
405428 }
@@ -436,13 +459,12 @@ namespace dsm {
436459
437460 template <typename delay_t >
438461 requires (is_numeric_v<delay_t >)
439- void RoadDynamics<delay_t >::setMaxFlowPercentage(double maxFlowPercentage) {
440- if (maxFlowPercentage < 0 . || maxFlowPercentage > 1 .) {
441- throw std::invalid_argument (
442- buildLog (std::format (" The maximum flow percentage ({}) must be between 0 and 1" ,
443- maxFlowPercentage)));
462+ void RoadDynamics<delay_t >::setPassageProbability(double passageProbability) {
463+ if (passageProbability < 0 . || passageProbability > 1 .) {
464+ throw std::invalid_argument (buildLog (std::format (
465+ " The passage probability ({}) must be between 0 and 1" , passageProbability)));
444466 }
445- m_maxFlowPercentage = maxFlowPercentage ;
467+ m_passageProbability = passageProbability ;
446468 }
447469
448470 template <typename delay_t >
0 commit comments