예제 #1
0
 def get_dist_martix(self):
     size = traf.lat.shape[0]
     return geo.latlondist_matrix(np.repeat(traf.lat, size),
                                  np.repeat(traf.lon, size),
                                  np.tile(traf.lat, size),
                                  np.tile(traf.lon,
                                          size)).reshape(size, size)
예제 #2
0
 def get_dist_matrix(self, _id, traf):
     size = traf.lat.shape[0]
     dist_matrix = geo.latlondist_matrix(np.repeat(traf.lat, size),
                                         np.repeat(traf.lon, size),
                                         np.tile(traf.lat, size),
                                         np.tile(traf.lon,
                                                 size)).reshape(size, size)
     return dist_matrix
예제 #3
0
def get_distance_matrix_ac(_id):
    size = traf.lat.shape[0]
    distances = geo.latlondist_matrix(np.repeat(traf.lat[_id], size),
                                      np.repeat(traf[_id].lon, size),
                                      np.tile(traf.lat, size),
                                      np.tile(traf.lon,
                                              size)).reshape(size, size)

    return distances
예제 #4
0
def get_closest_ac_distance(self, state, traffic, route_keeper):
    o_lat, o_lon, id_ = state[:3]
    index = int(id_[2:])
    rte = int(route_keeper[index])
    lat, lon, g_lat, g_lon, h = self.positions[rte]
    size = traffic.lat.shape[0]
    index = np.arange(size).reshape(-1, 1)
    ownship_obj = LineString([[o_lon, o_lat, 31000], [g_lon, g_lat, 31000]])
    d = geo.latlondist_matrix(np.repeat(o_lat, size), np.repeat(o_lon, size),
                              traffic.lat, traffic.lon)
    d = d.reshape(-1, 1)

    dist = np.concatenate([d, index], axis=1)

    dist = sorted(np.array(dist), key=itemgetter(0))[1:]
    if len(dist) > 0:
        for i in range(len(dist)):

            index = int(dist[i][1])
            id_ = traffic.id[index]
            index_route = int(id_[2:])

            rte_int = route_keeper[index_route]
            lat, lon, g_lat, g_lon, h = self.positions[rte_int]
            int_obj = LineString(
                [[traffic.lon[index], traffic.lat[index], 31000],
                 [g_lon, g_lat, 31000]])

            if not ownship_obj.intersects(int_obj):
                continue

            if not (rte in self.intersection_distances.keys() and rte in self.intersection_distances[rte].keys()) \
                    and rte_int != rte:
                continue

            if dist[i][0] > 100:
                continue

            return dist[i][0]
    else:
        return np.inf

    return np.inf
예제 #5
0
def get_normals_states(state, traf, ac_routes, next_action, no_states,
                       terminal_ac, agent, previous_observation, observation):
    number_of_aircraft = traf.lat.shape[0]

    normal_state = np.zeros((len(terminal_ac[terminal_ac != 1]), 5))

    size = traf.lat.shape[0]
    index = np.arange(size).reshape(-1, 1)

    distancematrix = geo.latlondist_matrix(
        np.repeat(state[:, 0], number_of_aircraft),
        np.repeat(state[:, 1], number_of_aircraft),
        np.tile(state[:, 0], number_of_aircraft),
        np.tile(state[:, 1],
                number_of_aircraft)).reshape(number_of_aircraft,
                                             number_of_aircraft)

    sort = np.array(np.argsort(distancematrix, axis=1))
    total_closest_states = []
    routecount = 0
    i = 0
    j = 0

    max_agents = 1

    count = 0

    for i in range(distancematrix.shape[0]):
        if terminal_ac[i] == 1:
            continue

        r = int(state[i][4])

        normal_state[count, :] = agent.normalize_state(state[i],
                                                       id_=traf.id[i])

        closest_states = []
        count += 1

        routecount = 0
        intruder_count = 0

        for j in range(len(sort[i])):
            index = int(sort[i, j])

            if i == index:
                continue

            if terminal_ac[index] == 1:
                continue

            route = int(state[index][4])

            if route == r and routecount == 2:
                continue

            if route == r:
                routecount += 1

            if distancematrix[i, index] > 100:
                continue

            max_agents = max(max_agents, j)

            if len(closest_states) == 0:
                closest_states = np.array([
                    traf.lat[index], traf.lon[index], traf.tas[index],
                    traf.alt[index], route, traf.ax[index]
                ])

                closest_states = agent.normalize_context(normal_state[count -
                                                                      1],
                                                         closest_states,
                                                         state[i],
                                                         id_=traf.id[index])
            else:
                adding = np.array([
                    traf.lat[index], traf.lon[index], traf.tas[index],
                    traf.alt[index], route, traf.ax[index]
                ])

                adding = agent.normalize_context(normal_state[count - 1],
                                                 adding,
                                                 state[i],
                                                 id_=traf.id[index])

                closest_states = np.append(closest_states, adding, axis=1)

            intruder_count += 1

            if intruder_count == agent.num_intruders:
                break

        if len(closest_states) == 0:
            closest_states = np.zeros(5).reshape(1, 1, 5)

        if len(total_closest_states) == 0:
            total_closest_states = closest_states
        else:
            total_closest_states = np.append(
                tf.keras.preprocessing.sequence.pad_sequences(
                    total_closest_states, agent.num_intruders,
                    dtype='float32'),
                tf.keras.preprocessing.sequence.pad_sequences(
                    closest_states, agent.num_intruders, dtype='float32'),
                axis=0)
    return normal_state, total_closest_states
