def schedule_departure(self): p('Scheduling departure of %s at %s. Waypoint: %s' % (self.aircraft, self.aircraft.departure_time, self.aircraft.route.waypoints[0])) self.add_event( sim.Event('aircraft-depart', self.aircraft, self.aircraft.departure_time))
def handle_departure(event): """Adds the aircraft to the candidate stack and schedules lock event.""" aircraft = event.sender global allocator # Register which hub this aircraft will fly to aircraft.hub = aircraft.route.waypoints[0] #assert aircraft.time_to_waypoint() > config.lock_time # If the origin lies within the hub lock area, the aircraft cannot # reach cruise before reaching the hub, so instead we ignore it altogether # and tell it to fly directly to its destination instead of via the hub. if (aircraft.time_to_waypoint() < config.lock_time): # Reset the aircraft route aircraft.route.waypoints = [aircraft.position, aircraft.destination] aircraft.route.init_segments() aircraft.controller.calibrate() aircraft.is_excluded = True p('warning', ('Excluded from flying to the hub: %s' % (aircraft))) return allocator.add_aircraft(aircraft) sim.events.append( sim.Event( 'enter-lock-area', aircraft, # If aircraft departs from within lock area, set lock time to now sim.time + max(aircraft.time_to_waypoint() - config.lock_time, 0)))
def init(hubs): assert len(hubs) > 0 sim.dispatcher.register('aircraft-at-waypoint', handle_at_waypoint) sim.dispatcher.register('sim-finish', handle_finish) # Also set an event that clears the aircraft each $interval mins for i in np.arange(0, 24 * 60 + interval_length, interval_length): sim.events.append(sim.Event('clear-hub-queue', 'hub', float(i))) vars[i] = 0