Beispiel #1
0
    def test_veh_cons_are_nlos_all(self):
        """Tests the function of veh_cons_are_nlos_all"""

        is_nlos_expected = np.array([
            0, 1, 1, 1, 1, 1, 1, 1,
            1, 1, 1, 1, 1, 1, 1,
            1, 1, 0, 1, 0, 1,
            0, 0, 0, 0, 1,
            0, 1, 1, 1,
            0, 0, 1,
            0, 1,
            0], dtype=bool)
        max_distance = 70

        network = DemoNetwork()
        graph_streets = network.build_graph_streets()
        gdf_buildings = network.build_gdf_buildings()
        graph_streets_wave = graph_streets.to_undirected()
        prop.add_edges_if_los(graph_streets_wave,
                              gdf_buildings,
                              max_distance=max_distance)
        vehs_points = network.build_vehs()

        is_nlos_generated = prop.veh_cons_are_nlos_all(
            vehs_points, gdf_buildings)
        result_correct = np.array_equal(is_nlos_generated, is_nlos_expected)

        self.assertTrue(result_correct)
Beispiel #2
0
    def test_add_edges_if_los(self):
        """Tests the function add_edges_if_los"""

        network = DemoNetwork()
        graph_streets = network.build_graph_streets()
        gdf_buildings = network.build_gdf_buildings()
        graph_streets_wave = graph_streets.to_undirected()
        prop.add_edges_if_los(graph_streets_wave,
                              gdf_buildings,
                              max_distance=70)

        self.assertTrue(graph_streets_wave.has_edge(5, 7))
        self.assertFalse(graph_streets_wave.has_edge(0, 3))
        self.assertFalse(graph_streets_wave.has_edge(7, 9))
Beispiel #3
0
    def test_calc_path_redundancy(self):
        """Tests the function calc_center_path_redundancy"""

        max_dist = {'nlos': 100, 'olos_los': 150}
        node_redundancies_expteced = [3, 3, 4, 5, 5, 5, 6, 3]
        edge_redundancies_expteced = [3, 3, 6, 6, 6, 5, 6, 3]
        sqrt = np.sqrt
        distances_expected = [sqrt(40 ** 2 + 110 ** 2),
                              sqrt(40 ** 2 + 110 ** 2),
                              70,
                              sqrt(30 ** 2 + 40 ** 2),
                              sqrt(30 ** 2 + 40 ** 2),
                              sqrt(30 ** 2 + 40 ** 2),
                              60,
                              sqrt(90 ** 2 + 40 ** 2)]

        network = DemoNetwork()
        graph_streets = network.build_graph_streets()
        gdf_buildings = network.build_gdf_buildings()
        graph_streets_wave = graph_streets.to_undirected()
        prop.add_edges_if_los(graph_streets_wave,
                              gdf_buildings,
                              max_distance=70)
        vehs = network.build_vehs(
            graph_streets=graph_streets, only_coords=False)

        graph_cons = con_ana.gen_connection_graph(
            vehs,
            gdf_buildings,
            max_dist,
            metric='distance',
            graph_streets_wave=graph_streets_wave)

        path_redundancy = con_ana.calc_center_path_redundancy(graph_cons, vehs)

        node_redundancy_correct = np.array_equal(
            path_redundancy['count_node_disjoint_paths'],
            node_redundancies_expteced)
        self.assertTrue(node_redundancy_correct)

        edge_redundancy_correct = np.array_equal(
            path_redundancy['count_edge_disjoint_paths'],
            edge_redundancies_expteced)
        self.assertTrue(edge_redundancy_correct)

        distance_correct = np.array_equal(
            path_redundancy['distance'],
            distances_expected
        )
        self.assertTrue(distance_correct)
