Exemplo n.º 1
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)
Exemplo n.º 2
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)
def init_surface_sentinels(n, p0, p1):
    # This module initializes the empty attainment surfaces and the sentinels
    # Summary attainment surface
    lsa = [[] for _ in range(n)]
    # Make tree with Sentinels
    tree = bst.AVLTree()
    tree.set_newroot(p0)
    tree.insert(p1)
    # Copy tree n times to lstar and xstar
    lstar = []
    xstar = []
    for t in range(n):
        lstar.append(deepcopy(tree))
        xstar.append(deepcopy(tree))
    return lsa, lstar, xstar
Exemplo n.º 4
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)