-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsgmentMain.py
More file actions
38 lines (33 loc) · 1.04 KB
/
Copy pathsgmentMain.py
File metadata and controls
38 lines (33 loc) · 1.04 KB
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
import interval
import matplotlib.pyplot as plt
import sgmntTree
plotResults = True
numberOfIntervals = 100
minLow = 10
maxLow = 6*numberOfIntervals
minSize = 5
maxSize = 20
intervals = []
for i in range(numberOfIntervals):
x = interval.Interval(minLow,maxLow,minSize,maxSize)
# print(x)
intervals.append(x)
Tree = sgmntTree.SegmentTree()
root = None
root = Tree.build(minLow, maxLow+maxSize)
for x in intervals:
Tree.insert(x.low, x.high, root)
# Tree.inOrder(root)
# Tree.printTreeInPdf("segment_tree.gv",root)
#get a random query point
queryPoint = interval.Interval(minLow, maxLow, 0,0)
print("Query Point: "+str(queryPoint.low))
Tree.query(root, queryPoint.low)
# plot intervals
if(plotResults):
for x in range(len(intervals)):
# print(intervalArray[x].high)
plt.plot((intervals[x].low,intervals[x].high), (x+1,x+1))
# print("Query Interval low: " + str(queryInterval[0])+" Query Interval High: " + str(queryInterval[1]))
plt.plot((queryPoint.low, queryPoint.low), (0,numberOfIntervals+1), 'k:')
plt.show()