Ejemplo n.º 1
0
def run():

    # Discount incurred on formation trajectory by follower
    alpha = .15

    # The formation hub
    hub = Waypoint('AMS')

    # The end point of trunk route (midpoint of the destinations)
    mid = Waypoint('JFK')

    # The actual destination of current participant
    des = Waypoint('SFO')

    # The trunk route itself
    trunk = Segment(hub, mid)

    hookoff = get_hookoff(trunk, des, alpha)

    print 'The trunk length = %d NM' % trunk.get_length()
    print 'The hookoff distance = %d NM' % d(hub, hookoff)
    print 'Therefore, Q = %.2f' % (d(hub, hookoff) / trunk.get_length())
Ejemplo n.º 2
0
    def calibrate(self):
        """Determines the trunk route and hookoff points"""
        
        # Determine formation trunk route
        destinations = []
        for aircraft in self:
            destinations.append(aircraft.destination)
        arrival_midpoint = midpoint(destinations)
        p('destinations: %s' % destinations)
        p('midpoint = %s' % arrival_midpoint)
        hub_to_midpoint = Segment(aircraft.hub, arrival_midpoint)
    
        # Determine hookoff point for each aircraft, except the last
        for aircraft in self:
            
            hub_to_destination = Segment(aircraft.hub, aircraft.destination)
            
            p('flight %s hub %s to destination: %s' % (
                aircraft,
                '%s{%d, %d}' % (
                    aircraft.hub,
                    aircraft.hub.lat,
                    aircraft.hub.lon
                ),
                aircraft.destination
            ))
            p('flight %s hub %s to midpoint: %s' % (
                aircraft,
                '%s{%d, %d}' % (
                    aircraft.hub,
                    aircraft.hub.lat,
                    aircraft.hub.lon
                ),
                arrival_midpoint
            ))
            
            aircraft.hookoff_point = get_hookoff(
                hub_to_midpoint,
                aircraft.destination,
                config.alpha
            )
            
            hub_to_hookoff = Segment(aircraft.hub, aircraft.hookoff_point)
            
            aircraft.Q = hub_to_hookoff.get_length() /\
                         hub_to_midpoint.get_length()

            p('flight %s, hub %s to hook-off point: %s' % (
                aircraft,
                '%s{%d, %d}' % (
                    aircraft.hub,
                    aircraft.hub.lat,
                    aircraft.hub.lon
                ),
                aircraft.hookoff_point
            ))
    
            aircraft.hookoff_point.name = 'hookoff-%s' % aircraft.hookoff_point
            
        # Place aircraft in order, ascending with Q, to fulfill LIFO condition.
        formation = sorted(self, key = lambda item: item.Q)
    
        # All aircraft at the front of the formation having the same destination
        # should hook off where the previous buddy (having a different
        # destination) hooked off.
    
        # Example: formation AMS-SFO, BRU-SFO, LHR-ATL.
        # AMS-SFO and BRU-SFO should hook off where LHR-ATL hooked off.
        # @todo Let AMS-SFO and BRU-SFO continue together along a new average
        #       formation trajectory (in this case directly to the destination)
    
        # First find the leading set of aircraft having the same destination
        formation.reverse()
        leading_destination = formation[0].destination
        leaders = []
        for aircraft in formation:
            
            # Start with always incurring benefits
            aircraft.incurs_benefits = True
    
            if not aircraft.destination.coincides(leading_destination):
                aircraft.is_leader = False
                continue

            aircraft.is_leader = True
            
            # Only the first leader incurs no benefits at all
            if len(leaders) == 0:
                aircraft.incurs_benefits = False
            
            leaders.append(aircraft)
    
        p('Leaders of formation %s are %s' % (
            formation,
            leaders
        ))
    
        # Then find the buddy just before the set of leading aircraft, if
        # it exists.
        try:
            # The leaders: same hookoff point as last buddy.
            last_buddy = formation[len(leaders)]
            for aircraft in leaders:
                aircraft.Q = last_buddy.Q
                #aircraft.P = last_buddy.P
                aircraft.hookoff_point = last_buddy.hookoff_point
        except IndexError:
            pass
    
        # Change reversed formation back to normal
        formation.reverse()

        for aircraft in formation:
    
            p('Adjusting waypoints of %s. Initial waypoints: %s' % (
                aircraft,
                aircraft.route.waypoints
            ))
            aircraft.route.waypoints = [
                #aircraft.hub,
                aircraft.hookoff_point,
                aircraft.destination]
            aircraft.route.init_segments()
            p('Adjusted waypoints of %s. New waypoints: %s' % (
                aircraft,
                aircraft.route.waypoints
            ))
            p('Need to calibrate aircraft %s (%s) in formation %s' % (
                aircraft, aircraft.route, formation
            ))
            aircraft.controller.calibrate()
