-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrtreeQueries.py
75 lines (65 loc) · 1.86 KB
/
rtreeQueries.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
'''
rtreeRange.py
Arguements: -d <datasetFile>, -r <rangeQueryFile>, -n <nnQueryFile>, -b <Bvalue>
Author: Yi Liu
Answer queries using sequentially scanning and r-tree respectively
'''
# standard libraries
import time
import sys
import getopt
# private libraries
import rtreeBuilder
import rtreeRange
import rtreeNN
import scanRange
import scanNN
# scan the data set sequentially and print the time
def scanDataSet(datasetFile):
points = []
start = time.time()
f = open(datasetFile, 'rt')
nextLine = f.readline() # the first line is the size
nextLine = f.readline()
while nextLine != '':
points.append(scanRange.getPoint(nextLine))
nextLine = f.readline()
f.close()
end = time.time()
print('Scanning time:', str(end-start))
return points
def main():
datasetFile = 'dataset.txt'
rangeFile = 'queriesRange.txt'
nnFile = 'queriesNN.txt'
Bvalue = None
scanFlag = 'n'
# parse arguments
options,args = getopt.getopt(sys.argv[1:],"d:r:n:b:")
for opt, para in options:
if opt == '-d':
datasetFile = para
if opt == '-r':
rangeFile = para
if opt == '-n':
nnFile = para
if opt == '-b':
Bvalue = int(para)
# scan the data set
points = scanDataSet(datasetFile)
# build r-tree
try:
root = rtreeBuilder.buildRtree(datasetFile, Bvalue)
rtreeBuilder.checkRtree(root)
except Exception:
print('Memory overflow')
# answer range queries
queries = scanRange.readRanges(rangeFile)
scanRange.scanRangeQueries(points, queries)
rtreeRange.answerRangeQueries(root, queries)
# answer NN queries
queries = scanNN.readNn(nnFile)
scanNN.scanNNQueries(points, queries)
rtreeNN.answerNnQueries(root, queries)
if __name__ == '__main__':
main()