Ejemplo n.º 1
0
 def setUp(self):
     # Set initial points for sentinels (to simulate infinity)
     big_pos_value = 10E10
     big_neg_value = -1 * big_pos_value
     self.p1 = np.array([big_neg_value, big_pos_value, big_neg_value])
     p2 = np.array([big_pos_value, big_neg_value, big_neg_value])
     # Initialize avltree
     point0 = eaf3D.ApproxPoint(None, 1000, self.p1)
     point1 = eaf3D.ApproxPoint(None, 1001, p2)
     node0 = bst.AVLNode(point0, 1)
     node1 = bst.AVLNode(point1, 0)
     self.t = bst.AVLTree()
     self.t.root = node0
     node0.right = node1
     self.t.count = 2
     # Import more data points
     fname = 'example/run01'
     exset = eaf3D.import_approximate_set(fname)
     x, m = eaf3D.multiset_sum([exset])
     # Q is X sorted in ascending order of the z coordinate
     self.qstack = Stack()
     xintoq = sorted(x.values(), key=attrgetter('z'))
     for i in range(len(xintoq)):
         self.qstack.push(xintoq[i])
     # Add new data points to tree
     for i in range(4):
         p = self.qstack.pop()
         self.t.insert(p)
Ejemplo n.º 2
0
 def test_remove_node_case3_left_is_rightmost(self):
     # Set up tree to test case 3 when the left node is the rightmost
     tree = bst.AVLTree()
     point0 = eaf3D.ApproxPoint(1, 1, np.array([4, 12.67, 0]))
     tree.set_newroot(point0)
     # Set initial points for sentinels (to simulate infinity)
     big_pos_value = 10E10
     big_neg_value = -1 * big_pos_value
     p1 = np.array([big_neg_value, big_pos_value, big_neg_value])
     p2 = np.array([big_pos_value, big_neg_value, big_neg_value])
     # Initialize avltree
     point1 = eaf3D.ApproxPoint(None, 1000, p1)
     av1 = bst.AVLNode(point1, balance=1)
     tree.root.left = av1
     point2 = eaf3D.ApproxPoint(None, 1001, p2)
     av2 = bst.AVLNode(point2, balance=-1)
     tree.root.right = av2
     point3 = eaf3D.ApproxPoint(1, 2, np.array([3, 20.21, 0]))
     av3 = bst.AVLNode(point3)
     tree.root.left.right = av3
     point4 = eaf3D.ApproxPoint(1, 3, np.array([5, 10.42, 0]))
     av4 = bst.AVLNode(point4)
     tree.root.right.left = av4
     tree.count = 5
     tree.remove_node(tree.root)
     tree.remove_node(tree.root)
     self.assertEqual(tree.root, av4)
     self.check_node_balances(tree)
 def test_incorrect_balance(self):
     # This test recreates an error to figure out the problem.
     # Recreate tree right before error occured
     p1 = eaf3D.ApproxPoint(None, None, np.array([3, 21.28, 0]))
     p2 = eaf3D.ApproxPoint(None, None, np.array([5, 12.93, 0]))
     p3 = eaf3D.ApproxPoint(None, None, np.array([6, 10.42, 0]))
     self.eaf_maker.lstar[1].insert(p1)
     self.eaf_maker.lstar[1].insert(p3)
     self.eaf_maker.lstar[1].insert(p2)
     # Insert problem child (newroot needs to be rebalanced after kids)
     newp = eaf3D.ApproxPoint(None, None, np.array([4, 15.79, 0]))
     self.eaf_maker.lstar[1].insert(newp)
     # Assert that the tree correctly balances
     self.check_node_balances(self.eaf_maker.lstar[1])
 def test_lower_y(self):
     p1 = eaf3D.ApproxPoint(1, 1002, np.array([3, 23.4623828, 6059.2348600000005]))
     p2 = eaf3D.ApproxPoint(1, 1003, np.array([4, 14.07345342, 5990.93696]))
     p3 = eaf3D.ApproxPoint(1, 1004, np.array([5, 10.90633272, 5965.522494]))
     p4 = eaf3D.ApproxPoint(1, 1005, np.array([7, 10.73267638, 5868.0173159999995]))
     p5 = eaf3D.ApproxPoint(0, 1006, np.array([9, 6.5, 7000]))
     q1 = self.t.lower_y(p1)
     q2 = self.t.lower_y(p2)
     q3 = self.t.lower_y(p3)
     q4 = self.t.lower_y(p4)
     q5 = self.t.lower_y(p5)
     self.assertAlmostEqual(q1.y, 20.21, places=2)
     self.assertAlmostEqual(q2.y, 12.67, places=2)
     self.assertAlmostEqual(q3.y, 10.42, places=2)
     self.assertAlmostEqual(q4.y, 10.42, places=2)
     self.assertEqual(q5.y, -10E10)
 def test_higher_x(self):
     p1 = eaf3D.ApproxPoint(1, 1002, np.array([3, 23.4623828, 6059.2348600000005]))
     p2 = eaf3D.ApproxPoint(1, 1003, np.array([4, 14.07345342, 5990.93696]))
     p3 = eaf3D.ApproxPoint(1, 1004, np.array([5, 10.90633272, 5965.522494]))
     p4 = eaf3D.ApproxPoint(1, 1005, np.array([7, 10.73267638, 5868.0173159999995]))
     p5 = eaf3D.ApproxPoint(0, 1006, np.array([1, 28, 7000]))
     q1 = self.t.higher_x(p1)
     q2 = self.t.higher_x(p2)
     q3 = self.t.higher_x(p3)
     q4 = self.t.higher_x(p4)
     q5 = self.t.higher_x(p5)
     self.assertEqual(q1.x, 4)
     self.assertEqual(q2.x, 5)
     self.assertEqual(q3.x, 10E10)
     self.assertEqual(q4.x, 10E10)
     self.assertEqual(q5.x, 3)
 def test_missing_sentinel(self):
     # This test recreates an error to figure out the problem.
     # Recreate tree right before error occured
     p1 = eaf3D.ApproxPoint(None, None, np.array([3, 25.58, 0]))
     p2 = eaf3D.ApproxPoint(None, None, np.array([5, 24.93, 0]))
     p3 = eaf3D.ApproxPoint(None, None, np.array([8, 21.23, 0]))
     self.eaf_maker.lstar[3].insert(p1)
     self.eaf_maker.lstar[3].insert(p3)
     self.eaf_maker.lstar[3].insert(p2)
     # Insert problem child
     newp = eaf3D.ApproxPoint(None, None, np.array([5, 21.226, 5987]))
     self.eaf_maker.submit_to_lstar(newp, 3)
     # The issue was that the left only child of the right only child
     # is not connecting
     (pivot, theStack, parent, found) = self.eaf_maker.lstar[3].\
         search(self.eaf_maker.p1)
     self.assertTrue(found)