Beispiel #4
0
    def test_gen_connection_graph(self):
        """Tests the function gen_connection_graph"""

        # Distance config
        max_dist = {'nlos': 100, 'olos_los': 150}
        edges_expected = [(0, 1), (0, 2), (0, 3),
                          (1, 2), (1, 4),
                          (2, 3), (2, 4), (2, 5), (2, 7),
                          (3, 4), (3, 5), (3, 6), (3, 7),
                          (4, 5), (4, 6), (4, 7),
                          (5, 6), (5, 7), (5, 8),
                          (6, 7), (6, 8), (6, 9),
                          (7, 8), (7, 9),
                          (8, 9)]

        edges_expected_sets = [set(edge) for edge in edges_expected]
        network = DemoNetwork()
        graph_streets = network.build_graph_streets()
        gdf_buildings = network.build_gdf_buildings()
        graph_streets_wave = graph_streets.to_undirected()
        prop.add_edges_if_los(graph_streets_wave,
                              gdf_buildings,
                              max_distance=70)
        vehs = network.build_vehs(
            graph_streets=graph_streets, only_coords=False)

        # Distance based connection matrix
        con_graph_dist_generated = con_ana.gen_connection_graph(
            vehs,
            gdf_buildings,
            max_dist,
            metric='distance',
            graph_streets_wave=graph_streets_wave)

        self.assertIsInstance(con_graph_dist_generated, nx.Graph)

        count_nodes = con_graph_dist_generated.number_of_nodes()

        for node_u in range(count_nodes):
            for node_v in range(count_nodes):
                edge_current = (node_u, node_v)
                if set(edge_current) in edges_expected_sets:
                    result_correct = con_graph_dist_generated.has_edge(*edge_current)
                else:
                    result_correct = not con_graph_dist_generated.has_edge(*edge_current)
                self.assertTrue(result_correct)
Beispiel #5
0
    def test_check_if_cons_orthogonal(self):
        """Tests the function check_if_cons_orthogonal"""

        idx_own = 0
        is_orthogonal_expected = np.array([1, 1, 0, 0, 1, 0, 1, 0], dtype=bool)
        coords_max_angle_expected = np.matlib.repmat([80, 0], 8, 1)

        network = DemoNetwork()
        graph_streets = network.build_graph_streets()
        gdf_buildings = network.build_gdf_buildings()
        graph_streets_wave = graph_streets.to_undirected()
        prop.add_edges_if_los(graph_streets_wave,
                              gdf_buildings,
                              max_distance=70)

        vehs = network.build_vehs(
            graph_streets=graph_streets, only_coords=False)
        idxs_other = np.setdiff1d(np.arange(vehs.count), idx_own)
        vehs.add_key('center', idx_own)
        vehs.add_key('other', idxs_other)

        is_orthogonal_generated, coords_max_angle_generated = \
            prop.check_if_cons_are_orthogonal(
                graph_streets_wave,
                vehs.get_graph('center'),
                vehs.get_graph('other'),
                max_angle=np.pi / 2)

        result_correct = np.array_equal(
            is_orthogonal_generated,
            is_orthogonal_expected)

        self.assertTrue(result_correct)

        result_correct = np.array_equal(
            coords_max_angle_generated,
            coords_max_angle_expected)

        self.assertTrue(result_correct)
Beispiel #6
0
    def test_gen_prop_cond_matrix(self):
        """Tests the function gen_prop_cond_matrix"""

        nlos_o = prop.Cond.NLOS_ort
        nlos_p = prop.Cond.NLOS_par
        olos = prop.Cond.OLOS
        los = prop.Cond.LOS
        olos_los = prop.Cond.OLOS_LOS
        nlos = prop.Cond.NLOS

        prop_cond_matrix_expected = np.array([
            los, nlos_o, nlos_p, nlos_p, nlos_o, nlos_p, nlos_o, nlos_p,
            nlos_o, nlos_p, nlos_p, nlos_o, nlos_p, nlos_o, nlos_p,
            nlos_o, nlos_o, los, nlos_o, olos, nlos_o,
            los, los, olos, los, nlos_p,
            los, nlos_p, nlos_o, nlos_p,
            los, los, nlos_o,
            los, nlos_p,
            los
        ], dtype=prop.Cond)

        arr = np.array
        coords_angle_expected = np.array([
            0, arr([80, 0]), 0, 0, arr([80, 0]), 0, arr([80, 0]), 0,
            arr([80, 0]), 0, 0, arr([80, 0]), 0, arr([80, 0]), 0,
            arr([80, 80]), arr([80, 80]), 0, arr([80, 140]), 0, arr([80, 200]),
            0, 0, 0, 0, 0,
            0, 0, arr([80, 80]), 0,
            0, 0, arr([80, 200]),
            0, 0,
            0
        ], dtype=object)

        prop_cond_matrix_red_expected = prop_cond_matrix_expected.copy()
        prop_cond_matrix_red_expected[numpy.logical_or(
            prop_cond_matrix_red_expected == nlos_o,
            prop_cond_matrix_red_expected == nlos_p)] = nlos
        prop_cond_matrix_red_expected[
            numpy.logical_or(
                prop_cond_matrix_red_expected == olos,
                prop_cond_matrix_red_expected == los)] = olos_los
        coords_angle_red_expected = np.zeros_like(
            coords_angle_expected)

        network = DemoNetwork()
        graph_streets = network.build_graph_streets()
        gdf_buildings = network.build_gdf_buildings()
        graph_streets_wave = graph_streets.to_undirected()
        prop.add_edges_if_los(graph_streets_wave,
                              gdf_buildings,
                              max_distance=70)

        vehs = network.build_vehs(graph_streets=graph_streets)

        prop_cond_matrix_generated, coords_angle_generated = \
            prop.gen_prop_cond_matrix(
                vehs.get_points(),
                gdf_buildings,
                graph_streets_wave=graph_streets_wave,
                graphs_vehs=vehs.get_graph(),
                fully_determine=True,
                max_dist=None,
                car_radius=2,
                max_angle=np.pi / 2)

        prop_cond_matrix_red_generated, coords_angle_red_generated = \
            prop.gen_prop_cond_matrix(
                vehs.get_points(),
                gdf_buildings,
                graph_streets_wave=graph_streets_wave,
                graphs_vehs=vehs.get_graph(),
                fully_determine=False,
                max_dist=None,
                car_radius=2,
                max_angle=np.pi / 2)

        result_correct = np.array_equal(
            prop_cond_matrix_generated,
            prop_cond_matrix_expected)
        self.assertTrue(result_correct)

        for generated, expected in \
                zip(coords_angle_generated, coords_angle_expected):
            result_correct = generated == expected
            self.assertTrue(numpy.all(result_correct))

        result_correct = np.array_equal(
            prop_cond_matrix_red_generated,
            prop_cond_matrix_red_expected)
        self.assertTrue(result_correct)

        for generated, expected in \
                zip(coords_angle_red_generated, coords_angle_red_expected):
            result_correct = generated == expected
            self.assertTrue(numpy.all(result_correct))