예제 #6
0
def get_closest_ac(state, store_terminal):
    global n_states, agent

    n_ac = traffic.lat.shape[0]
    norm_state = np.zeros((len(store_terminal[store_terminal != 1]), n_states))

    d = geo.latlondist_matrix(np.repeat(state[:, 0], n_ac), np.repeat(state[:, 1], n_ac), np.tile(state[:, 0], n_ac),
                              np.tile(state[:, 1], n_ac)).reshape(n_ac, n_ac)
    arg_sort = np.array(np.argsort(d, axis=1))

    total_closest_states = []

    max_agents = 1

    count = 0
    for i in range(d.shape[0]):
        r = int(state[i][3])
        lat, lon, g_lat, g_lon, h = agent.positions[r]
        if store_terminal[i] == 1:
            continue
        own_ship_obj = LineString([[state[i][1], state[i][0], 31000], [g_lon, g_lat, 31000]])

        norm_state[count, :] = agent.normalize(state[i], 'state', id_=traffic.id[i])
        closest_states = []
        count += 1

        route_count = 0

        intruder_count = 0

        for j in range(len(arg_sort[i])):

            index = int(arg_sort[i][j])

            if i == index:
                continue

            if store_terminal[index] == 1:
                continue

            route = int(state[index][3])

            if route == r and route_count == 2:
                continue

            if route == r:
                route_count += 1

            lat, lon, g_lat, g_lon, h = agent.positions[route]
            int_obj = LineString([[state[index, 1], state[index, 0], 31000], [g_lon, g_lat, 31000]])

            if not own_ship_obj.intersects(int_obj):
                continue

            if not (r in agent.intersection_distances.keys() and route in agent.intersection_distances[r].keys()) \
                    and route != r:
                continue

            if d[i, index] > 100:
                continue

            max_agents = max(max_agents, j)

            if len(closest_states) == 0:
                closest_states = np.array([traffic.lat[index], traffic.lon[index], traffic.tas[index], route,
                                           traffic.ax[index]])
                closest_states = agent.normalize(norm_state[count - 1], 'context', closest_states, state[i],
                                                 id_=traffic.id[index])
            else:
                closest_states = np.append(closest_states, closest_states, axis=1)

            intruder_count += 1

            if intruder_count == agent.num_intruders:
                break

        if len(closest_states) == 0:
            closest_states = np.array([0, 0, 0, 0, 0, 0, 0]).reshape([1, 1, 7])

        if len(total_closest_states) == 0:
            total_closest_states = closest_states
        else:

            total_closest_states = np.append(
                tf.keras.preprocessing.sequence.pad_sequences(total_closest_states, agent.num_intruders,
                                                              dtype='float32'),
                tf.keras.preprocessing.sequence.pad_sequences(closest_states, agent.num_intruders, dtype='float32'),
                axis=0)

    if len(total_closest_states) == 0:
        total_closest_states = np.array([0, 0, 0, 0, 0, 0, 0]).reshape([1, agent.num_intruders, 7])

    return norm_state, total_closest_states