Ejemplo n.º 7
0
 def test_insert_case2(self):
     # Test insert function for adjust only
     tree = bst.AVLTree()
     tree.set_newroot(self.qstack.pop())
     for i in range(12):
         point = self.qstack.pop()
         tree.insert(point)
     # Insert nonvalid point to prove test
     point1 = eaf3D.ApproxPoint(None, 1002, np.array([2, 0, 0]))
     tree.insert(point1)
     point2 = eaf3D.ApproxPoint(None, 1003, np.array([3.5, 0, 0]))
     tree.insert(point2)
     (pivot, theStack, parent, found) = tree.search(point1)
     theStack.pop()
     while not theStack.isEmpty():
         node = theStack.pop()
         self.assertEqual(node.balance, 0)
 def test_2(self):
     # This test recreates an error to figure out the problem.
     # Recreate tree right before error occured
     t = 8
     p1 = eaf3D.ApproxPoint(None, None,
                            np.array([41, 52.61580174, 9787.313057]))
     p2 = eaf3D.ApproxPoint(None, None,
                            np.array([42, 50.55516332, 9792.087863]))
     p3 = eaf3D.ApproxPoint(None, None,
                            np.array([46, 34.52374955, 9776.017285]))
     p4 = eaf3D.ApproxPoint(None, None,
                            np.array([44, 35.27757581, 9773.745261]))
     self.eaf_maker.lstar[t].insert(p2)
     self.eaf_maker.lstar[t].insert(p1)
     self.eaf_maker.lstar[t].insert(p3)
     self.eaf_maker.lstar[t].insert(p4)
     # Insert new child and remove dominated points
     newp = eaf3D.ApproxPoint(None, None,
                              np.array([43, 40.23564548, 9772.417427]))
     self.eaf_maker.lstar[t].insert(newp)
     # Assert that the tree correctly balances
     self.check_node_balances(self.eaf_maker.lstar[t])
     # Remove node (problem occurs here)
     newp2 = eaf3D.ApproxPoint(None, None,
                               np.array([42, 46.04608999, 9763.185098]))
     omegas = self.eaf_maker.lstar[t].list_nodes_domxy(newp2)
     self.eaf_maker.lstar[t].remove_node(omegas[0])
     # Assert that the tree correctly balances
     self.check_node_balances(self.eaf_maker.lstar[t])
