@@ -459,7 +459,8 @@ namespace dsm {
459459 void Dynamics<Delay>::m_evolveStreet(const Id streetId,
460460 const std::unique_ptr<Street>& pStreet,
461461 bool reinsert_agents) {
462- for (auto queueIndex = 0 ; queueIndex < pStreet->nLanes (); ++queueIndex) {
462+ auto const nLanes = pStreet->nLanes ();
463+ for (auto queueIndex = 0 ; queueIndex < nLanes; ++queueIndex) {
463464 if (m_uniformDist (m_generator) > m_maxFlowPercentage ||
464465 pStreet->queue (queueIndex).empty ()) {
465466 continue ;
@@ -475,18 +476,16 @@ namespace dsm {
475476 }
476477 if (destinationNode->isTrafficLight ()) {
477478 auto & tl = dynamic_cast <TrafficLight<Delay>&>(*destinationNode);
478- if (tl.leftTurnRatio ().has_value ()) {
479- auto it = m_agentNextStreetId.find (agentId);
480- if (it == m_agentNextStreetId.end ()) {
481- if (!tl.isGreen (streetId, 0 .)) {
482- continue ;
483- }
484- } else {
485- auto const & nextStreet{m_graph.streetSet ()[m_agentNextStreetId[agentId]]};
486- auto const delta{nextStreet->deltaAngle (pStreet->angle ())};
487- if (!tl.isGreen (streetId, delta)) {
488- continue ;
489- }
479+ if (tl.leftTurnRatio ().has_value () && nLanes > 1 && queueIndex == nLanes - 1 ) {
480+ if (tl.isGreen (streetId) &&
481+ tl.counter () >
482+ tl.delay ().value ().first * (1 . - tl.leftTurnRatio ().value ().first )) {
483+ continue ;
484+ } else if (!tl.isGreen (streetId) &&
485+ tl.counter () > tl.delay ().value ().first +
486+ tl.delay ().value ().second *
487+ (1 . - tl.leftTurnRatio ().value ().second )) {
488+ continue ;
490489 }
491490 } else if (!tl.isGreen (streetId)) {
492491 continue ;
0 commit comments