Ejemplo n.º 3
0
    def calibrate(self):
        """Determines the trunk route and hookoff points"""

        # Determine formation trunk route
        destinations = []
        for aircraft in self:
            destinations.append(aircraft.destination)
        arrival_midpoint = midpoint(destinations)
        p('destinations: %s' % destinations)
        p('midpoint = %s' % arrival_midpoint)
        hub_to_midpoint = Segment(aircraft.hub, arrival_midpoint)

        # Determine hookoff point for each aircraft, except the last
        for aircraft in self:

            hub_to_destination = Segment(aircraft.hub, aircraft.destination)

            p('flight %s hub %s to destination: %s' %
              (aircraft, '%s{%d, %d}' %
               (aircraft.hub, aircraft.hub.lat, aircraft.hub.lon),
               aircraft.destination))
            p('flight %s hub %s to midpoint: %s' %
              (aircraft, '%s{%d, %d}' %
               (aircraft.hub, aircraft.hub.lat, aircraft.hub.lon),
               arrival_midpoint))

            aircraft.hookoff_point = get_hookoff(hub_to_midpoint,
                                                 aircraft.destination,
                                                 config.alpha)

            hub_to_hookoff = Segment(aircraft.hub, aircraft.hookoff_point)

            aircraft.Q = hub_to_hookoff.get_length() /\
                         hub_to_midpoint.get_length()

            p('flight %s, hub %s to hook-off point: %s' %
              (aircraft, '%s{%d, %d}' %
               (aircraft.hub, aircraft.hub.lat, aircraft.hub.lon),
               aircraft.hookoff_point))

            aircraft.hookoff_point.name = 'hookoff-%s' % aircraft.hookoff_point

        # Place aircraft in order, ascending with Q, to fulfill LIFO condition.
        formation = sorted(self, key=lambda item: item.Q)

        # All aircraft at the front of the formation having the same destination
        # should hook off where the previous buddy (having a different
        # destination) hooked off.

        # Example: formation AMS-SFO, BRU-SFO, LHR-ATL.
        # AMS-SFO and BRU-SFO should hook off where LHR-ATL hooked off.
        # @todo Let AMS-SFO and BRU-SFO continue together along a new average
        #       formation trajectory (in this case directly to the destination)

        # First find the leading set of aircraft having the same destination
        formation.reverse()
        leading_destination = formation[0].destination
        leaders = []
        for aircraft in formation:

            # Start with always incurring benefits
            aircraft.incurs_benefits = True

            if not aircraft.destination.coincides(leading_destination):
                aircraft.is_leader = False
                continue

            aircraft.is_leader = True

            # Only the first leader incurs no benefits at all
            if len(leaders) == 0:
                aircraft.incurs_benefits = False

            leaders.append(aircraft)

        p('Leaders of formation %s are %s' % (formation, leaders))

        # Then find the buddy just before the set of leading aircraft, if
        # it exists.
        try:
            # The leaders: same hookoff point as last buddy.
            last_buddy = formation[len(leaders)]
            for aircraft in leaders:
                aircraft.Q = last_buddy.Q
                #aircraft.P = last_buddy.P
                aircraft.hookoff_point = last_buddy.hookoff_point
        except IndexError:
            pass

        # Change reversed formation back to normal
        formation.reverse()

        for aircraft in formation:

            p('Adjusting waypoints of %s. Initial waypoints: %s' %
              (aircraft, aircraft.route.waypoints))
            aircraft.route.waypoints = [
                #aircraft.hub,
                aircraft.hookoff_point,
                aircraft.destination
            ]
            aircraft.route.init_segments()
            p('Adjusted waypoints of %s. New waypoints: %s' %
              (aircraft, aircraft.route.waypoints))
            p('Need to calibrate aircraft %s (%s) in formation %s' %
              (aircraft, aircraft.route, formation))
            aircraft.controller.calibrate()