Пример #1
0
    def state(self):
        """Identify whether the aircraft is on pushbackway or taxiway"""
        # add conflict state
        if self.has_conflict is True:
            return State.conflict

        if self.is_delayed is True:
            self.delayed = True
        if self.itinerary is None or self.itinerary.is_completed:
            # self.status = State.stop
            return State.stop
        if self.itinerary.next_target is None or \
                self.itinerary.current_target is None:
            # self.status = State.stop
            return State.stop
        if self.is_departure is True:
            if type(self.itinerary.current_target.start) is Gate:
                #  do not update state if holdlink is added at gate
                if self.real_time == "":
                    self.real_time = get_seconds_after(
                        self.appear_time, self.sim_time * self.tick_count)
                return State.atGate
            elif type(self.itinerary.current_target) is PushbackWay:
                if self.real_time == "":
                    self.real_time = get_seconds_after(
                        self.appear_time, self.sim_time * self.tick_count)
                return State.pushback
            elif type(self.itinerary.current_target) is Taxiway:
                if len(self.itinerary.current_target.nodes
                       ) > 0 and self.itinerary.current_target.nodes[
                           0].name.startswith('I'):
                    self.ramp_flag = 0
                    # self.status = State.moving
                    return State.taxi
                if self.ramp_flag:
                    # self.status = State.ramp
                    return State.ramp
            return State.taxi
        elif self.is_departure is False:
            if len(
                    self.itinerary.current_target.nodes
            ) > 0 and self.count_intersection(
            ) == 0:  # and self.itinerary.current_target.nodes[0].name.startswith('I'):
                # self.status = State.ramp
                self.ramp_flag = 0
                # self.status = State.ramp
                return State.ramp
            if not self.ramp_flag:
                # self.status = State.ramp
                return State.ramp
            return State.taxi
        # self.status = State.moving
        return State.moving
Пример #2
0
    def tick(self):
        """Moves the clock to next tick."""

        time_after_tick = get_seconds_after(self.now, self.sim_time)
        if time_after_tick > self.end_time:
            raise ClockException("End of the day")
        self.now = time_after_tick
Пример #3
0
    def __add_aircrafts_from_scenario(self, scenario, now, sim_time):

        # NOTE: we will only focus on departures now
        next_tick_time = get_seconds_after(now, sim_time)

        # For all departure flights
        for flight in scenario.departures:

            # Only if the scheduled appear time is between now and next tick
            if not (now <= flight.appear_time
                    and flight.appear_time < next_tick_time):
                continue

            gate, aircraft = flight.from_gate, flight.aircraft

            if self.is_occupied_at(gate):
                # Adds the flight to queue
                queue = self.gate_queue.get(gate, deque())
                queue.append(aircraft)
                self.gate_queue[gate] = queue
                self.logger.info("Adds %s into gate queue", flight)

            else:
                # Adds the flight to the airport
                aircraft.set_location(gate)
                self.add_aircraft(aircraft)
                self.logger.info("Adds %s into the airport", flight)
Пример #4
0
    def __add_aircrafts_from_scenario(self, scenario, now, sim_time,
                                      scheduler):

        # NOTE: we will only focus on departures now
        next_tick_time = get_seconds_after(now, sim_time)

        # For all departure flights
        for flight in scenario.departures:
            # Only if the scheduled appear time is between now and next tick
            if not (now <= flight.appear_time < next_tick_time):
                continue

            gate, aircraft = flight.from_gate, flight.aircraft

            if self.is_occupied_at(gate):
                # Adds the flight to queue
                queue = self.gate_queue.get(gate, deque())
                queue.append(aircraft)
                self.gate_queue[gate] = queue
                self.logger.info("Adds %s into gate queue", flight)
            else:
                # Adds the flight to the airport
                if flight.runway is None:
                    runway_name = next(scheduler.departure_assigner)
                    runway = self.surface.get_link(runway_name)
                    flight.set_runway(runway)
                aircraft.set_location(gate, Aircraft.LOCATION_LEVEL_COARSE)
                self.add_aircraft(aircraft)
                self.logger.info("Adds %s into the airport", flight)

        # Deal with the arrival flights, assume that the runway is always not
        # occupied because this is an arrival flight

        for flight in scenario.arrivals:
            if not (now <= flight.appear_time < next_tick_time):
                continue
            if flight.runway is None:
                runway_name = next(scheduler.arrival_assigner)
                runway = self.surface.get_link(runway_name)
                flight.set_runway(runway)
            runway, aircraft = flight.runway.end, flight.aircraft
            aircraft.set_location(runway, Aircraft.LOCATION_LEVEL_COARSE)
            self.add_aircraft(aircraft)
            self.logger.info(
                "Adds {} arrival flight into the airport".format(flight))