Ejemplo n.º 9
0
 def setUp(self):
     self.t = bst.AVLTree()
     # Import more data points
     fname = 'example/run01'
     exset = eaf3D.import_approximate_set(fname)
     x, m = eaf3D.multiset_sum([exset])
     # Q is X sorted in ascending order of the z coordinate
     self.qstack = Stack()
     xintoq = sorted(x.values(), key=attrgetter('z'))
     for i in range(len(xintoq)):
         self.qstack.push(xintoq[i])
     self.t.set_newroot(self.qstack.pop())
     # Add data points to tree
     while not self.qstack.isEmpty():
         p = self.qstack.pop()
         self.t.insert(p)
     p1 = eaf3D.ApproxPoint(None, 1001, np.array([12, 6.6, 0]))
     self.t.insert(p1)
     p2 = eaf3D.ApproxPoint(None, 1002, np.array([8, 9.7, 0]))
     self.t.insert(p2)
     p3 = eaf3D.ApproxPoint(None, 1002, np.array([10, 7.5, 0]))
     self.t.insert(p3)
Ejemplo n.º 10
0
 def test_insert_case1(self):
     # Test for inserting into balanced tree
     # Get balanced tree
     tree = bst.AVLTree()
     tree.set_newroot(self.qstack.pop())
     for i in range(12):
         point = self.qstack.pop()
         tree.insert(point)
     # Insert nonvalid point to balance tree
     point1 = eaf3D.ApproxPoint(None, 1002, np.array([2, 0, 0]))
     tree.insert(point1)
     point2 = eaf3D.ApproxPoint(None, 1003, np.array([3.5, 0, 0]))
     tree.insert(point2)
     # Point to test
     point3 = eaf3D.ApproxPoint(None, 1004, np.array([8, 0, 0]))
     tree.insert(point3)
     # Check that all nodes along stack have balance = 1
     self.assertEqual(tree.count, 8)
     (pivot, theStack, parent, found) = tree.search(point3)
     theStack.pop()
     while not theStack.isEmpty():
         node = theStack.pop()
         self.assertEqual(node.balance, 1)
 def test_1(self):
     # This test recreates an error to figure out the problem.
     # Recreate tree right before error occured
     t = 7
     p1 = eaf3D.ApproxPoint(None, None, np.array([41.0, 50.56, 0]))
     p2 = eaf3D.ApproxPoint(None, None, np.array([42, 34.94, 9740.30]))
     p3 = eaf3D.ApproxPoint(None, None, np.array([44.0, 33.30406447, 0]))
     p4 = eaf3D.ApproxPoint(None, None, np.array([43.0, 33.75, 0]))
     p5 = eaf3D.ApproxPoint(None, None, np.array([45, 33.08, 0]))
     self.eaf_maker.lstar[t].insert(p2)
     self.eaf_maker.lstar[t].insert(p1)
     self.eaf_maker.lstar[t].insert(p3)
     self.eaf_maker.lstar[t].insert(p4)
     self.eaf_maker.lstar[t].insert(p5)
     newchild = self.eaf_maker.lstar[t].root.left.rotateLeft()
     newchild.balance = -1
     newchild.left.balance = 0
     self.eaf_maker.lstar[t].root.left = newchild
     child2 = self.eaf_maker.lstar[t].root.right.right.rotateRight()
     child2.balance = 1
     child2.right.balance = 0
     self.eaf_maker.lstar[t].root.right.right = child2
     # Add point right before error:
     p6 = eaf3D.ApproxPoint(None, None,
                            np.array([46, 32.99667, 9708.755383]))
     self.eaf_maker.submit_to_lstar(p6, t)
     # Insert problem child and remove dominated points
     newp = eaf3D.ApproxPoint(None, None,
                              np.array([43, 33.30406447, 9700.916965]))
     omegas = self.eaf_maker.lstar[t].list_nodes_domxy(newp)
     while omegas:
         self.eaf_maker.lstar[t].remove_node(omegas[0])
         self.check_node_balances(self.eaf_maker.lstar[t])
         omegas = self.eaf_maker.lstar[t].list_nodes_domxy(newp)
     self.eaf_maker.lstar[t].insert(newp)
     # Assert that the tree correctly balances
     self.check_node_balances(self.eaf_maker.lstar[t])
 def test_incorrect_balance(self):
     # This test recreates an error to figure out the problem.
     # Recreate tree right before error occured
     p1 = eaf3D.ApproxPoint(None, None, np.array([58, 32.51, 0]))
     p2 = eaf3D.ApproxPoint(None, None, np.array([43, 35.39, 0]))
     p3 = eaf3D.ApproxPoint(None, None, np.array([44, 33.46, 0]))
     p4 = eaf3D.ApproxPoint(None, None, np.array([103, 32.26, 0]))
     p5 = eaf3D.ApproxPoint(None, None, np.array([42, 37.10, 0]))
     self.eaf_maker.lstar[8].insert(p1)
     self.eaf_maker.lstar[8].insert(p3)
     self.eaf_maker.lstar[8].insert(p2)
     self.eaf_maker.lstar[8].insert(p4)
     self.eaf_maker.lstar[8].insert(p5)
     # Insert problem child and remove dominated points
     newp = eaf3D.ApproxPoint(None, None, np.array([54, 32.26, 0]))
     omegas = self.eaf_maker.lstar[8].list_nodes_domxy(newp)
     while omegas:
         self.eaf_maker.lstar[8].remove_node(omegas[0])
         omegas = self.eaf_maker.lstar[8].list_nodes_domxy(newp)
     self.eaf_maker.lstar[8].insert(newp)
     # Assert that the tree correctly balances
     self.check_node_balances(self.eaf_maker.lstar[8])
 def test_3(self):
     # This test recreates an error to figure out the problem.
     # Recreate tree right before error occured
     t = 9
     p1 = eaf3D.ApproxPoint(None, None,
                            np.array([44, 32.99667322, 9692.300569]))
     p2 = eaf3D.ApproxPoint(None, None,
                            np.array([41, 50.18079041, 9652.966452]))
     p3 = eaf3D.ApproxPoint(None, None,
                            np.array([43, 33.29213592, 9646.838321]))
     p4 = eaf3D.ApproxPoint(None, None,
                            np.array([42, 34.93930038, 9590.186112]))
     p5 = eaf3D.ApproxPoint(None, None,
                            np.array([51, 29.59311919, 9564.932893]))
     p6 = eaf3D.ApproxPoint(None, None,
                            np.array([47, 31.53745389, 9559.198558]))
     p7 = eaf3D.ApproxPoint(None, None,
                            np.array([50, 30.54022012, 9555.970874]))
     p8 = eaf3D.ApproxPoint(None, None,
                            np.array([53, 28.91678773, 9555.401697]))
     p9 = eaf3D.ApproxPoint(None, None,
                            np.array([58, 27.73733822, 9555.401697]))
     p10 = eaf3D.ApproxPoint(None, None,
                             np.array([61, 26.67391754, 9555.401697]))
     p11 = eaf3D.ApproxPoint(None, None,
                             np.array([67, 25.55429681, 9552.098401]))
     p12 = eaf3D.ApproxPoint(None, None,
                             np.array([62, 25.88606603, 9551.119924]))
     p13 = eaf3D.ApproxPoint(None, None,
                             np.array([64, 25.55429681, 9551.119924]))
     self.eaf_maker.lstar[t].insert(p1)
     self.eaf_maker.lstar[t].insert(p2)
     self.eaf_maker.lstar[t].insert(p5)
     self.eaf_maker.lstar[t].insert(p3)
     self.eaf_maker.lstar[t].insert(p6)
     self.eaf_maker.lstar[t].insert(p10)
     self.eaf_maker.lstar[t].insert(p4)
     self.eaf_maker.lstar[t].insert(p7)
     self.eaf_maker.lstar[t].insert(p9)
     self.eaf_maker.lstar[t].insert(p8)
     self.eaf_maker.lstar[t].insert(p11)
     self.eaf_maker.submit_to_lstar(p12, t)
     self.eaf_maker.submit_to_lstar(p13, t)
     self.eaf_maker.lstar[t].print_astree()
     # Assert that the tree correctly balances
     self.check_node_balances(self.eaf_maker.lstar[t])
     # Remove node (problem occurs here)
     newp = eaf3D.ApproxPoint(None, None,
                              np.array([50, 29.59311919, 9547.593165]))
     omegas = self.eaf_maker.lstar[t].list_nodes_domxy(newp)
     while omegas:
         self.eaf_maker.lstar[t].remove_node(omegas[0])
         self.check_node_balances(self.eaf_maker.lstar[t])
         omegas = self.eaf_maker.lstar[t].list_nodes_domxy(newp)
         self.eaf_maker.lstar[t].print_astree()
     # Assert that the tree correctly balances
     self.check_node_balances(self.eaf_maker.lstar[t])
Ejemplo n.º 14
0
 def test_insert_found(self):
     expected = str(self.t)
     self.t.insert(eaf3D.ApproxPoint(None, 1000, self.p1))
     self.assertEqual(str(self.t), expected)
Ejemplo n.º 15
0
 def test_list_nodes_domxy(self):
     p1 = eaf3D.ApproxPoint(1, 1002, np.array([3, 19.0, 6059.]))
     list = self.t.list_nodes_domxy(p1)
     self.assertListEqual(list, [self.t.root.left.right])
Ejemplo n.º 16
0
 def test_insert_case3_subcaseA(self):
     point = eaf3D.ApproxPoint(None, 1002, np.array([4.5, 0, 0]))
     (pivot, theStack, parent, found) = self.t.search(point)
     self.t.insert(point)
     self.assertEqual(pivot.balance, 0)
     self.assertEqual(self.t.root.balance, 0)