@@ -550,82 +550,93 @@ namespace dsm {
550550 requires (is_numeric_v<delay_t >)
551551 void RoadDynamics<delay_t >::m_evolveStreet(const std::unique_ptr<Street>& pStreet,
552552 bool reinsert_agents) {
553- auto const nLanes = pStreet->nLanes ();
554- std::uniform_real_distribution<double > uniformDist{0 ., 1 .};
555- bool bCanPass{true };
556- if (pStreet->isStochastic () &&
557- (uniformDist (this ->m_generator ) >
558- dynamic_cast <StochasticStreet&>(*pStreet).flowRate ())) {
559- bCanPass = false ;
560- }
561- for (auto queueIndex = 0 ; queueIndex < nLanes; ++queueIndex) {
562- if (pStreet->queue (queueIndex).empty ()) {
563- continue ;
564- }
565- const auto agentId{pStreet->queue (queueIndex).front ()};
566- auto const & pAgent{this ->agents ().at (agentId)};
567- if (pAgent->freeTime () > this ->time ()) {
568- continue ;
553+ auto const & transportCapacity{pStreet->transportCapacity ()};
554+ for (auto i = 0 ; i < std::ceil (transportCapacity); ++i) {
555+ auto const nLanes = pStreet->nLanes ();
556+ std::uniform_real_distribution<double > uniformDist{0 ., 1 .};
557+ bool bCanPass{true };
558+ if (pStreet->isStochastic () &&
559+ (uniformDist (this ->m_generator ) >
560+ dynamic_cast <StochasticStreet&>(*pStreet).flowRate ())) {
561+ bCanPass = false ;
569562 }
570- pAgent->setSpeed (0 .);
571- const auto & destinationNode{this ->graph ().node (pStreet->target ())};
572- if (destinationNode->isFull ()) {
573- continue ;
563+ if (i == std::ceil (transportCapacity) - 1 ) {
564+ double integral;
565+ double fractional = std::modf (transportCapacity, &integral);
566+ if (fractional != 0 . && uniformDist (this ->m_generator ) > fractional) {
567+ bCanPass = false ;
568+ }
574569 }
575- if (destinationNode->isTrafficLight ()) {
576- auto & tl = dynamic_cast <TrafficLight&>(*destinationNode);
577- auto const direction{pStreet->laneMapping ().at (queueIndex)};
578- if (!tl.isGreen (pStreet->id (), direction)) {
570+ for (auto queueIndex = 0 ; queueIndex < nLanes; ++queueIndex) {
571+ if (pStreet->queue (queueIndex).empty ()) {
579572 continue ;
580573 }
581- }
582- bCanPass = bCanPass &&
583- (uniformDist (this ->m_generator ) < m_passageProbability.value_or (1.1 ));
584- bool bArrived{false };
585- if (!bCanPass) {
586- if (pAgent->isRandom ()) {
587- bArrived = true ;
588- } else {
574+ const auto agentId{pStreet->queue (queueIndex).front ()};
575+ auto const & pAgent{this ->agents ().at (agentId)};
576+ if (pAgent->freeTime () > this ->time ()) {
589577 continue ;
590578 }
591- }
592- if (!pAgent->isRandom ()) {
593- if (destinationNode->id () ==
594- this ->itineraries ().at (pAgent->itineraryId ())->destination ()) {
595- bArrived = true ;
579+ pAgent->setSpeed (0 .);
580+ const auto & destinationNode{this ->graph ().node (pStreet->target ())};
581+ if (destinationNode->isFull ()) {
582+ continue ;
583+ }
584+ if (destinationNode->isTrafficLight ()) {
585+ auto & tl = dynamic_cast <TrafficLight&>(*destinationNode);
586+ auto const direction{pStreet->laneMapping ().at (queueIndex)};
587+ if (!tl.isGreen (pStreet->id (), direction)) {
588+ continue ;
589+ }
590+ }
591+ bCanPass = bCanPass &&
592+ (uniformDist (this ->m_generator ) < m_passageProbability.value_or (1.1 ));
593+ bool bArrived{false };
594+ if (!bCanPass) {
595+ if (pAgent->isRandom ()) {
596+ bArrived = true ;
597+ } else {
598+ continue ;
599+ }
600+ }
601+ if (!pAgent->isRandom ()) {
602+ if (destinationNode->id () ==
603+ this ->itineraries ().at (pAgent->itineraryId ())->destination ()) {
604+ bArrived = true ;
605+ }
606+ }
607+ if (bArrived) {
608+ pStreet->dequeue (queueIndex);
609+ m_travelDTs.push_back (
610+ {pAgent->distance (),
611+ static_cast <double >(this ->time () - pAgent->spawnTime ())});
612+ if (reinsert_agents) {
613+ // reset Agent's values
614+ pAgent->reset (this ->time ());
615+ } else {
616+ m_agentsToRemove.push_back (agentId);
617+ // this->removeAgent(agentId);
618+ }
619+ continue ;
620+ }
621+ auto const & nextStreet{
622+ this ->graph ().edge (this ->agents ().at (agentId)->nextStreetId ().value ())};
623+ if (nextStreet->isFull ()) {
624+ continue ;
596625 }
597- }
598- if (bArrived) {
599626 pStreet->dequeue (queueIndex);
600- m_travelDTs.push_back ({pAgent->distance (),
601- static_cast <double >(this ->time () - pAgent->spawnTime ())});
602- if (reinsert_agents) {
603- // reset Agent's values
604- pAgent->reset (this ->time ());
605- } else {
606- m_agentsToRemove.push_back (agentId);
607- // this->removeAgent(agentId);
627+ if (destinationNode->id () != nextStreet->source ()) {
628+ Logger::error (std::format (" Agent {} is going to the wrong street" , agentId));
629+ }
630+ assert (destinationNode->id () == nextStreet->source ());
631+ if (destinationNode->isIntersection ()) {
632+ auto & intersection = dynamic_cast <Intersection&>(*destinationNode);
633+ auto const delta{nextStreet->deltaAngle (pStreet->angle ())};
634+ // m_increaseTurnCounts(pStreet->id(), delta);
635+ intersection.addAgent (delta, agentId);
636+ } else if (destinationNode->isRoundabout ()) {
637+ auto & roundabout = dynamic_cast <Roundabout&>(*destinationNode);
638+ roundabout.enqueue (agentId);
608639 }
609- continue ;
610- }
611- auto const & nextStreet{
612- this ->graph ().edge (this ->agents ().at (agentId)->nextStreetId ().value ())};
613- if (nextStreet->isFull ()) {
614- continue ;
615- }
616- pStreet->dequeue (queueIndex);
617- if (destinationNode->id () != nextStreet->source ()) {
618- Logger::error (std::format (" Agent {} is going to the wrong street" , agentId));
619- }
620- assert (destinationNode->id () == nextStreet->source ());
621- if (destinationNode->isIntersection ()) {
622- auto & intersection = dynamic_cast <Intersection&>(*destinationNode);
623- auto const delta{nextStreet->deltaAngle (pStreet->angle ())};
624- // m_increaseTurnCounts(pStreet->id(), delta);
625- intersection.addAgent (delta, agentId);
626- } else if (destinationNode->isRoundabout ()) {
627- auto & roundabout = dynamic_cast <Roundabout&>(*destinationNode);
628- roundabout.enqueue (agentId);
629640 }
630641 }
631642 }
@@ -1111,9 +1122,7 @@ namespace dsm {
11111122 if (bUpdateData) {
11121123 m_streetTails[streetId] += pStreet->nExitingAgents ();
11131124 }
1114- for (auto i = 0 ; i < pStreet->transportCapacity (); ++i) {
1115- m_evolveStreet (pStreet, reinsert_agents);
1116- }
1125+ m_evolveStreet (pStreet, reinsert_agents);
11171126 }
11181127 });
11191128 std::for_each (this ->m_agentsToRemove .cbegin (),
0 commit comments