pub fn update_intersection(
        &mut self,
        now: Time,
        id: IntersectionID,
        map: &Map,
        scheduler: &mut Scheduler,
    ) {
        let state = self.state.get_mut(&id).unwrap();
        let signal = map.get_traffic_signal(id);

        // Switch to a new phase?
        if now != Time::START_OF_DAY {
            assert_eq!(now, state.phase_ends_at);
            let old_phase = &signal.phases[state.current_phase];
            match old_phase.phase_type {
                PhaseType::Fixed(_) => {
                    state.current_phase += 1;
                }
                PhaseType::Adaptive(_) => {
                    // TODO Make a better policy here. For now, if there's _anyone_ waiting to
                    // start a protected turn, repeat this phase for the full duration. Note that
                    // "waiting" is only defined as "at the end of the lane, ready to start the
                    // turn." If a vehicle/ped is a second away from the intersection, this won't
                    // detect that. We could pass in all of the Queues here and use that to count
                    // all incoming agents, even ones a little farther away.
                    if state.waiting.keys().all(|req| {
                        old_phase.get_priority_of_turn(req.turn, signal) != TurnPriority::Protected
                    }) {
                        state.current_phase += 1;
                        self.events.push(Event::Alert(
                            AlertLocation::Intersection(id),
                            "Repeating an adaptive phase".to_string(),
                        ));
                    }
                }
            }
            if state.current_phase == signal.phases.len() {
                state.current_phase = 0;
            }
        }

        state.phase_ends_at = now
            + signal.phases[state.current_phase]
                .phase_type
                .simple_duration();
        scheduler.push(state.phase_ends_at, Command::UpdateIntersection(id));
        self.wakeup_waiting(now, id, scheduler, map);
    }
// This is only triggered for traffic signals.
This is only triggered for traffic signals.
This is only triggered for traffic signals .
pub fn update_intersection(
        &mut self,
        now: Time,
        id: IntersectionID,
        map: &Map,
        scheduler: &mut Scheduler,
    ) {
        let state = self.state.get_mut(&id).unwrap();
        let signal = map.get_traffic_signal(id);
        // Switch to a new phase?
        if now != Time::START_OF_DAY {
            assert_eq!(now, state.phase_ends_at);
            let old_phase = &signal.phases[state.current_phase];
            match old_phase.phase_type {
                PhaseType::Fixed(_) => {
                    state.current_phase += 1;
                }
                PhaseType::Adaptive(_) => {
                    // TODO Make a better policy here. For now, if there's _anyone_ waiting to
                    // start a protected turn, repeat this phase for the full duration. Note that
                    // "waiting" is only defined as "at the end of the lane, ready to start the
                    // turn." If a vehicle/ped is a second away from the intersection, this won't
                    // detect that. We could pass in all of the Queues here and use that to count
                    // all incoming agents, even ones a little farther away.
                    if state.waiting.keys().all(|req| {
                        old_phase.get_priority_of_turn(req.turn, signal) != TurnPriority::Protected
                    }) {
                        state.current_phase += 1;
                        self.events.push(Event::Alert(
                            AlertLocation::Intersection(id),
                            "Repeating an adaptive phase".to_string(),
                        ));
                    }
                }
            }
            if state.current_phase == signal.phases.len() {
                state.current_phase = 0;
            }
        }
        state.phase_ends_at = now
            + signal.phases[state.current_phase]
                .phase_type
                .simple_duration();
        scheduler.push(state.phase_ends_at, Command::UpdateIntersection(id));
        self.wakeup_waiting(now, id, scheduler, map);
    }
pub fn update_intersection ( & mut self , now : Time , id : IntersectionID , map : & Map , scheduler : & mut Scheduler , ) { let state = self . state . get_mut ( & id ) . unwrap ( ) ; let signal = map . get_traffic_signal ( id ) ; // Switch to a new phase? if now != Time :: START_OF_DAY { assert_eq ! ( now state phase_ends_at ) ; let old_phase = & signal . phases [ state . current_phase ] ; match old_phase . phase_type { PhaseType :: Fixed ( _ ) => { state . current_phase += 1 ; } PhaseType :: Adaptive ( _ ) => { // TODO Make a better policy here. For now, if there's _anyone_ waiting to // start a protected turn, repeat this phase for the full duration. Note that // "waiting" is only defined as "at the end of the lane, ready to start the // turn." If a vehicle/ped is a second away from the intersection, this won't // detect that. We could pass in all of the Queues here and use that to count // all incoming agents, even ones a little farther away. if state . waiting . keys ( ) . all ( | req | { old_phase . get_priority_of_turn ( req . turn , signal ) != TurnPriority :: Protected } ) { state . current_phase += 1 ; self . events . push ( Event :: Alert ( AlertLocation :: Intersection ( id ) , " " . to_string ( ) , ) ) ; } } } if state . current_phase == signal . phases . len ( ) { state . current_phase = 0 ; } } state . phase_ends_at = now + signal . phases [ state . current_phase ] . phase_type . simple_duration ( ) ; scheduler . push ( state . phase_ends_at , Command :: UpdateIntersection ( id ) ) ; self . wakeup_waiting ( now , id , scheduler , map ) ; }
This is only triggered for traffic signals.
This is only triggered for traffic signals .
&mut self
now
Time
id
IntersectionID
map
&Map
scheduler
&mut Scheduler
&mut self
now
Time
id
IntersectionID
map
&Map
scheduler
&mut Scheduler