def test_getting_non_existing_signal_group(self): """ Test retrieving signal group by id when this id does not exist """ # GIVEN signalgroup1 = SignalGroup(id="sg1", traffic_lights=[TrafficLight(capacity=1800, lost_time=1)], min_greenyellow=10, max_greenyellow=80, min_red=10, max_red=80) signalgroup2 = SignalGroup(id="sg2", traffic_lights=[TrafficLight(capacity=1800, lost_time=1)], min_greenyellow=10, max_greenyellow=80, min_red=10, max_red=80) intersection = Intersection(signalgroups=[signalgroup1, signalgroup2], conflicts=[], sync_starts=[], offsets=[], greenyellow_leads=[]) with self.assertRaises(ValueError): # WHEN intersection.get_signalgroup(signalgroup_id="sg3")
def test_getting_signal_group(self): """ Test retrieving signal group by id """ # GIVEN signalgroup1 = SignalGroup(id="sg1", traffic_lights=[TrafficLight(capacity=1800, lost_time=1)], min_greenyellow=10, max_greenyellow=80, min_red=10, max_red=80) signalgroup2 = SignalGroup(id="sg2", traffic_lights=[TrafficLight(capacity=1800, lost_time=1)], min_greenyellow=10, max_greenyellow=80, min_red=10, max_red=80) intersection = Intersection(signalgroups=[signalgroup1, signalgroup2], conflicts=[], sync_starts=[], offsets=[], greenyellow_leads=[]) # WHEN/THEN self.assertEqual(intersection.get_signalgroup(signalgroup_id="sg1"), signalgroup1) self.assertEqual(intersection.get_signalgroup(signalgroup_id="sg2"), signalgroup2)
def validate_fixed_order(intersection: Intersection, fts: FixedTimeSchedule, periodic_order: PeriodicOrder) -> None: """ Validate that the the signalgroups indeed receive their greenyellow intervals in the requested periodic order (for only the periodic order that is given as argument). :return: - :raises SafetyException: if the requested order is not satisfied""" first_signalgroup = intersection.get_signalgroup( signalgroup_id=periodic_order.order[0]) first_interval_start = fts.get_greenyellow_interval(first_signalgroup, k=0).start_greenyellow prev_switch = 0 for signalgroup in periodic_order.order: for interval in fts.get_greenyellow_intervals(signalgroup): # shift schedule such that first greenyellow interval of the first signalgroup in the order starts at time=0 switch = (interval.start_greenyellow - first_interval_start + EPSILON) % fts.period - EPSILON if switch < prev_switch: raise SafetyViolation( f"Periodic order {periodic_order.to_json()} is violated") prev_switch = switch