Пример #5
0
 def __is_time_to_reschedule(self):
     reschedule_cycle = Config.params["simulation"]["reschedule_cycle"]
     last_time = self.last_schedule_time
     next_time = (get_seconds_after(last_time, reschedule_cycle)
                  if last_time is not None else None)
     return last_time is None or next_time <= self.now
Пример #6
0
    def __add_aircrafts_from_scenario(self, scenario, now, sim_time,
                                      scheduler):

        # NOTE: we will only focus on departures now
        next_tick_time = get_seconds_after(now, sim_time)
        # Only if the scheduled appear time is between now and next tick
        current_tick_flight = scenario.departures.irange(
            Flight(None, now), Flight(None, next_tick_time), (True, False))

        # For all departure flights
        for flight in list(current_tick_flight):
            gate, aircraft = flight.from_gate, flight.aircraft
            spot = gate.get_spots()

            if flight.runway is None:
                runway_name = next(scheduler.departure_assigner)
                runway = self.surface.get_link(runway_name)
                flight.set_runway(runway)

            if self.is_occupied_at(gate) or self.num_aircrafts_running >= self.max_airpcrafts_running \
                    or not self.terminal_controller.get_departure_access(gate.name, aircraft):
                # Adds the flight to queue
                queue = self.gate_queue.get(gate, deque())
                queue.append(aircraft)

                # Add to gate
                self.gate_queue[gate] = queue
                self.logger.info("Adds %s into gate queue", flight)

            elif self.ramp_control.spot_occupied(spot):
                # Add the flight to spot queue
                self.ramp_control.add_aircraft_to_spot_queue(
                    spot, gate, aircraft)
                self.logger.info("Adds %s into spot queue", flight)

            else:
                # Adds the flight to the airport
                aircraft.set_location(gate, Aircraft.LOCATION_LEVEL_COARSE)
                self.add_aircraft(aircraft)
                self.terminal_controller.add_departure_gate(
                    aircraft, gate.name)
                # print(self.terminal_controller.depature_2_gate.keys())
                self.logger.info("Adds %s into the airport, runway %s", flight,
                                 flight.runway)

            aircraft.set_estimated(flight.departure_time)
            aircraft.set_appear_time(flight.appear_time)
            aircraft.set_sim_time(sim_time)

        # # Deal with the arrival flights, assume that the runway is always not
        # # occupied because this is an arrival flight
        current_tick_flight = scenario.arrivals.irange(
            Flight(None, now), Flight(None, next_tick_time), (True, False))
        for flight in list(current_tick_flight):
            gate, aircraft = flight.to_gate, flight.aircraft
            self.terminal_controller.add_arrival_gate(aircraft, gate.name)
            spot = gate.get_spots()

            if flight.runway is None:
                runway_name = next(scheduler.arrival_assigner)
                runway = self.surface.get_link(runway_name)
                flight.set_runway(runway)
            runway_node, aircraft = flight.runway.end, flight.aircraft
            if self.is_occupied_at(
                    runway_node
            ) or not self.terminal_controller.get_arrival_access(
                    gate.name, aircraft):
                # add the aircraft to queue
                queue = self.runway_gate_queue.get(runway_node, deque())
                queue.append(aircraft)

                # update queue
                self.runway_gate_queue[runway_node] = queue
                self.logger.info("Adds %s into gate queue", flight)
                continue

            aircraft.set_estimated(flight.arrival_time)
            aircraft.set_appear_time(flight.appear_time)
            aircraft.set_sim_time(sim_time)

            aircraft.set_location(runway_node, Aircraft.LOCATION_LEVEL_COARSE)
            self.add_aircraft(aircraft)
            self.logger.info(
                "Adds {} arrival flight into the airport".format(flight))