def test_basic_u(self): np.random.seed(401) z_ref = -1 width = 10 length = 10 # planes x_planes = [] x_offsets = np.cumsum(np.random.randint(1, 3, 6)) - width / 2 for x in x_offsets: x_planes.append(models.Plane.from_axis_distance(axis=np.array([1, 0, 0]), distance=x)) y_planes = [] y_offsets = np.cumsum(np.random.randint(1, 3, 5)) - length / 2 for y in y_offsets: y_planes.append(models.Plane.from_axis_distance(axis=np.array([0, 1, 0]), distance=y)) # boundaries boundaries = [simulator.rectangle(x_planes[4], x=np.mean([y_offsets[3], y_offsets[2]]), y=0, w=y_offsets[3]-y_offsets[2]-0.3, h=2), simulator.rectangle(x_planes[5], x=np.mean([y_offsets[4], y_offsets[1]]), y=0, w=y_offsets[4]-y_offsets[1]-0.5, h=2), simulator.rectangle(y_planes[1], x=-np.mean([x_offsets[5], x_offsets[1]]), y=0, w=x_offsets[5]-x_offsets[1]-0.4, h=2), simulator.rectangle(y_planes[2], x=-np.mean([x_offsets[4], x_offsets[1]]), y=0, w=x_offsets[4]-x_offsets[1]-0.2, h=2), simulator.rectangle(y_planes[3], x=-np.mean([x_offsets[4], x_offsets[1]]), y=0, w=x_offsets[4]-x_offsets[1]-0.25, h=2), simulator.rectangle(y_planes[4], x=-np.mean([x_offsets[5], x_offsets[1]]), y=0, w=x_offsets[5]-x_offsets[1]-0.1, h=2) ] # evidence evidence_index = [((2, 2), (1, 1)), ((4, 2), (2, 1)), ((5, 2), (4, 1)), ((5, 4), (4, 2)), ((4, 4), (3, 3)), ((3, 4), (2, 3)), ((2, 4), (1, 3)), ((3, 1), (2, 0))] evidence = [models.Point(np.array([-2, 3, 0]))] for ev in evidence_index: tr_corner = np.array([x_offsets[ev[0][0]], y_offsets[ev[0][1]]]) bl_corner = np.array([x_offsets[ev[1][0]], y_offsets[ev[1][1]]]) diff = tr_corner - bl_corner center = np.mean(np.array([tr_corner, bl_corner]), axis=0) ellipse = simulator.ellipse(float(diff[0]) / 2, float(diff[1]) / 2, 3).rigid(np.eye(2), center) evidence.append(ellipse) # construct cell_complex = models.CellComplex2D(z_ref=z_ref, width=width, length=length, evidence=evidence) # cell_complex = models.CellComplex2D(z_ref=z_ref, width=width, length=length) for p in x_planes + y_planes: cell_complex.insert_partition(p) for b in boundaries: cell_complex.insert_boundary(b) speculator = estimators.FloorPlanSpeculator(cell_complex, horizon=1) scene_graph = speculator.floorplan() # scene_graph = cell_complex.cell_graph() cell_complex.draw(scene_graph)
def test_add4_random(self): cell_complex = models.CellComplex2D(0, 10, 10) np.random.seed(3) planes = simulator.random_planes(num_planes=4, max_distance=9, c=0) for p in planes: cell_complex.insert_partition(p) H = cell_complex.cell_graph() G = nx.to_networkx_graph({ 0: [1, 2, 4], 1: [0, 6], 2: [0, 3, 6], 3: [2, 4, 7, 8], 4: [0, 3, 5], 5: [4, 8], 6: [1, 2, 7], 7: [6, 3], 8: [3, 5] }) self.assertTrue(nx.is_isomorphic(G, H)) cell_complex.draw(scene_graph=H)
def test_multi_add_big(self): cell_complex = models.CellComplex2D(1, 20, 10) np.random.seed(12) planes = simulator.random_planes(num_planes=60, max_distance=9, c=0) for p in planes: cell_complex.insert_partition(p)
def test_add1(self): cell_complex = models.CellComplex2D(0, 20, 10) cutting_plane = models.Plane.from_axis_distance(np.array([1, 1, 0]), 1) cell_complex.insert_partition(cutting_plane) G = nx.to_networkx_graph({0: [1], 1: [0]}) H = cell_complex.cell_graph() self.assertTrue(nx.is_isomorphic(G, H)) self.assertEqual(6, len(cell_complex.vertices))
def test_partition_with_boundary2(self): cell_complex = models.CellComplex2D(0, 20, 10) cutting_plane = models.Plane.from_axis_distance(np.array([1, 1, 0]), 1) boundary = simulator.rectangle(cutting_plane, 2, 1, 4, 2) cell_complex.insert_partition(cutting_plane) cell_complex.insert_boundary(boundary) G = nx.to_networkx_graph({0: [1], 1: [0]}) H = cell_complex.cell_graph(coverage_threshold=4.1) self.assertTrue(nx.is_isomorphic(G, utilities.filter_boundary_edges(H))) self.assertEqual(6, len(cell_complex.vertices)) cell_complex.draw(scene_graph=H)
def test_partition_with_evidence_simple(self): evidence = [simulator.ellipse(5, 3, 4, -3)] cell_complex = models.CellComplex2D(-3, 20, 10, evidence=evidence) cutting_plane = models.Plane.from_axis_distance(np.array([1, 1, 0]), 1) cell_complex.insert_partition(cutting_plane) G = nx.to_networkx_graph({0: [1], 1: [0]}) H = cell_complex.cell_graph() self.assertTrue(nx.is_isomorphic(G, H)) self.assertEqual(6, len(cell_complex.vertices)) node_evidence_edges = 0 for node in H.nodes: self.assertTrue(len(node.evidence) == 1) node_evidence_edges += len(node.evidence[0].edges) self.assertEqual(len(evidence[0].edges), node_evidence_edges - 4) cell_complex.draw(scene_graph=H)
def test_add3(self): cell_complex = models.CellComplex2D(0, 20, 10) cp1 = models.Plane.from_axis_distance(np.array([1, 1, 0]), 1) cp2 = models.Plane.from_axis_distance(np.array([1, 1, 0]), 2) cp3 = models.Plane.from_axis_distance(np.array([-1, 1, 0]), 1) cell_complex.insert_partition(cp1) cell_complex.insert_partition(cp2) cell_complex.insert_partition(cp3) G = nx.to_networkx_graph({ 0: [1, 2], 1: [0, 3], 2: [0, 3, 4], 3: [1, 2, 5], 4: [2, 5], 5: [3, 4] }) H = cell_complex.cell_graph() self.assertTrue(nx.is_isomorphic(G, H)) self.assertEqual(12, len(cell_complex.vertices)) self.assertEqual(17, len(cell_complex.edges))
def test_multi_add_small(self): cell_complex = models.CellComplex2D(0, 10, 10) np.random.seed(1) planes = simulator.random_planes(num_planes=5, max_distance=9, c=0) for p in planes: cell_complex.insert_partition(p) G = nx.to_networkx_graph({ 0: [1], 1: [0, 2], 2: [1, 3, 5, 7], 3: [2, 4], 4: [3, 5], 5: [2, 4, 6], 6: [5, 7], 7: [6, 2] }) H = cell_complex.cell_graph() self.assertTrue(nx.is_isomorphic(G, H)) self.assertEqual(16, len(cell_complex.vertices)) self.assertEqual(23, len(cell_complex.edges))