@@ -568,6 +568,138 @@ TEST_CASE("Dynamics") {
568568 }
569569 }
570570 }
571+ GIVEN (
572+ " A traffic light managing an intersection with 4 3-lanes streets and 4 1-lane "
573+ " streets" ) {
574+ // Streets
575+ Street s0_1{1 , 1 , 30 ., 15 ., std::make_pair (0 , 1 ), 3 };
576+ Street s1_0{5 , 1 , 30 ., 15 ., std::make_pair (1 , 0 ), 3 };
577+ Street s1_2{7 , 1 , 30 ., 15 ., std::make_pair (1 , 2 ), 3 };
578+ Street s2_1{11 , 1 , 30 ., 15 ., std::make_pair (2 , 1 ), 3 };
579+
580+ Street s3_1{8 , 1 , 30 ., 15 ., std::make_pair (3 , 1 )};
581+ Street s1_3{16 , 1 , 30 ., 15 ., std::make_pair (1 , 3 )};
582+ Street s4_1{21 , 1 , 30 ., 15 ., std::make_pair (4 , 1 )};
583+ Street s1_4{9 , 1 , 30 ., 15 ., std::make_pair (1 , 4 )};
584+
585+ Graph graph2;
586+ graph2.addNode (std::make_unique<TrafficLight>(1 ));
587+ graph2.addStreets (s0_1, s1_0, s1_2, s2_1, s3_1, s1_3, s4_1, s1_4);
588+ graph2.buildAdj ();
589+ graph2.adjustNodeCapacities ();
590+ graph2.normalizeStreetCapacities ();
591+ auto const & nodes = graph2.nodeSet ();
592+ auto & tl = dynamic_cast <TrafficLight&>(*nodes.at (1 ));
593+ tl.setDelay (3 );
594+ tl.setLeftTurnRatio (0.3 );
595+ tl.setPhase (2 );
596+ tl.addStreetPriority (1 );
597+ tl.setCoords ({0 ., 0 .});
598+ nodes.at (0 )->setCoords ({-1 ., 0 .});
599+ nodes.at (2 )->setCoords ({1 ., 0 .});
600+ nodes.at (3 )->setCoords ({0 ., -1 .});
601+ nodes.at (4 )->setCoords ({0 ., 1 .});
602+ graph2.buildStreetAngles ();
603+
604+ Dynamics dynamics{graph2};
605+ dynamics.setSeed (69 );
606+
607+ std::vector<uint32_t > destinationNodes{0 , 2 , 3 , 4 };
608+ dynamics.setDestinationNodes (destinationNodes);
609+
610+ CHECK (tl.leftTurnRatio ().has_value ());
611+
612+ WHEN (" We add agents and make the system evolve" ) {
613+ Agent agent1{0 , 2 , 0 };
614+ Agent agent2{1 , 4 , 0 };
615+ dynamics.addAgents (agent1, agent2);
616+ dynamics.evolve (false );
617+ dynamics.evolve (false );
618+ THEN (" The agents are correctly placed" ) {
619+ CHECK_EQ (dynamics.agents ().at (0 )->streetId ().value (), 1 );
620+ CHECK_EQ (dynamics.agents ().at (1 )->streetId ().value (), 1 );
621+ }
622+ dynamics.evolve (false );
623+ dynamics.evolve (false );
624+ dynamics.evolve (false );
625+ THEN (" The agent 0 passes and agent 1 waits" ) {
626+ CHECK_EQ (dynamics.agents ().at (0 )->streetId ().value (), 7 );
627+ CHECK_EQ (dynamics.agents ().at (1 )->streetId ().value (), 1 );
628+ }
629+ dynamics.evolve (false );
630+ THEN (" The agent 1 passes" ) {
631+ CHECK_EQ (dynamics.agents ().at (0 )->streetId ().value (), 7 );
632+ CHECK_EQ (dynamics.agents ().at (1 )->streetId ().value (), 9 );
633+ }
634+ }
635+ }
636+ GIVEN (
637+ " A traffic light managing an intersection with 4 3-lanes streets and 4 1-lane "
638+ " streets" ) {
639+ // Streets
640+ Street s0_1{1 , 1 , 30 ., 15 ., std::make_pair (0 , 1 ), 3 };
641+ Street s1_0{5 , 1 , 30 ., 15 ., std::make_pair (1 , 0 ), 3 };
642+ Street s1_2{7 , 1 , 30 ., 15 ., std::make_pair (1 , 2 ), 3 };
643+ Street s2_1{11 , 1 , 30 ., 15 ., std::make_pair (2 , 1 ), 3 };
644+
645+ Street s3_1{8 , 1 , 30 ., 15 ., std::make_pair (3 , 1 )};
646+ Street s1_3{16 , 1 , 30 ., 15 ., std::make_pair (1 , 3 )};
647+ Street s4_1{21 , 1 , 30 ., 15 ., std::make_pair (4 , 1 )};
648+ Street s1_4{9 , 1 , 30 ., 15 ., std::make_pair (1 , 4 )};
649+
650+ Graph graph2;
651+ graph2.addNode (std::make_unique<TrafficLight>(1 ));
652+ graph2.addStreets (s0_1, s1_0, s1_2, s2_1, s3_1, s1_3, s4_1, s1_4);
653+ graph2.buildAdj ();
654+ graph2.adjustNodeCapacities ();
655+ graph2.normalizeStreetCapacities ();
656+ auto const & nodes = graph2.nodeSet ();
657+ auto & tl = dynamic_cast <TrafficLight&>(*nodes.at (1 ));
658+ tl.setDelay (3 );
659+ tl.setLeftTurnRatio (0.3 );
660+ // NO! Now testing red light
661+ // tl.setPhase(2);
662+ tl.addStreetPriority (21 );
663+ tl.addStreetPriority (8 );
664+ tl.setCoords ({0 ., 0 .});
665+ nodes.at (0 )->setCoords ({-1 ., 0 .});
666+ nodes.at (2 )->setCoords ({1 ., 0 .});
667+ nodes.at (3 )->setCoords ({0 ., -1 .});
668+ nodes.at (4 )->setCoords ({0 ., 1 .});
669+ graph2.buildStreetAngles ();
670+
671+ Dynamics dynamics{graph2};
672+ dynamics.setSeed (69 );
673+
674+ std::vector<uint32_t > destinationNodes{0 , 2 , 3 , 4 };
675+ dynamics.setDestinationNodes (destinationNodes);
676+
677+ CHECK (tl.leftTurnRatio ().has_value ());
678+
679+ WHEN (" We add agents and make the system evolve" ) {
680+ Agent agent1{0 , 2 , 0 };
681+ Agent agent2{1 , 4 , 0 };
682+ dynamics.addAgents (agent1, agent2);
683+ dynamics.evolve (false );
684+ dynamics.evolve (false );
685+ THEN (" The agents are correctly placed" ) {
686+ CHECK_EQ (dynamics.agents ().at (0 )->streetId ().value (), 1 );
687+ CHECK_EQ (dynamics.agents ().at (1 )->streetId ().value (), 1 );
688+ }
689+ dynamics.evolve (false );
690+ dynamics.evolve (false );
691+ dynamics.evolve (false );
692+ THEN (" The agent 0 passes and agent 1 waits" ) {
693+ CHECK_EQ (dynamics.agents ().at (0 )->streetId ().value (), 7 );
694+ CHECK_EQ (dynamics.agents ().at (1 )->streetId ().value (), 1 );
695+ }
696+ dynamics.evolve (false );
697+ THEN (" The agent 1 passes" ) {
698+ CHECK_EQ (dynamics.agents ().at (0 )->streetId ().value (), 7 );
699+ CHECK_EQ (dynamics.agents ().at (1 )->streetId ().value (), 9 );
700+ }
701+ }
702+ }
571703 }
572704 SUBCASE (" Traffic Lights optimization algorithm" ) {
573705 GIVEN (" A dynamics object with a traffic light intersection" ) {
0 commit comments