Beispiel #7
0
    def test_gen_connection_matrix(self):
        """Tests the function gen_connection_matrix"""

        # Distance config
        max_dist = {'nlos': 100, 'olos_los': 150}
        con_matrix_dist_expected_cond = np.array([
            1, 1, 1, 0, 0, 0, 0, 0,
            1, 0, 1, 0, 0, 0, 0,
            1, 1, 1, 0, 1, 0,
            1, 1, 1, 1, 0,
            1, 1, 1, 0,
            1, 1, 1,
            1, 1,
            1
        ], dtype=bool)

        # Pathloss config
        max_pl = 120
        con_matrix_pl_expected_cond = np.array([
            1, 1, 0, 0, 0, 0, 0, 0,
            1, 0, 0, 0, 0, 0, 0,
            1, 1, 1, 0, 1, 0,
            1, 1, 1, 1, 0,
            1, 0, 0, 0,
            1, 1, 0,
            1, 0,
            1
        ], dtype=bool)

        # Exception config
        metric_not_implemented = 'foo_bar_does_not_exist'

        con_matrix_dist_expected = sp_dist.squareform(con_matrix_dist_expected_cond)
        con_matrix_pl_expected = sp_dist.squareform(con_matrix_pl_expected_cond)

        network = DemoNetwork()
        graph_streets = network.build_graph_streets()
        gdf_buildings = network.build_gdf_buildings()
        graph_streets_wave = graph_streets.to_undirected()
        prop.add_edges_if_los(graph_streets_wave,
                              gdf_buildings,
                              max_distance=70)
        vehs = network.build_vehs(
            graph_streets=graph_streets, only_coords=False)

        # Distance based connection matrix
        con_matrix_dist_generated = con_ana.gen_connection_matrix(
            vehs,
            gdf_buildings,
            max_dist,
            metric='distance',
            graph_streets_wave=graph_streets_wave)

        result_correct = np.array_equal(
            con_matrix_dist_generated,
            con_matrix_dist_expected)
        self.assertTrue(result_correct)

        # Pathloss based connection matrix
        metric_config = {'shadowfading_enabled': False}
        con_matrix_pl_generated = con_ana.gen_connection_matrix(
            vehs,
            gdf_buildings,
            max_pl,
            metric='pathloss',
            graph_streets_wave=graph_streets_wave,
            metric_config=metric_config)

        result_correct = np.array_equal(
            con_matrix_pl_generated,
            con_matrix_pl_expected)
        self.assertTrue(result_correct)

        # Exception check
        with self.assertRaises(NotImplementedError):
            con_ana.gen_connection_matrix(
                vehs,
                gdf_buildings,
                max_dist,
                metric=metric_not_implemented,
                graph_streets_wave=graph_streets_wave)