-
Notifications
You must be signed in to change notification settings - Fork 0
/
minList.py
78 lines (73 loc) · 3.42 KB
/
minList.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class minList:
def __init__(self):
self.toDo_list = []
self.mindist_list: [int] = []
self.skyline: [Node] = []
# INSERTS A NODE OR AN ENTRY ALONG WITH ITS MINDIST AND SORTS BOTH LISTS WITH KEY=MINDIST
def insert(self, node: 'Node' = None, entry: 'Entry' = None, point: 'Point' = None):
if node is not None:
self.toDo_list.extend([node])
else:
self.toDo_list.extend([entry])
if point is None:
self.mindist_list.extend([node.mbr.mindist()])
else:
self.mindist_list.extend([node.mbr.mindist(point)])
list1 = self.toDo_list
list2 = self.mindist_list
self.toDo_list, self.mindist_list = (list(s) for s in zip(
*sorted(zip(list1, list2), key=lambda pair: pair[1])))
# CHECKS TO SEE IF THE MINLIST OBJECT IS EMPTY
def isEmpty(self):
if len(self.mindist_list) != 0:
return False
else:
return True
# OPENS UP THE FIRST NODE UNTIL WE REACH AN ENTRY. AN ENTRY IS THEN COMPARED WITH THE REST OF THE SKYLINE ENTRIES.
# IF THE ENTRY IS DOMINATED BY NO OTHER ENTRY INSIDE THE SKYLINE LIST, IT IS ADDED ASWELL.
def process(self, rec: 'Rectangle' = None):
isDominatedFlag = 0
if(len(self.toDo_list) != 0):
tmp_node = self.toDo_list[0]
del self.toDo_list[0]
del self.mindist_list[0]
if(str(type(tmp_node)) == "<class 'rtree.RTree.Node'>"):
if len(tmp_node.children) != 0:
for num_skylines in range(len(self.skyline)):
if tmp_node.mbr.is_dominated(self.skyline[num_skylines].mbr):
isDominatedFlag = 1
if isDominatedFlag == 0:
for num_children in range(len(tmp_node.children)):
self.insert(tmp_node.children[num_children])
elif len(tmp_node.entries) != 0:
for num_skylines in range(len(self.skyline)):
if tmp_node.mbr.is_dominated(self.skyline[num_skylines].mbr):
isDominatedFlag = 1
if isDominatedFlag == 0:
for num_entries in range(len(tmp_node.entries)):
self.insert(tmp_node.entries[num_entries])
else:
if len(self.skyline) != 0:
for num_skylines in range(len(self.skyline)):
if tmp_node.mbr.is_dominated(self.skyline[num_skylines].mbr):
isDominatedFlag = 1
if isDominatedFlag == 0:
if rec is None:
self.skyline.extend([tmp_node])
else:
if rec.contains(tmp_node.mbr):
self.skyline.extend([tmp_node])
else:
if rec is None:
self.skyline.extend([tmp_node])
else:
if rec.contains(tmp_node.mbr):
self.skyline.extend([tmp_node])
return self.skyline
def __repr__(self):
ret = ""
for num_nodes in range(len(self.toDo_list)):
ret += "\nMindist: " + \
str(self.mindist_list[num_nodes]) + "\n" + \
self.toDo_list[num_nodes].mbr.__repr__() + "\n"
return ret